Syntaxe des workflows GitHub Actions

VérifiéPrudence

Guide pour créer et modifier des fichiers de workflow GitHub Actions, compatible avec act pour les tests locaux.

Spar Skills Guide Bot
DevOpsIntermédiaire
26/07/2026
Claude CodeCursor
#github-actions#ci-cd#workflow-syntax#yaml#act

Recommandé pour

Synthèse automatique

Ce skill guide la rédaction et la modification de fichiers de workflow GitHub Actions (.github/workflows/*.yml), avec des exemples de déclencheurs, jobs, étapes et matrices compatibles avec une exécution locale via act.

Points forts

  • Fournit des extraits YAML concrets et copiables pour les déclencheurs (push, pull_request, workflow_dispatch, schedule), les jobs, les dépendances via needs et les matrices de build
  • Couvre les étapes conditionnelles (if, success(), failure(), always()) et l'usage de with, working-directory et shell
  • Oriente vers des workflows qui fonctionnent à la fois sur GitHub et en local avec act

Limites

  • La section sur les expressions et contextes est amorcée mais tronquée, donc la référence sur ${{ }} reste partielle
  • Ne détaille pas l'installation ni les options CLI d'act pour l'exécution locale
  • Peu de profondeur sur le durcissement sécurité (permissions minimales, épinglage par SHA, OIDC)
Quand l'utiliser

À utiliser lorsqu'il faut créer ou corriger un workflow GitHub Actions valide et testable localement.

Quand l'éviter

À éviter si vous cherchez une référence complète sur les expressions GitHub Actions ou un guide d'installation et de configuration avancée d'act.

Analyse de sécurité

Prudence
Score qualité76/100

This is reference documentation for GitHub Actions YAML syntax with no obfuscated payloads, no curl|sh installs, no destructive commands, and no instructions to send secrets to external endpoints. Its Bash usage is limited to invoking `act` locally, and the only secret-handling example uses placeholder tokens written to a local file. Because it authorizes Bash/Write/Edit and touches secret handling, it warrants mild caution, but nothing indicates malicious intent.

Points d'attention
  • •Declares Bash/Write/Edit tools and shows running `act` commands that execute workflow jobs locally, which is powerful but legitimate
  • •Example writes tokens to a local `.secrets` file and passes them via `act --secret-file`; should remind users to gitignore that file so secrets are not committed
Comment cette analyse est faite

Exemples

Matrix test workflow
Create a GitHub Actions workflow that runs npm test on Node 18, 20 and 22 across ubuntu-latest and macos-latest with fail-fast disabled.
Manual deploy trigger
Add a workflow_dispatch trigger to my deploy workflow with a choice input for staging or production, and gate the deploy step on that input.
Conditional failure step
Edit .github/workflows/ci.yml so a step runs only when a previous step fails and another always runs, then verify it locally with act.

name: act-workflow-syntax description: Use when creating or modifying GitHub Actions workflow files. Provides guidance on workflow syntax, triggers, jobs, steps, and expressions for creating valid GitHub Actions workflows that can be tested locally with act. allowed-tools:

  • Read
  • Write
  • Edit
  • Bash
  • Grep
  • Glob

Act - GitHub Actions Workflow Syntax

Use this skill when creating or modifying GitHub Actions workflow files (.github/workflows/*.yml). This covers workflow structure, triggers, jobs, steps, and best practices for workflows that work both on GitHub and locally with act.

Workflow File Structure

Every GitHub Actions workflow follows this basic structure:

name: Workflow Name
on: [push, pull_request]  # Triggers

jobs:
  job-name:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Step name
        run: echo "Commands here"

Top-Level Fields

  • name: Human-readable workflow name (optional but recommended)
  • on: Trigger events (push, pull_request, workflow_dispatch, etc.)
  • env: Environment variables available to all jobs
  • jobs: Map of job definitions
  • permissions: Token permissions for the workflow

Workflow Triggers

Event Triggers

# Single event
on: push

# Multiple events
on: [push, pull_request]

# Event with filters
on:
  push:
    branches:
      - main
      - 'releases/**'
    paths:
      - '**.js'
      - '!docs/**'
  pull_request:
    types: [opened, synchronize, reopened]

Manual Triggers

on:
  workflow_dispatch:
    inputs:
      environment:
        description: 'Target environment'
        required: true
        default: 'staging'
        type: choice
        options:
          - staging
          - production

Schedule Triggers

on:
  schedule:
    - cron: '0 9 * * 1'  # Every Monday at 9am UTC

Job Configuration

Basic Job

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm ci
      - run: npm test

Job with Environment Variables

jobs:
  deploy:
    runs-on: ubuntu-latest
    env:
      NODE_ENV: production
      API_URL: ${{ secrets.API_URL }}
    steps:
      - run: echo "Deploying to $NODE_ENV"

Job Dependencies

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - run: npm run build

  test:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - run: npm test

  deploy:
    needs: [build, test]
    runs-on: ubuntu-latest
    steps:
      - run: npm run deploy

Matrix Builds

jobs:
  test:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
        node: [18, 20, 22]
      fail-fast: false
    steps:
      - uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node }}
      - run: npm test

Steps

Using Actions

steps:
  # Checkout code
  - uses: actions/checkout@v4

  # Setup Node.js
  - uses: actions/setup-node@v4
    with:
      node-version: '20'
      cache: 'npm'

  # Upload artifacts
  - uses: actions/upload-artifact@v4
    with:
      name: dist
      path: dist/

Running Commands

steps:
  # Single line
  - run: npm install

  # Multi-line
  - run: |
      npm ci
      npm run build
      npm test

  # With name
  - name: Install dependencies
    run: npm ci

  # With working directory
  - run: npm test
    working-directory: ./packages/core

  # With shell
  - run: echo "Hello"
    shell: bash

Conditional Steps

steps:
  - name: Deploy to production
    if: github.ref == 'refs/heads/main'
    run: npm run deploy

  - name: Run on success
    if: success()
    run: echo "Previous steps succeeded"

  - name: Run on failure
    if: failure()
    run: echo "A step failed"

  - name: Always run
    if: always()
    run: echo "Runs regardless of status"

Expressions and Contexts

Common Contexts

steps:
  - run: echo "Event: ${{ github.event_name }}"
  - run: echo "Branch: ${{ github.ref_name }}"
  - run: echo "SHA: ${{ github.sha }}"
  - run: echo "Actor: ${{ github.actor }}"
  - run: echo "Job status: ${{ job.status }}"
  - run: echo "Runner OS: ${{ runner.os }}"

Using Secrets

steps:
  - run: echo "Token is set"
    env:
      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      API_KEY: ${{ secrets.API_KEY }}

Functions

steps:
  - if: contains(github.event.head_commit.message, '[skip ci]')
    run: echo "Skipping CI"

  - if: startsWith(github.ref, 'refs/tags/')
    run: echo "This is a tag"

  - if: endsWith(github.ref, '/main')
    run: echo "This is main branch"

  - run: echo "${{ format('Hello {0}', github.actor) }}"

Act-Specific Considerations

Testing Locally with Act

# Run all workflows
act

# Run specific event
act push

# Run specific job
act -j build

# Dry run (validate without executing)
act --dryrun

# List workflows
act -l

# Use specific platform
act -P ubuntu-latest=catthehacker/ubuntu:act-latest

Environment Variables for Act

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: Check environment
        run: |
          if [ "$ACT" = "true" ]; then
            echo "Running in act"
          else
            echo "Running on GitHub"
          fi

Secrets with Act

Create .secrets file for local testing:

GITHUB_TOKEN=ghp_your_token_here
API_KEY=your_api_key_here

Then run:

act --secret-file .secrets

Or pass secrets individually:

act -s GITHUB_TOKEN=ghp_token -s API_KEY=key

Best Practices

DO

✅ Use semantic job and step names ✅ Pin action versions (actions/checkout@v4) ✅ Use fail-fast: false for matrix builds to see all results ✅ Set appropriate timeout-minutes for jobs ✅ Use working-directory instead of cd commands ✅ Test workflows locally with act --dryrun before pushing ✅ Use caching for dependencies ✅ Use environments for deployment jobs

DON'T

❌ Hardcode secrets in workflow files ❌ Use latest tags for actions ❌ Run workflows on every file change (use path filters) ❌ Create overly complex workflows (split into multiple files) ❌ Ignore act compatibility when using GitHub-specific features ❌ Forget to validate YAML syntax

Common Patterns

Build and Test

name: CI
on: [push, pull_request]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: '20'
          cache: 'npm'
      - run: npm ci
      - run: npm test
      - run: npm run build

Deploy on Tag

name: Deploy
on:
  push:
    tags:
      - 'v*'

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Get version
        id: version
        run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
      - run: echo "Deploying ${{ steps.version.outputs.VERSION }}"

Monorepo with Changed Files

jobs:
  detect-changes:
    runs-on: ubuntu-latest
    outputs:
      api: ${{ steps.changes.outputs.api }}
      web: ${{ steps.changes.outputs.web }}
    steps:
      - uses: actions/checkout@v4
      - uses: dorny/paths-filter@v3
        id: changes
        with:
          filters: |
            api:
              - 'packages/api/**'
            web:
              - 'packages/web/**'

  build-api:
    needs: detect-changes
    if: needs.detect-changes.outputs.api == 'true'
    runs-on: ubuntu-latest
    steps:
      - run: echo "Building API"

Related Skills

  • act-local-testing: Testing workflows locally before pushing
  • act-docker-setup: Configuring Docker environments for act
  • act-secrets-management: Managing secrets for local testing

Du fichier au premier essai

Le téléchargement contient exactement le contenu affiché sur cette fiche. Cette copie peut différer de la dernière version du dépôt source.

Consulter la source et ses fichiers annexes

Ce téléchargement contient uniquement SKILL.md. Les scripts, références, modèles et dépendances éventuels ne sont pas inclus. Récupérez les fichiers nécessaires depuis la source en conservant leur arborescence avant de poursuivre.

1. Télécharger le fichier

Télécharger SKILL.md

Depuis la racine d’un projet de test, enregistrez le fichier sous .skill-downloads/github-actions-workflow-syntax-ms1aw4kg/SKILL.md, ou utilisez la commande suivante. Ce dossier sert à examiner la skill avant son installation.

Commande pour macOS/Linux ou WSL : un shell POSIX et curl sont nécessaires. Sous Windows sans WSL, utilisez le bouton de téléchargement et créez le dossier manuellement.

mkdir -p '.skill-downloads/github-actions-workflow-syntax-ms1aw4kg' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/github-actions-workflow-syntax-ms1aw4kg/download' --output '.skill-downloads/github-actions-workflow-syntax-ms1aw4kg/SKILL.md.part' && mv '.skill-downloads/github-actions-workflow-syntax-ms1aw4kg/SKILL.md.part' '.skill-downloads/github-actions-workflow-syntax-ms1aw4kg/SKILL.md'

2. Vérifier les prérequis

Lisez SKILL.md avant de l’utiliser. Si le fichier cite des scripts ou services externes, examinez-les et préparez les accès nécessaires dans votre environnement de test.

Aucune section de prérequis reconnue dans ce fichier. Cela ne signifie pas qu’il est autonome : les bibliothèques, outils et accès peuvent être cités ailleurs dans le contenu ou dans le dépôt source.

Les plateformes de la fiche sont des indications du catalogue. Les chemins ci-dessous suivent la documentation des outils ; ils ne prouvent pas que cette skill y a été exécutée. Aucune version minimale de ces outils n’est attestée pour cette fiche.

3. Charger la skill

Après vérification, copiez le dossier complet dans le projet avec l’une des commandes ci-dessous, puis ouvrez une nouvelle session de l’outil. La commande s’arrête si un dossier du même nom existe déjà : comparez les fichiers avant de le remplacer.

Claude Code
test -f '.skill-downloads/github-actions-workflow-syntax-ms1aw4kg/SKILL.md' && test -s '.skill-downloads/github-actions-workflow-syntax-ms1aw4kg/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/act-workflow-syntax' && cp -R '.skill-downloads/github-actions-workflow-syntax-ms1aw4kg' '.claude/skills/act-workflow-syntax'

Cursor
test -f '.skill-downloads/github-actions-workflow-syntax-ms1aw4kg/SKILL.md' && test -s '.skill-downloads/github-actions-workflow-syntax-ms1aw4kg/SKILL.md' && mkdir -p '.cursor/skills' && test ! -e '.cursor/skills/act-workflow-syntax' && cp -R '.skill-downloads/github-actions-workflow-syntax-ms1aw4kg' '.cursor/skills/act-workflow-syntax'

OpenSkills

OpenSkills doit déjà être installé. La procédure locale install/read est contrôlée avec OpenSkills 1.5.0, qui exige Node.js ≥ 20.6.0. Aucun slug du catalogue n’est résolu automatiquement.

Installation officielle d’OpenSkills
openskills install './.skill-downloads/github-actions-workflow-syntax-ms1aw4kg'

openskills read 'github-actions-workflow-syntax-ms1aw4kg'

La lecture doit afficher le contenu du fichier installé et son dossier de base. Elle ne lance ni la skill ni ses dépendances.

Pour un agent qui lit AGENTS.md, synchronisez ensuite l’index. Cette commande modifie AGENTS.md : relisez le diff avant de l’utiliser.

openskills sync

Mode manuel ou autre outil : joignez SKILL.md à une conversation, ou ouvrez-le dans un agent capable de lire les fichiers. Ajoutez les ressources annexes nécessaires. Il n’existe pas de dossier universel reconnu par tous les outils.

4. Faire un premier essai

Utilisez une entrée courte et fictive : un endpoint d’API, un petit document ou un brief d’interface. Dans une nouvelle conversation, joignez le fichier ou donnez son chemin à l’agent, puis adaptez cette demande :

Lis .skill-downloads/github-actions-workflow-syntax-ms1aw4kg/SKILL.md et applique ses instructions à cet exemple : [décrire une entrée de test]. Indique les fichiers, dépendances ou accès qui manquent. Produis le résultat demandé par la skill sans inventer de données ni exécuter de script non examiné.

Résultat attendu : une sortie correspondant aux instructions de la skill, ou une liste précise des prérequis manquants. Une simple confirmation de lecture ne valide pas le premier usage. Si une ressource externe est indisponible, ce parcours reste à tester.

Skills similaires