1. A complete workflow #
Tests on two Python versions.
The file #
name: CI
on:
push:
branches: [main]
pull_request:
permissions:
contents: read
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
matrix:
python: ["3.12", "3.13"]
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v7
with:
python-version: ${{ matrix.python }}
cache: pip
cache-dependency-path: requirements-dev.txt
- run: pip install -r requirements-dev.txt
- run: pytest --junitxml=rapport-${{ matrix.python }}.xml
- uses: actions/upload-artifact@v7
if: always()
with:
name: rapport-${{ matrix.python }}
path: rapport-${{ matrix.python }}.xml
- run: echo "### Tests Python ${{ matrix.python }} réussis :white_check_mark:" >> "$GITHUB_STEP_SUMMARY"onsets triggers, withbranches,pathsandpaths-ignorefilters.concurrencycancels the previous run of the same branch;timeout-minutesbounds duration.setup-pythonhandles the pip cache itself;actions/cachecovers other cases.
Contexts #
2. Data between steps and jobs #
Outputs, environment, summary.
Outputs #
jobs:
version:
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.calc.outputs.tag }}
steps:
- id: calc
run: echo "tag=$(date +%Y.%m.%d)-${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
build:
needs: version
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- run: echo "Version ${{ needs.version.outputs.tag }}"$GITHUB_OUTPUTpublishes a step output,$GITHUB_ENVa variable for following steps,$GITHUB_STEP_SUMMARYa Markdown summary shown on the run page.- The
success(),failure(),always(),cancelled()functions condition a step on the job state. - Service containers (
services: postgres:) provide a database for the duration of the job.
Watch out : Theset-outputandsave-statecommands are removed: use the$GITHUB_OUTPUTand$GITHUB_STATEfiles.
Commands to know #
Commands to know
gh run view --log-failed: log of failed stepsgh run download <id>: download artifactsgh run rerun --failed: rerun failed jobsgh cache list: cache entries
Sources #
Checked in November 2026: CI/CD platforms change every month, check versions and plans in the vendor's documentation.
