Indicate that Sphinx should be run on Linux only #13
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# For more information on GitHub Actions for Python projects, see: https://git.io/JtENw | |
name: tests | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
branches: [main] | |
jobs: | |
build: | |
runs-on: ${{ matrix.operating-system }} | |
strategy: | |
fail-fast: false | |
matrix: | |
operating-system: [ubuntu-latest, macos-latest, windows-latest] | |
python-version: ["3.10", "3.11", "3.12"] | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Get pip cache dir | |
id: pip-cache | |
run: echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT | |
- name: pip cache | |
uses: actions/cache@v3 | |
with: | |
path: ${{ steps.pip-cache.outputs.dir }} | |
key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }} | |
restore-keys: ${{ runner.os }}-pip- | |
- name: Rustup latest 64-bit Rust, as it seems faster than Rust-related workflows | |
run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs -sSf | sh -s -- -y --no-modify-path | |
- name: Update current environment to access Rust compiler | |
if: startsWith(runner.os, 'Linux') || startsWith(runner.os, 'macOS') | |
run: source "$HOME"/.cargo/env ; | |
- name: Update current environment to access Rust compiler | |
if: startsWith(runner.os, 'Windows') | |
run: $addPath = "$env:USERPROFILE\.cargo\bin" ; $scope = 'User' ; [Environment]::SetEnvironmentVariable('PATH', ([Environment]::GetEnvironmentVariable('PATH', $scope) + ";$addPath"), $scope) ; $env:PATH += ";$addPath" ; | |
- name: Install cargo-binstall | |
if: startsWith(runner.os, 'Linux') || startsWith(runner.os, 'macOS') | |
run: curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash | |
- name: Install cargo-binstall | |
if: startsWith(runner.os, 'Windows') | |
run: Set-ExecutionPolicy Unrestricted -Scope Process; iex (iwr "https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.ps1").Content | |
- name: Install useful cargo utilities | |
run: cargo binstall -y cargo-tarpaulin ripgrep sd ; | |
- name: Run cargo clippy (Linter-like checker for Rust code) | |
run: cargo clippy --all-targets -- -D warnings ; | |
- name: Update pip prerequisites | |
if: steps.pip-cache.outputs.cache-hit != 'true' | |
run: python -u -m pip install --upgrade pip setuptools ; | |
- name: Install requirements from requirements.txt | |
if: steps.pip-cache.outputs.cache-hit != 'true' | |
run: pip install --upgrade -r requirements.txt ; | |
- name: Run cargo tarpaulin (code coverage for Rust code), note that macOS runs bash on CI, not zsh | |
run: cargo tarpaulin --all-targets --count --exclude-files=target/* --engine=llvm --fail-under=80 --ignored --no-dead-code --out=stdout --skip-clean --target-dir=target/tarpaulin-target/ ; | |
- name: Install using maturin, optimized Rust code | |
run: env VIRTUAL_ENV=$(python -c 'import sys; print(sys.base_prefix)') maturin develop --release ; | |
- name: Run with ruff | |
run: python -u -m ruff . | |
# - name: Run with refurb to find code that can be written in a more modern way | |
# run: python -u -m refurb . | |
- name: Run with vulture to find dead code | |
if: startsWith(runner.os, 'Linux') || startsWith(runner.os, 'macOS') | |
run: | | |
python -c 'exec("from pathlib import Path;import shutil;import subprocess;\ntry: import tomllib;\nexcept ImportError: import tomli as tomllib;\nwith Path(\"pyproject.toml\").open(mode=\"rb\") as fp: c = tomllib.load(fp); n = c[\"project\"][\"name\"];\nif not (v := shutil.which(\"vulture\")): raise RuntimeError(\"Please first install vulture\");\nfor z in sorted({x.split(\" # \",maxsplit=1)[0] for x in sorted(subprocess.run([y for y in [v,\".\",\".vulture_allowlist\" if Path(\".vulture_allowlist\").is_file() else \"\"] if y],capture_output=True,text=True).stdout.rstrip().splitlines()) if not x.startswith(\"# \")}): print(z)")' | |
- name: Run pyright | |
if: startsWith(runner.os, 'Linux') | |
run: python -u -m pyright | |
- name: Run shellcheck | |
if: startsWith(runner.os, 'Linux') | |
run: rg -t sh --files | xargs shellcheck | |
- name: Run bashate | |
if: startsWith(runner.os, 'Linux') | |
run: rg -t sh --files | xargs bashate -i E006 | |
- name: Generate Sphinx docs (inspect this output for Sphinx errors) | |
if: startsWith(runner.os, 'Linux') | |
run: | | |
( pushd docs/ > /dev/null && ./gen-sphinx-html.sh 2>&1 | rg ": (ERROR|WARNING|CRITICAL): " ; popd > /dev/null ; ) || true | |
- name: Reset Git repo after Sphinx documentation generation | |
if: startsWith(runner.os, 'Linux') | |
run: git clean -fd | |
- name: Fail if Sphinx doc generation has Sphinx errors | |
if: startsWith(runner.os, 'Linux') | |
run: | | |
if [ "$( pushd docs/ > /dev/null && ./gen-sphinx-html.sh 2>&1 | rg ": (ERROR|WARNING|CRITICAL): " | wc -l ; popd > /dev/null ; )" != "0" ] ; then exit 1 ; fi ; | |
- name: Reset Git repo a second time after Sphinx documentation generation | |
if: startsWith(runner.os, 'Linux') | |
run: git clean -fd | |
- name: Run tools using pytest under code coverage | |
run: python -u -m pytest --cov --mypy --pylint --ruff --ruff-format | |
- name: Try running the package | |
run: python -u -m rustpy01 | |
- name: Use aria2 to download enwik9 zipped test data for the Large Text Compression Benchmark. | |
if: startsWith(runner.os, 'Linux') | |
run: aria2c https://web.archive.org/web/20231130154044/http://mattmahoney.net/dc/enwik9.zip | |
- name: Unzip enwik9 test data | |
if: startsWith(runner.os, 'Linux') | |
run: unzip enwik9.zip | |
- name: Verify enwik9 test data | |
if: startsWith(runner.os, 'Linux') | |
run: echo "2996e86fb978f93cca8f566cc56998923e7fe581 enwik9" | sha1sum -c | |
- name: Copy enwik9 file to backup location | |
if: startsWith(runner.os, 'Linux') | |
run: cp enwik9 "$HOME"/backup-enwik9.txt ; | |
- name: Run benchmark command from README, should default to Rust function | |
if: startsWith(runner.os, 'Linux') | |
run: cp ~/backup-enwik9.txt enwik9.txt ; date ; time python -u -m rustpy01.truncate ; date ; rm enwik9.txt ; | |
- name: Switch to the naive Python function | |
if: startsWith(runner.os, 'Linux') | |
run: sd "truncate_file_lines\(desired_file," "py_truncate_file_lines(desired_file," python/rustpy01/truncate.py ; | |
- name: Re-run benchmark command from README, this time with the naive Python function | |
if: startsWith(runner.os, 'Linux') | |
run: cp ~/backup-enwik9.txt enwik9.txt ; date ; time python -u -m rustpy01.truncate ; date ; rm enwik9.txt ; | |
- name: Revert truncate.py since it has been changed | |
run: git checkout -- python/rustpy01/truncate.py ; | |
- name: Switch to the fast Python function | |
if: startsWith(runner.os, 'Linux') | |
run: sd "truncate_file_lines\(desired_file," "fast_py_truncate_file_lines(desired_file," python/rustpy01/truncate.py ; | |
- name: Re-run benchmark command from README, this time with the fast Python function | |
if: startsWith(runner.os, 'Linux') | |
run: cp ~/backup-enwik9.txt enwik9.txt ; date ; time python -u -m rustpy01.truncate ; date ; rm enwik9.txt ; | |
- name: Revert truncate.py since it has been changed | |
run: git checkout -- python/rustpy01/truncate.py ; | |
- name: Upload coverage to Codecov | |
uses: codecov/codecov-action@v3 | |
continue-on-error: true # codecov limits number of uploads allowed for each commit | |
with: | |
env_vars: OS,PYTHON | |
fail_ci_if_error: true # optional (default = false) | |
verbose: true |