Example overview
Este artigo usa um fluxo de trabalho de exemplo para demonstrar alguns dos principais recursos de CI do GitHub Actions. When this workflow is triggered, it tests your code using a matrix of test combinations with npm test.
O diagrama a seguir mostra uma visão de alto nível das etapas do fluxo de trabalho e como elas são executadas no trabalho:

Features used in this example
O fluxo de trabalho de exemplo demonstra os seguintes recursos do GitHub Actions:
| Feature | Implementation |
|---|---|
| Como executar um fluxo de trabalho manualmente usando a interface do usuário: | workflow_dispatch |
| Como disparar um fluxo de trabalho a ser executado automaticamente: | pull_request |
| Executar um fluxo de trabalho em intervalos regulares: | schedule |
| Definir permissões para o token: | permissions |
| Como controlar quantas execuções de fluxo de trabalho ou trabalhos podem ser executadas ao mesmo tempo: | concurrency |
| Running the job on different runners, depending on the repository: | runs-on |
| Impedir a execução de um trabalho, a menos que condições específicas sejam atendidas: | if |
| Using a matrix to create different test configurations: | matrix |
| Clonar seu repositório para o executor: | actions/checkout |
Como instalar o node no executor: | actions/setup-node |
| Caching dependencies: | actions/cache |
| Running tests on the runner: | npm test |
Example workflow
O fluxo de trabalho a seguir foi criado pela equipe de engenharia de Docs do GitHub. Para revisar a versão mais recente deste arquivo no repositório github/docs, confira test.yml.
Observação: cada linha desse fluxo de trabalho é explicada na próxima seção em "Noções básicas sobre o exemplo".
|
Understanding the example
A tabela a seguir explica como cada um desses recursos é usado ao criar um fluxo de trabalho GitHub Actions.
| Code | Explanation |
|---|---|
|
O nome do fluxo de trabalho, como aparece na guia "Ações" do repositório do GitHub. |
|
The |
|
Add the |
|
Add the |
|
Add the |
|
Modifies the default permissions granted to |
|
Creates a concurrency group for specific events, and uses the |
|
Cancels any currently running job or workflow in the same concurrency group. |
|
Groups together all the jobs that run in the workflow file. |
|
Defines a job with the ID |
|
Configures the job to run on a GitHub-hosted runner or a self-hosted runner, depending on the repository running the workflow. In this example, the job will run on a self-hosted runner if the repository is named |
|
Sets the maximum number of minutes to let the job run before it is automatically canceled. For more information, see |
|
This section defines the build matrix for your jobs. |
|
Setting |
|
Creates a matrix named |
|
Groups together all the steps that will run as part of the |
|
The |
|
If the current repository is the |
|
If the current repository is the |
|
If the current repository is the |
|
This step runs a command to check out LFS objects from the repository. |
|
This step uses the |
|
This step runs a shell command that uses an output from the previous step to create a file containing the list of files changed in the pull request. |
|
This step uses the |
|
This step runs the |
|
This step uses the |
|
This step runs the build script. |
|
This step runs the tests using |
Next steps
- Para aprender os conceitos do GitHub Actions, confira "Noções básicas sobre o GitHub Actions".
- Para obter um guia passo a passo de criação de um fluxo de trabalho básico, confira "Guia de início rápido do GitHub Actions".
- Se você já entende os conceitos básicos do GitHub Actions, saiba mais sobre os fluxos de trabalho e seus recursos em "Sobre fluxos de trabalho".