Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Refactor CI with resusable, custom GitHub Action #252

Merged
merged 8 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading