From e2b6a0fc4f9f76fb3cefa4d72cbd1242d2998e93 Mon Sep 17 00:00:00 2001 From: Alexander Druz Date: Thu, 8 Feb 2024 22:22:06 +0100 Subject: [PATCH] Add test workflows --- .../workflows/{test.yml => basic-usage.yml} | 20 ++----- .github/workflows/ci.yml | 16 ++--- .github/workflows/dynamic-matrix-builtin.yml | 57 ++++++++++++++++++ .github/workflows/dynamic-matrix.yml | 50 ++++++++++++++++ .github/workflows/issue-5.yml | 60 ------------------- .github/workflows/reuse-matrix-builtin.yml | 53 ++++++++++++++++ .github/workflows/reuse-matrix.yml | 59 ++++++++++++++++++ Makefile | 4 +- README.md | 54 ++++++++--------- 9 files changed, 260 insertions(+), 113 deletions(-) rename .github/workflows/{test.yml => basic-usage.yml} (52%) create mode 100644 .github/workflows/dynamic-matrix-builtin.yml create mode 100644 .github/workflows/dynamic-matrix.yml delete mode 100644 .github/workflows/issue-5.yml create mode 100644 .github/workflows/reuse-matrix-builtin.yml create mode 100644 .github/workflows/reuse-matrix.yml diff --git a/.github/workflows/test.yml b/.github/workflows/basic-usage.yml similarity index 52% rename from .github/workflows/test.yml rename to .github/workflows/basic-usage.yml index 558c45c..5fee728 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/basic-usage.yml @@ -1,4 +1,4 @@ -name: 1. Basic usage +name: '1. โฑ๏ธ Basic usage' on: push @@ -8,25 +8,13 @@ jobs: runs-on: ubuntu-latest outputs: matrix: ${{ steps.setup-matrix.outputs.matrix }} - env: - REF: ${{ github.ref_name }} steps: - - run: echo $REF - - run: echo ${{ env.REF }} - id: setup-matrix - uses: druzsan/setup-matrix@$REF + uses: druzsan/setup-matrix@feature/use-python-dockerfile with: matrix: | - os: [ubuntu-latest, macos-latest] - python-version: [3.8, 3.10, 3.12] - include: - - os: windows-latest - python-version: 3.8 - - os: windows-latest - python-version: 3.10 - exclude: - - os: macos-latest - python-version: 3.8 + os: ubuntu-latest windows-latest macos-latest, + python-version: 3.8 3.9 3.10 # Setup python and print version setup-python: needs: setup-matrix diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 28b5f7d..1346f2a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,8 +13,8 @@ jobs: with: python-version: 3.12 - run: python -m pip install -IU pip setuptools wheel - - run: make init - - run: make check-format + - run: pip install -IUr requirements.txt -r requirements-dev.txt + - run: black --check . typecheck: name: '๐Ÿ” Check Types' runs-on: ubuntu-latest @@ -24,8 +24,8 @@ jobs: with: python-version: 3.12 - run: python -m pip install -IU pip setuptools wheel - - run: make init - - run: make typecheck + - run: pip install -IUr requirements.txt -r requirements-dev.txt + - run: mypy main.py && mypy tests lint: name: '๐Ÿ” Lint' runs-on: ubuntu-latest @@ -35,8 +35,8 @@ jobs: with: python-version: 3.12 - run: python -m pip install -IU pip setuptools wheel - - run: make init - - run: make lint + - run: pip install -IUr requirements.txt -r requirements-dev.txt + - run: ruff check main.py tests # Test stage unit-test: name: '๐Ÿงช Unit-Test' @@ -47,5 +47,5 @@ jobs: with: python-version: 3.12 - run: python -m pip install -IU pip setuptools wheel - - run: make init - - run: make test + - run: pip install -IUr requirements.txt -r requirements-dev.txt + - run: python -m pytest diff --git a/.github/workflows/dynamic-matrix-builtin.yml b/.github/workflows/dynamic-matrix-builtin.yml new file mode 100644 index 0000000..2c43456 --- /dev/null +++ b/.github/workflows/dynamic-matrix-builtin.yml @@ -0,0 +1,57 @@ +name: '3.1. ๐Ÿงช Test (built-in matrix)' + +on: push + +jobs: + # Run unit-test a dev branch + unit-test-dev: + name: '๐Ÿงช Unit-Test (dev)' + if: github.ref != 'refs/heads/main' && !startsWith(github.ref, 'refs/tags/') + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: 3.8 + - run: python -m pip install -IU pip setuptools wheel + - run: pip install -IUr requirements.txt -r requirements-dev.txt + - run: python -m pytest + # Run unit-test on the main branch + unit-test-main: + name: '๐Ÿงช Unit-Test (main)' + if: github.ref == 'refs/heads/main' + strategy: + matrix: + os: [ubuntu-latest] + python-version: [3.8, 3.10, 3.12] + include: + - os: windows-latest + python-version: 3.8 + - os: macos-latest + python-version: 3.8 + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - run: python -m pip install -IU pip setuptools wheel + - run: pip install -IUr requirements.txt -r requirements-dev.txt + - run: python -m pytest + # Run unit-test on a tag + unit-test-tag: + name: '๐Ÿงช Unit-Test (tag)' + if: startsWith(github.ref, 'refs/tags/') + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + python-version: [3.8, 3.10, 3.12] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - run: python -m pip install -IU pip setuptools wheel + - run: pip install -IUr requirements.txt -r requirements-dev.txt + - run: python -m pytest diff --git a/.github/workflows/dynamic-matrix.yml b/.github/workflows/dynamic-matrix.yml new file mode 100644 index 0000000..c53295d --- /dev/null +++ b/.github/workflows/dynamic-matrix.yml @@ -0,0 +1,50 @@ +name: '3.2. ๐Ÿงช Test (setup matrix action)' + +on: push + +jobs: + # Setup matrix + setup-matrix: + runs-on: ubuntu-latest + steps: + - if: startsWith(github.ref, 'refs/tags/') + uses: druzsan/setup-matrix@feature/use-python-dockerfile + with: + matrix: | + os: ubuntu-latest windows-latest macos-latest, + python-version: 3.8 3.10 3.12 + - if: github.ref == 'refs/heads/main' + uses: druzsan/setup-matrix@feature/use-python-dockerfile + with: + matrix: | + os: ubuntu-latest, + python-version: 3.8 3.10 3.12 + include: | + os: windows-latest python-version: 3.8, + os: macos-latest python-version: 3.8 + - if: github.ref != 'refs/heads/main' && !startsWith(github.ref, 'refs/tags/') + uses: druzsan/setup-matrix@feature/use-python-dockerfile + with: + matrix: | + os: ubuntu-latest, + python-version: 3.8 + # MATRIX environment variable is set by the last executed action + - id: setup-matrix + run: echo "matrix=$MATRIX" >> $GITHUB_OUTPUT + outputs: + matrix: ${{ steps.setup-matrix.outputs.matrix }} + # Run unit-test + unit-test: + name: '๐Ÿงช Unit-Test' + needs: setup-matrix + strategy: + matrix: ${{ fromJson(needs.setup-matrix.outputs.matrix) }} + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - run: python -m pip install -IU pip setuptools wheel + - run: pip install -IUr requirements.txt -r requirements-dev.txt + - run: python -m pytest diff --git a/.github/workflows/issue-5.yml b/.github/workflows/issue-5.yml deleted file mode 100644 index 6f55dcc..0000000 --- a/.github/workflows/issue-5.yml +++ /dev/null @@ -1,60 +0,0 @@ -name: Issue 5 -on: push - -jobs: - # Setup matrix - setup-matrix: - runs-on: ubuntu-latest - outputs: - matrix: ${{ steps.setup-matrix.outputs.matrix }} - steps: - - id: setup-matrix - uses: druzsan/setup-matrix@feature/use-python-dockerfile - with: - matrix: | - include: - - os: linux - cpu: amd64 - run-on: ubuntu-latest - shell: bash -e - - os: macos - cpu: amd64 - run-on: macos-latest - shell: bash -e - - os: windows - cpu: amd64 - run-on: windows-latest - shell: msys2 - - # Setup python and print version - build: - needs: setup-matrix - strategy: - matrix: ${{ fromJson(needs.setup-matrix.outputs.matrix) }} - runs-on: ${{ matrix.run-on }} - name: '${{ matrix.os }}-${{ matrix.cpu }}-${{ matrix.shell }}' - steps: - - name: Checkout sources - uses: actions/checkout@v4 - - build-builtin: - strategy: - matrix: - include: - - os: linux - cpu: amd64 - run-on: ubuntu-latest - shell: bash -e - - os: macos - cpu: amd64 - run-on: macos-latest - shell: bash -e - - os: windows - cpu: amd64 - run-on: windows-latest - shell: msys2 - runs-on: ${{ matrix.run-on }} - name: '${{ matrix.os }}-${{ matrix.cpu }}-${{ matrix.shell }}' - steps: - - name: Checkout sources - uses: actions/checkout@v4 diff --git a/.github/workflows/reuse-matrix-builtin.yml b/.github/workflows/reuse-matrix-builtin.yml new file mode 100644 index 0000000..5640811 --- /dev/null +++ b/.github/workflows/reuse-matrix-builtin.yml @@ -0,0 +1,53 @@ +name: '2.1. ๐Ÿ” CI (built-in matrix)' + +on: push + +jobs: + # Check code formatting + check-format: + name: '๐Ÿ” Check Formatting' + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + python-version: [3.8, 3.10, 3.12] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - run: python -m pip install -IU pip setuptools wheel + - run: pip install -IUr requirements.txt -r requirements-dev.txt + - run: black --check . + # Check code types + typecheck: + name: '๐Ÿ” Check Types' + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + python-version: [3.8, 3.10, 3.12] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - run: python -m pip install -IU pip setuptools wheel + - run: pip install -IUr requirements.txt -r requirements-dev.txt + - run: mypy main.py && mypy tests + # Lint code + lint: + name: '๐Ÿ” Lint' + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + python-version: [3.8, 3.10, 3.12] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - run: python -m pip install -IU pip setuptools wheel + - run: pip install -IUr requirements.txt -r requirements-dev.txt + - run: ruff check main.py tests diff --git a/.github/workflows/reuse-matrix.yml b/.github/workflows/reuse-matrix.yml new file mode 100644 index 0000000..cceb13d --- /dev/null +++ b/.github/workflows/reuse-matrix.yml @@ -0,0 +1,59 @@ +name: '2.2. ๐Ÿ” CI (setup matrix action)' + +on: push + +jobs: + # Setup matrix + setup-matrix: + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.setup-matrix.outputs.matrix }} + steps: + - id: setup-matrix + uses: druzsan/setup-matrix@feature/use-python-dockerfile + with: + matrix: | + os: ubuntu-latest windows-latest macos-latest, + python-version: 3.8 3.10 3.12 + # Check code formatting + check-format: + name: '๐Ÿ” Check Formatting' + strategy: + matrix: ${{ fromJson(needs.setup-matrix.outputs.matrix) }} + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - run: python -m pip install -IU pip setuptools wheel + - run: pip install -IUr requirements.txt -r requirements-dev.txt + - run: black --check . + # Check code types + typecheck: + name: '๐Ÿ” Check Types' + strategy: + matrix: ${{ fromJson(needs.setup-matrix.outputs.matrix) }} + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - run: python -m pip install -IU pip setuptools wheel + - run: pip install -IUr requirements.txt -r requirements-dev.txt + - run: mypy main.py && mypy tests + # Lint code + lint: + name: '๐Ÿ” Lint' + strategy: + matrix: ${{ fromJson(needs.setup-matrix.outputs.matrix) }} + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - run: python -m pip install -IU pip setuptools wheel + - run: pip install -IUr requirements.txt -r requirements-dev.txt + - run: ruff check main.py tests diff --git a/Makefile b/Makefile index e7e5500..56f27e3 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ init: # Install all dependencies .PHONY: clean clean: ## Clean project - rm -rf .ruff_cache/ .mypy_cache/ node_modules/ .direnv/ + rm -rf .ruff_cache/ .mypy_cache/ node_modules/ .direnv/ .venv/ .PHONY: check-format check-format: ## Check code formatting @@ -35,7 +35,7 @@ lint: ## Lint all source files .PHONY: test test: ## Run unit-test - python -m pytest tests/unit + python -m pytest .PHONY: docker-image docker-build: # Build Docker image diff --git a/README.md b/README.md index 70e4ea5..ac9387a 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ jobs: matrix: ${{ fromJson(needs.setup-matrix.outputs.matrix) }} runs-on: ${{ matrix.os }} steps: - - uses: actions/setup-python@v4 + - uses: actions/setup-python@v5 with: python-version: '${{ matrix.python-version }}' - run: python --version @@ -147,8 +147,8 @@ jobs: python-version: ['3.8', '3.9', '3.10'] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: python-version: '${{ matrix.python-version }}' cache: pip @@ -162,8 +162,8 @@ jobs: python-version: ['3.8', '3.9', '3.10'] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: python-version: '${{ matrix.python-version }}' cache: pip @@ -180,8 +180,8 @@ jobs: python-version: ['3.8', '3.9', '3.10'] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: python-version: '${{ matrix.python-version }}' cache: pip @@ -212,8 +212,8 @@ jobs: matrix: ${{ fromJson(needs.setup-matrix.outputs.matrix) }} runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: python-version: '${{ matrix.python-version }}' cache: pip @@ -225,8 +225,8 @@ jobs: matrix: ${{ fromJson(needs.setup-matrix.outputs.matrix) }} runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: python-version: '${{ matrix.python-version }}' cache: pip @@ -241,8 +241,8 @@ jobs: matrix: ${{ fromJson(needs.setup-matrix.outputs.matrix) }} runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: python-version: '${{ matrix.python-version }}' cache: pip @@ -263,11 +263,11 @@ jobs: # No matrix setup # Test code on a dev branch unit-test-dev: - if: github.ref != 'refs/heads/main' && !startsWith(github.ref, 'refs/tags/v') + if: github.ref != 'refs/heads/main' && !startsWith(github.ref, 'refs/tags/') runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: python-version: '3.8' - run: python -m pip install -r requirements.txt @@ -286,23 +286,23 @@ jobs: python-version: '3.8' runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: python-version: '${{ matrix.python-version }}' - run: python -m pip install -r requirements.txt - run: python -m pytest # Test code on a tag unit-test-tag: - if: startsWith(github.ref, 'refs/tags/v') + if: startsWith(github.ref, 'refs/tags/') strategy: matrix: os: [ubuntu-latest, windows-latest, macos-latest] python-version: ['3.8', '3.9', '3.10'] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: python-version: '${{ matrix.python-version }}' - run: python -m pip install -r requirements.txt @@ -317,7 +317,7 @@ jobs: setup-matrix: runs-on: ubuntu-latest steps: - - if: startsWith(github.ref, 'refs/tags/v') + - if: startsWith(github.ref, 'refs/tags/') uses: druzsan/setup-matrix@v1 with: matrix: | @@ -332,17 +332,17 @@ jobs: include: | os: windows-latest python-version: 3.8, os: macos-latest python-version: 3.8 - - if: github.ref != 'refs/heads/main' && !startsWith(github.ref, 'refs/tags/v') + - if: github.ref != 'refs/heads/main' && !startsWith(github.ref, 'refs/tags/') uses: druzsan/setup-matrix@v1 with: matrix: | os: ubuntu-latest, python-version: 3.8 # MATRIX environment variable is set by the last executed action - - id: set-matrix + - id: setup-matrix run: echo "matrix=$MATRIX" >> $GITHUB_OUTPUT outputs: - matrix: ${{ steps.set-matrix.outputs.matrix }} + matrix: ${{ steps.setup-matrix.outputs.matrix }} # Test code unit-test: needs: setup-matrix @@ -350,8 +350,8 @@ jobs: matrix: ${{ fromJson(needs.setup-matrix.outputs.matrix) }} runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: python-version: '${{ matrix.python-version }}' - run: python -m pip install -r requirements.txt