From 5301889d258f805325791b9872632c4772a24ef9 Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Wed, 6 Nov 2024 08:14:59 +0100 Subject: [PATCH] Add tests --- .github/workflows/checks.yml | 46 --------------------- .github/workflows/cruft.yml | 79 ++++++++++++++++++++++++++++++++++++ .github/workflows/ndex.yml | 2 +- .github/workflows/tests.yml | 78 +++++++++++++++++++++++++++++++++++ 4 files changed, 158 insertions(+), 47 deletions(-) delete mode 100644 .github/workflows/checks.yml create mode 100644 .github/workflows/cruft.yml create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml deleted file mode 100644 index ebf64fc2..00000000 --- a/.github/workflows/checks.yml +++ /dev/null @@ -1,46 +0,0 @@ -name: Check mappings - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - lint: - name: Lint - runs-on: ubuntu-latest - strategy: - matrix: - python-version: [ "3.11", "3.8" ] - steps: - - uses: actions/checkout@v2 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: pip install tox - - name: Check manifest - run: tox -e manifest - - name: Check package metadata with Pyroma - run: tox -e pyroma - - name: Check code style with flake8 - run: tox -e flake8 - tests: - name: Tests - runs-on: ubuntu-latest - strategy: - matrix: - python-version: [ "3.11", "3.8" ] - steps: - - name: Check out repo - uses: actions/checkout@v2 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: pip install tox - - name: Run checks - run: tox -e py diff --git a/.github/workflows/cruft.yml b/.github/workflows/cruft.yml new file mode 100644 index 00000000..7442c9f5 --- /dev/null +++ b/.github/workflows/cruft.yml @@ -0,0 +1,79 @@ +# from https://cruft.github.io/cruft/#automating-updates-with-github-actions + +name: Update repository with Cruft + +permissions: + contents: write + pull-requests: write + +on: + workflow_dispatch: + schedule: + - cron: "0 2 * * 1" # Every Monday at 2am + +jobs: + update: + runs-on: ubuntu-latest + strategy: + fail-fast: true + matrix: + include: + - add-paths: . + body: Use this to merge the changes to this repository. + branch: cruft/update + commit-message: "chore: accept new Cruft update" + title: New updates detected with Cruft + - add-paths: .cruft.json + body: Use this to reject the changes in this repository. + branch: cruft/reject + commit-message: "chore: reject new Cruft update" + title: Reject new updates detected with Cruft + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-python@v4 + with: + python-version: "3.10" + + - name: Install Cruft + run: pip3 install cruft + + - name: Check if update is available + continue-on-error: false + id: check + run: | + CHANGES=0 + if [ -f .cruft.json ]; then + if ! cruft check; then + CHANGES=1 + fi + else + echo "No .cruft.json file" + fi + + echo "has_changes=$CHANGES" >> "$GITHUB_OUTPUT" + + - name: Run update if available + if: steps.check.outputs.has_changes == '1' + run: | + git config --global user.email "you@example.com" + git config --global user.name "GitHub" + + cruft update --skip-apply-ask --refresh-private-variables + git restore --staged . + + - name: Create pull request + if: steps.check.outputs.has_changes == '1' + uses: peter-evans/create-pull-request@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + add-paths: ${{ matrix.add-paths }} + commit-message: ${{ matrix.commit-message }} + branch: ${{ matrix.branch }} + delete-branch: true + branch-suffix: timestamp + title: ${{ matrix.title }} + body: | + This is an autogenerated PR. ${{ matrix.body }} + + [Cruft](https://cruft.github.io/cruft/) has detected updates from the Cookiecutter repository. diff --git a/.github/workflows/ndex.yml b/.github/workflows/ndex.yml index 571ebd6f..81d8b6b4 100644 --- a/.github/workflows/ndex.yml +++ b/.github/workflows/ndex.yml @@ -14,7 +14,7 @@ jobs: - uses: actions/checkout@master - uses: actions/setup-python@v2 with: - python-version: "3.9" + python-version: "3.12" - name: Install dependencies run: | pip install tox diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..ebf81a3b --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,78 @@ +# This file configures the continuous integration (CI) system on GitHub. +# Introductory materials can be found here: https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions. +# Documentation for editing this file can be found here: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions + +name: Tests + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + lint: + name: Code Quality + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [ "3.12", "3.9" ] + tox-command: ["manifest", "lint", "pyroma", "mypy"] + steps: + - uses: actions/checkout@v4 + - name: "Install uv" + uses: "astral-sh/setup-uv@v3" + with: + enable-cache: true + cache-dependency-glob: "pyproject.toml" + - name: "Run command" + run: | + uvx -p ${{ matrix.python-version }} --with tox-uv tox -e ${{ matrix.tox-command }} + + docs: + name: Documentation + runs-on: ubuntu-latest + strategy: + matrix: + # We only test documentation on the latest version + # sphinx 8.0 / sphinx-rtd-theme 3.0 discontinued Python 3.9 support + # a year early, which prompted re-thinking about this. + python-version: [ "3.12" ] + steps: + - uses: actions/checkout@v4 + - name: "Install uv" + uses: "astral-sh/setup-uv@v3" + with: + enable-cache: true + cache-dependency-glob: "pyproject.toml" + - name: Install dependencies + run: | + sudo apt-get install graphviz + - name: Check RST conformity with doc8 + run: uvx -p ${{ matrix.python-version }} --with tox-uv tox -e doc8 + - name: Check docstring coverage + run: uvx -p ${{ matrix.python-version }} --with tox-uv tox -e docstr-coverage + - name: Check documentation build with Sphinx + run: uvx -p ${{ matrix.python-version }} --with tox-uv tox -e docs-test + tests: + name: Tests + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ ubuntu-latest ] + python-version: [ "3.12", "3.9" ] + steps: + - uses: actions/checkout@v4 + - name: "Install uv" + uses: "astral-sh/setup-uv@v3" + with: + enable-cache: true + cache-dependency-glob: "pyproject.toml" + - name: Test with pytest and generate coverage file + run: + uvx -p ${{ matrix.python-version }} --with tox-uv tox -e py + - name: Upload coverage report to codecov + uses: codecov/codecov-action@v4 + if: success() + with: + file: coverage.xml