GitHub Action: CI/CD Tests
This GitHub Action workflow is designed to streamline and automate the CI/CD processes for your project. The workflow is triggered on pull requests and pushes to the main
branch. It performs several key tasks including linting, pre-commit checks, project update validation, and running tests with coverage reporting.
Workflow Details
Triggers (on
)
pull_request
: The workflow runs when a pull request is opened or updated.push
: The workflow is triggered for pushes to themain
branch.
Jobs Overview
The workflow defines four jobs:
actionlint
: Validates the syntax and structure of GitHub Action workflow files.lint-cruft
: Ensures no.rej
files are present, verifying that project updates were applied correctly.pre-commit
: Executes pre-commit hooks to enforce code standards and formatting in all files.test
: Runs unit tests with coverage reporting and uploads the results to Codecov.
Job Details
1. actionlint
runs-on
: ubuntu-latest
Steps:
- Checkout: Uses
actions/checkout@v4
to fetch the repository. - Download actionlint: Fetches
actionlint
using a bash script. - Check workflow files: Runs
actionlint
to validate the workflow files.
2. lint-cruft
runs-on
: ubuntu-latest
Steps:
- Checkout: Uses
actions/checkout@v4
to fetch the repository. - Check for
.rej
files: Fails the job if.rej
files are found, indicating an unsuccessful project structure update.
3. pre-commit
runs-on
: ubuntu-latest
Steps:
- Checkout: Uses
actions/checkout@v4
to fetch the repository. - Install
uv
: Sets up theuv
tool usingastral-sh/setup-uv@v5
. - Run pre-commit hooks: Executes all pre-commit hooks across the repository, displaying any failures with colorized diffs.
4. test
runs-on
: ubuntu-latest
Steps:
- Checkout: Uses
actions/checkout@v4
to fetch the repository. - Install
uv
: Sets up theuv
tool usingastral-sh/setup-uv@v5
. - Set up Python: Configures Python according to the
.python-version
file usingactions/setup-python@v5
. - Install the project: Installs the project with all extras and development dependencies using
uv sync
. - Run tests with coverage: Executes tests with
pytest
and generates a coverage report in XML format. - Upload coverage report: Uploads the coverage report to Codecov using
codecov/codecov-action@v4
. Requires aCODECOV_TOKEN
secret stored in the repository settings.
In summary, this workflow automates linting, project update validation, pre-commit checks, testing, and coverage reporting for a robust CI/CD pipeline.