Esaminare un file del flusso di lavoro

Completato

GitHub Actions usa la sintassi YAML per definire il flusso di lavoro. Ogni flusso di lavoro viene archiviato come file YAML separato nel repository di codice, in una directory denominata .github/workflows. L'esempio di flusso di lavoro seguente viene attivato ogni volta che viene eseguito il push del codice in un repository. Il flusso di lavoro esegue i passaggi seguenti:

  1. Estrae il codice di cui è stato eseguito il push.
  2. Installa la piattaforma Node.js.
  3. Installa il framework di test BATS (Bash Automated Testing System).
  4. Esegue un comando per restituire la versione 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

Fornisce informazioni sul file del flusso di lavoro

Per comprendere come viene usata la sintassi YAML per creare un file del flusso di lavoro, questa sezione illustra ogni riga dell'esempio precedente:

# 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

Visualizzare l'attività per un'esecuzione del flusso di lavoro

Quando viene attivato un flusso di lavoro, viene avviato un processo che esegue il flusso di lavoro. Dopo l'avvio di un'esecuzione del flusso di lavoro, è possibile visualizzare un grafico di visualizzazione dello stato di avanzamento dell'esecuzione e visualizzare l'attività di ogni passaggio in GitHub. Per visualizzare l'attività, seguire questa procedura:

  1. Passare alla pagina principale del repository.

  2. Selezionare il pulsante Azioni situato sotto il nome del repository. Screenshot che mostra la posizione del pulsante Azioni.

  3. Nella barra laterale sinistra selezionare il flusso di lavoro da visualizzare.

  4. Nell'elenco delle esecuzioni del flusso di lavoro selezionare il nome dell'esecuzione per visualizzare il riepilogo dell'esecuzione del flusso di lavoro.

  5. Nella barra laterale sinistra o nel grafico di visualizzazione, seleziona il processo che desideri visualizzare.

  6. Selezionare un passaggio per visualizzare i risultati dettagliati.

Ora che si conoscono i componenti dei file del flusso di lavoro, è possibile vedere in che modo gli sviluppatori possono personalizzare il file per diversi casi d'uso.