Skip to content

Commit

Permalink
Add test workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
druzsan committed Feb 8, 2024
1 parent 554ee6c commit e2b6a0f
Show file tree
Hide file tree
Showing 9 changed files with 260 additions and 113 deletions.
20 changes: 4 additions & 16 deletions .github/workflows/test.yml → .github/workflows/basic-usage.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 1. Basic usage
name: '1. ⏱️ Basic usage'

on: push

Expand All @@ -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
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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'
Expand All @@ -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
57 changes: 57 additions & 0 deletions .github/workflows/dynamic-matrix-builtin.yml
Original file line number Diff line number Diff line change
@@ -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
50 changes: 50 additions & 0 deletions .github/workflows/dynamic-matrix.yml
Original file line number Diff line number Diff line change
@@ -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
60 changes: 0 additions & 60 deletions .github/workflows/issue-5.yml

This file was deleted.

53 changes: 53 additions & 0 deletions .github/workflows/reuse-matrix-builtin.yml
Original file line number Diff line number Diff line change
@@ -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
59 changes: 59 additions & 0 deletions .github/workflows/reuse-matrix.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading

0 comments on commit e2b6a0f

Please sign in to comment.