New batchZero to DevOps starts 29 Nov · limited seatsReserve your seat
Cheat sheetsGitHub ActionsGitHub Actions
ProSheet 06 of 6

Advanced Workflows & Best Practices

A comprehensive developer cheatsheet covering advanced GitHub Actions workflows and best practices, featuring essential YAML configurations and operational patterns for complex matrix builds, self-hosted runners, reusable workflows, composite actions, OIDC cloud authentication, and environment protection rules.

Advanced Matrix Strategies

Combining Multiple Dimensions

yaml
jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [18, 20, 22]
        os: [ubuntu-latest, windows-latest, macos-latest]
        browser: [chrome, firefox]

    steps:
      - uses: actions/checkout@v4
      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node-version }}
      - name: Run tests
        run: npm test -- --browser=${{ matrix.browser }}

Include/Exclude in Matrix

yaml
strategy:
  matrix:
    node-version: [18, 20, 22]
    os: [ubuntu-latest, windows-latest]
    include:
      # Add extra config for specific combination
      - node-version: 18
        os: ubuntu-latest
        coverage: true
      - node-version: 20
        os: windows-latest
        environment: production
    exclude:
      # Remove specific combinations
      - node-version: 18
        os: windows-latest
      - node-version: 22
        os: windows-latest

Dynamic Matrix from Output

yaml
jobs:
  setup:
    runs-on: ubuntu-latest
    outputs:
      versions: ${{ steps.versions.outputs.matrix }}
    steps:
      - id: versions
        run: |
          echo "matrix=[\"18\", \"20\", \"22\"]" >> $GITHUB_OUTPUT

  test:
    needs: setup
    runs-on: ubuntu-latest
    strategy:
      matrix:
        version: ${{ fromJSON(needs.setup.outputs.versions) }}
    steps:
      - run: echo "Testing Node.js ${{ matrix.version }}"

Fail-Fast Control

yaml
strategy:
  matrix:
    node-version: [18, 20, 22]
    os: [ubuntu-latest, windows-latest]
  fail-fast: false  # Continue other jobs if one fails
  max-parallel: 4   # Limit concurrent runs
The rest of this sheet is locked3 Pro sheets unlock together, across every toolEveryPro sheet, every toolLifetimeone payment, no renewalNewsheets included as they shipOne-time payment · lifetime access