Skip to content

Commit

Permalink
ci: Refactor CI with resusable, custom GitHub Action (#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
mansenfranzen authored Apr 12, 2024
1 parent 532b54f commit 0d582c7
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 43 deletions.
55 changes: 55 additions & 0 deletions .github/actions/invoke-tox/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: 'Setup Test Environment'
description: 'Common setup for testing workflows'
inputs:

python-version:
description: 'Define the Python version to use'
required: false
default: '3.x'

install-graphviz:
description: 'Install graphviz and graphviz-dev'
required: false
default: 'false'

tox-environment:
description: 'Tox environment to run'
required: true

codacy:
description: 'Enable code coverage by providing Codacy token'
required: false

outputs:
random-number:
description: "Random number"
value: ${{ steps.random-number-generator.outputs.random-number }}
runs:
using: "composite"
steps:
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}

- name: Install Graphviz
if: ${{ inputs.install-graphviz == 'true' }}
run: sudo apt-get install graphviz graphviz-dev
shell: bash

- name: Install Tox
run: pip install tox
shell: bash

- name: Invoke Tox
run: tox -e ${{ inputs.tox-environment }}
shell: bash

- name: Code Coverage
if: ${{ inputs.codacy}}
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true
token: ${{ inputs.codacy}}


84 changes: 41 additions & 43 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,76 +49,74 @@ jobs:
sphinx_version: "72"
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- name: Checkout
uses: actions/checkout@v4

- name: Setup Test Environment and Run Tox
uses: ./.github/actions/invoke-tox
with:
python-version: ${{ matrix.python_version }}
- run: sudo apt-get install graphviz graphviz-dev
- run: pip install tox
- run: tox -e pydantic${{ matrix.pydantic_version }}-sphinx${{ matrix.sphinx_version }}
- name: Code Coverage
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true
token: ${{ secrets.CODACY_PROJECT_TOKEN }}
tox-environment: pydantic${{ matrix.pydantic_version }}-sphinx${{ matrix.sphinx_version }}
install-graphviz: true
codacy: ${{ secrets.CODACY_PROJECT_TOKEN }}

test-latest-version:
environment: Tests
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- run: sudo apt-get install graphviz graphviz-dev
- run: pip install tox
- run: tox -e latest
- name: Code Coverage
uses: codecov/codecov-action@v4
- name: Checkout
uses: actions/checkout@v4

- name: Setup Test Environment and Run Tox
uses: ./.github/actions/invoke-tox
with:
fail_ci_if_error: true
token: ${{ secrets.CODACY_PROJECT_TOKEN }}
tox-environment: latest
install-graphviz: true
codacy: ${{ secrets.CODACY_PROJECT_TOKEN }}

test-no-erdantic-version:
environment: Tests
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- name: Checkout
uses: actions/checkout@v4

- name: Setup Test Environment and Run Tox
uses: ./.github/actions/invoke-tox
with:
python-version: '3.x'
- run: pip install tox
- run: tox -e no_erdantic
tox-environment: no_erdantic

test-development-versions-deps:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- name: Checkout
uses: actions/checkout@v4

- name: Setup Test Environment and Run Tox
uses: ./.github/actions/invoke-tox
with:
python-version: '3.x'
- run: sudo apt-get install graphviz graphviz-dev
- run: pip install tox
- run: tox -e development
tox-environment: development
install-graphviz: true
continue-on-error: true
- run: echo "Done"

linter:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- name: Checkout
uses: actions/checkout@v4

- name: Setup Test Environment and Run Tox
uses: ./.github/actions/invoke-tox
with:
python-version: '3.x'
- run: pip install tox
- run: tox -e linter
tox-environment: linter

formatter:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- name: Checkout
uses: actions/checkout@v4

- name: Setup Test Environment and Run Tox
uses: ./.github/actions/invoke-tox
with:
python-version: '3.x'
- run: pip install tox
- run: tox -e formatter
tox-environment: formatter

0 comments on commit 0d582c7

Please sign in to comment.