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 themainbranch.
Jobs Overview
The workflow defines four jobs:
actionlint: Validates the syntax and structure of GitHub Action workflow files.lint-cruft: Ensures no.rejfiles 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@v4to fetch the repository. - Download actionlint: Fetches
actionlintusing a bash script. - Check workflow files: Runs
actionlintto validate the workflow files.
2. lint-cruft
runs-on: ubuntu-latest
Steps:
- Checkout: Uses
actions/checkout@v4to fetch the repository. - Check for
.rejfiles: Fails the job if.rejfiles are found, indicating an unsuccessful project structure update.
3. pre-commit
runs-on: ubuntu-latest
Steps:
- Checkout: Uses
actions/checkout@v4to fetch the repository. - Install
uv: Sets up theuvtool 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@v4to fetch the repository. - Install
uv: Sets up theuvtool usingastral-sh/setup-uv@v5. - Set up Python: Configures Python according to the
.python-versionfile 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
pytestand generates a coverage report in XML format. - Upload coverage report: Uploads the coverage report to Codecov using
codecov/codecov-action@v4. Requires aCODECOV_TOKENsecret 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.