RousselTMLEARNING

DevOps

Writing GitHub Actions workflows

Mastering workflow syntax: triggers and filters, jobs and needs, matrices, if conditions, contexts and expressions, outputs between steps and jobs, GITHUB_OUTPUT, GITHUB_ENV and summary, cache, artifacts, service containers and concurrency.

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"
  • on sets triggers, with branches, paths and paths-ignore filters.
  • concurrency cancels the previous run of the same branch; timeout-minutes bounds duration.
  • setup-python handles the pip cache itself; actions/cache covers other cases.

Contexts #

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_OUTPUT publishes a step output, $GITHUB_ENV a variable for following steps, $GITHUB_STEP_SUMMARY a 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 : The set-output and save-state commands are removed: use the $GITHUB_OUTPUT and $GITHUB_STATE files.

Commands to know #

Commands to know
  • gh run view --log-failed : log of failed steps
  • gh run download <id> : download artifacts
  • gh run rerun --failed : rerun failed jobs
  • gh cache list : cache entries

Sources #

Checked in November 2026: CI/CD platforms change every month, check versions and plans in the vendor's documentation.

Related articles

GitHub Actions: concepts and how it works

Discover GitHub Actions: events, workflows, jobs, steps and actions, the Marketplace, hosted runners, minute …

GitHub Actions runners: hosted, self-hosted and ARC

Choosing where workflows run: hosted runners and images, larger runners, self-hosted runners (installation, l…

Delivering with GitHub Actions: GHCR, environments, OIDC and attestations

Building and deploying with GitHub Actions: publishing an image to GitHub Container Registry with GITHUB_TOKE…

Keep learning

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!