Examiner un fichier de flux de travail

Effectué

GitHub Actions utilise la syntaxe YAML pour définir le flux de travail. Chaque flux de travail est stocké sous la forme d’un fichier YAML distinct dans votre référentiel de code, dans un répertoire nommé .github/workflows. L’exemple de flux de travail suivant est déclenché chaque fois que le code est envoyé à un référentiel. Le flux de travail effectue les étapes suivantes :

  1. Vérifie le code envoyé.
  2. Installe Node.js.
  3. Installe le framework de tests automatisés Bash (Bats).
  4. Exécute une commande pour afficher la version Bats : bats -v.
name: learn-github-actions
run-name: ${{ github.actor }} is learning GitHub Actions
on: [push]
jobs:
  check-bats-version:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: '20'
      - run: npm install -g bats
      - run: bats -v

Présentation du fichier de flux de travail

Pour vous aider à comprendre comment la syntaxe YAML est utilisée pour créer un fichier de flux de travail, cette section explique chaque ligne de l’exemple précédent :

# Optional - The name of the workflow as it will appear in the "Actions" tab of the GitHub repository. If this field is omitted, the name of the workflow file will be used instead.
name: learn-github-actions

# Optional - The name for workflow runs generated that appear in the list of workflow runs on your repository's "Actions" tab. This example uses an expression with the 'github' context to display the username of the actor that triggered the workflow run. 
run-name: ${{ github.actor }} is learning GitHub Actions

# Specifies the trigger for this workflow. This example uses the 'push' event, so a workflow run is triggered every time someone pushes a change to the repository or merges a pull request.
on: [push]

# Groups together all the jobs that run in the 'learn-github-actions' workflow.
jobs:

# Defines a job named 'check-bats-version'. The child keys will define properties of the job.
  check-bats-version:

# Configures the job to run on the latest version of an Ubuntu Linux runner. This means that the job will execute on a fresh virtual machine hosted by GitHub.
    runs-on: ubuntu-latest

# Groups together all the steps that run in the 'check-bats-version' job. Each item nested under this section is a separate action or shell script.
    steps:

# The 'uses' keyword specifies that this step will run 'v4' of the 'actions/checkout' action. This is an action that checks out your repository onto the runner, allowing you to run scripts or other actions against your code (such as build and test tools). You should use the checkout action any time your workflow will use the repository's code.
      - uses: actions/checkout@v4

# This step uses the 'actions/setup-node@v4' action to install the specified version of the Node.js. (This example uses version 20.) This puts both the 'node' and 'npm' commands in your PATH.
      - uses: actions/setup-node@v4
        with:
          node-version: '20'

# The 'run' keyword tells the job to execute a command on the runner. In this case, you are using 'npm' to install the 'bats' software testing package.
      - run: npm install -g bats

# The 'bats' command with a parameter that outputs the software version.
      - run: bats -v

Afficher l’activité d’une exécution d’un flux de travail

Lorsqu’un flux de travail est déclenché, une exécution de flux de travail est créée qui exécute le flux de travail. Une fois l’exécution du flux de travail démarrée, vous pouvez voir un graphique de visualisation de la progression de l’exécution et afficher l’activité de chaque étape sur GitHub. Procédez comme suit pour afficher l’activité :

  1. Accédez à la page principale du référentiel.

  2. Sélectionnez Actions situées sous le nom du référentiel. Capture d’écran montrant l’emplacement du bouton Actions.

  3. Dans la barre latérale gauche, sélectionnez le flux de travail que vous souhaitez voir.

  4. Dans la liste des exécutions de flux de travail, sélectionnez le nom de l’exécution pour afficher le résumé de l’exécution du flux de travail.

  5. Dans la barre latérale gauche ou dans le graphique de visualisation, sélectionnez le travail à afficher.

  6. Sélectionnez une étape pour afficher les résultats détaillés.

Maintenant que vous comprenez les composants du fichier de flux de travail, vous pouvez voir comment les développeurs peuvent personnaliser le fichier pour divers cas d’usage.