Skip to main content

Creating an example workflow

In this tutorial, you'll learn how to create a basic workflow that is triggered by a push event.

Introduction

This guide shows you how to create a basic workflow that is triggered when code is pushed to your repository.

Pour commencer Ă  utiliser les flux de travail prĂ©configurĂ©s, parcourez la liste des modĂšles dans le rĂ©fĂ©rentiel actions/starter-workflows. Pour plus d’informations, consultez « Utilisation de modĂšles de workflow ».

Important

For more information about best practices for securing your workflows and secure use of GitHub Actions features, see Secure use reference.

CrĂ©ation d’un exemple de workflow

GitHub Actions utilise la syntaxe YAML pour définir le workflow. Chaque workflow est stocké en tant que fichier YAML distinct dans votre référentiel de code, dans un répertoire appelé .github/workflows.

Vous pouvez créer un exemple de workflow dans votre dépÎt qui déclenche automatiquement une série de commandes chaque fois que du code est poussé (push). Dans ce workflow, GitHub Actions extrait le code envoyé, installe le framework de test bats et exécute une commande de base pour générer la version de bats : bats -v.

  1. Dans votre dépÎt, créez le répertoire .github/workflows/ pour stocker vos fichiers de workflow.

  2. Dans le répertoire .github/workflows/, créez un nouveau fichier appelé learn-github-actions.yml et ajoutez le code suivant.

    YAML
    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
    
  3. Validez ces modifications et poussez-les vers votre dépÎt GitHub.

Votre nouveau fichier de workflow GitHub Actions est maintenant installĂ© dans votre dĂ©pĂŽt et s’exĂ©cute automatiquement chaque fois que quelqu’un pousse (push) une modification vers le dĂ©pĂŽt. Pour afficher les dĂ©tails sur l’historique d’exĂ©cution d’un flux de travail, consultez Affichage de l’activitĂ© pour une exĂ©cution de flux de travail.

Présentation du fichier de workflow

Pour vous aider Ă  comprendre comment la syntaxe YAML est utilisĂ©e pour crĂ©er un fichier de workflow, cette section explique chaque ligne de l’exemple d’introduction :

YAML
name: learn-github-actions

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.

run-name: ${{ github.actor }} is learning GitHub Actions

Optional - The name for workflow runs generated from the workflow, which will 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. For more information, see Workflow syntax for GitHub Actions.

on: [push]

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. This is triggered by a push to every branch; for examples of syntax that runs only on pushes to specific branches, paths, or tags, see AUTOTITLE.

jobs:

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

  check-bats-version:

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

    runs-on: ubuntu-latest

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. For syntax examples using other runners, see AUTOTITLE

    steps:

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.

      - uses: actions/checkout@v4

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/setup-node@v4
        with:
          node-version: '20'

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.

      - run: npm install -g bats

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: bats -v

Finally, you'll run the bats command with a parameter that outputs the software version.

# 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 from the workflow, which will 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. For more information, see [AUTOTITLE](/actions/using-workflows/workflow-syntax-for-github-actions#run-name).
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. This is triggered by a push to every branch; for examples of syntax that runs only on pushes to specific branches, paths, or tags, see [AUTOTITLE](/actions/reference/workflow-syntax-for-github-actions#onpushpull_requestpull_request_targetpathspaths-ignore).
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. For syntax examples using other runners, see [AUTOTITLE](/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on)
    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

# Finally, you'll run the `bats` command with a parameter that outputs the software version.
      - run: bats -v

Visualisation du fichier de workflow

Dans ce diagramme, vous pouvez voir le fichier de workflow que vous venez de crĂ©er et comment les composants GitHub Actions sont organisĂ©s dans une hiĂ©rarchie. Chaque Ă©tape exĂ©cute une action ou un script d’interprĂ©teur de commandes unique. Les Ă©tapes 1 et 2 exĂ©cutent des actions, tandis que les Ă©tapes 3 et 4 exĂ©cutent des scripts d’interprĂ©teur de commandes. Pour trouver d’autres actions prĂ©dĂ©finies destinĂ©es Ă  vos flux de travail, consultez Utilisation de blocs Ă©lĂ©mentaires prĂ©-Ă©crits dans votre workflow.

Diagramme montrant le dĂ©clencheur, l’exĂ©cuteur et le travail d’un workflow. Le travail est divisĂ© en 4 étapes.

Affichage de l’activitĂ© pour une exĂ©cution de workflow

Lorsque votre workflow est dĂ©clenchĂ©, une exĂ©cution de workflow est créée et exĂ©cute le workflow. Une fois l’exĂ©cution de votre workflow dĂ©marrĂ©e, vous pouvez voir un graphe de visualisation de la progression de l’exĂ©cution, ainsi que l’activitĂ© de chaque Ă©tape sur GitHub.

  1. Sur GitHub, accédez à la page principale du référentiel.

  2. Sous le nom de votre dépÎt, cliquez sur Actions.

    Capture d’écran des onglets du rĂ©fĂ©rentiel « github/docs ». L’onglet « Actions » est mis en surbrillance avec un encadrĂ© orange.

  3. Dans la barre latérale gauche, cliquez sur le workflow que vous souhaitez afficher.

    Capture d'écran de la barre latérale gauche de l'onglet « Actions », avec un workflow « CodeQL » indiqué en orange foncé.

  4. Dans la liste des exĂ©cutions de workflow, cliquez sur le nom de l’exĂ©cution pour voir le rĂ©sumĂ© de l’exĂ©cution du workflow.

  5. Dans la barre latérale à gauche ou dans le graphe de visualisation, cliquez sur le travail que vous souhaitez voir.

  6. Pour voir les rĂ©sultats d’une Ă©tape, cliquez sur l’étape.

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy