Nota: Los ejecutores hospedados en GitHub no son compatibles con GitHub Enterprise Server actualmente. Puedes encontrar más información sobre el soporte que se tiene planeado en el futuro en el Itinerario público de GitHub.
About the GITHUB_TOKEN
secret
At the start of each workflow run, GitHub automatically creates a unique GITHUB_TOKEN
secret to use in your workflow. You can use the GITHUB_TOKEN
to authenticate in a workflow run.
When you enable GitHub Actions, GitHub installs a GitHub App on your repository. The GITHUB_TOKEN
secret is a GitHub App installation access token. You can use the installation access token to authenticate on behalf of the GitHub App installed on your repository. The token's permissions are limited to the repository that contains your workflow. For more information, see "Permissions for the GITHUB_TOKEN
."
Before each job begins, GitHub fetches an installation access token for the job. The token expires when the job is finished.
The token is also available in the github.token
context. For more information, see "Contexts."
Using the GITHUB_TOKEN
in a workflow
You can use the GITHUB_TOKEN
by using the standard syntax for referencing secrets: ${{ secrets.GITHUB_TOKEN }}
. Examples of using the GITHUB_TOKEN
include passing the token as an input to an action, or using it to make an authenticated GitHub Enterprise Server API request.
Cuando utilizas el repositorio GITHUB_TOKEN
para realizar tareas, los eventos que activa el GITHUB_TOKEN
no crearán una ejecución de flujo de trabajo nueva. Esto impide que crees ejecuciones de flujo de trabajo recursivas por accidente. Por ejemplo, si un flujo de trabajo sube código utilizando el GITHUB_TOKEN
del repositorio, no se ejecutará un nuevo flujo de trabajo aún si el repositorio contiene alguno configurado para ejecutarse cuando ocurran eventos de subida
de información.
Example 1: passing the GITHUB_TOKEN
as an input
Este flujo de trabajo de ejemplo usa la acción de etiquetadora , que requiere el GITHUB_TOKEN
como el valor para el parámetro de entrada repo-token
:
name: Pull request labeler
on: [ pull_request_target ]
jobs:
triage:
runs-on: ubuntu-latest
steps:
- uses: actions/labeler@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
Example 2: calling the REST API
You can use the GITHUB_TOKEN
to make authenticated API calls. This example workflow creates an issue using the GitHub REST API:
name: Create issue on commit
on: [ push ]
jobs:
create_commit:
runs-on: ubuntu-latest
steps:
- name: Create issue using REST API
run: |
curl --request POST \
--url http(s)://[hostname]/api/v3/repos/${{ github.repository }}/issues \
--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
--header 'content-type: application/json' \
--data '{
"title": "Automated issue for commit: ${{ github.sha }}",
"body": "This issue was automatically created by the GitHub Action workflow **${{ github.workflow }}**. \n\n The commit hash was: _${{ github.sha }}_."
}' \
--fail
Permissions for the GITHUB_TOKEN
For information about the API endpoints GitHub Apps can access with each permission, see "GitHub App Permissions."
Scope | Access type | Access by forked repos |
---|---|---|
actions | read/write | read |
checks | read/write | read |
contents | read/write | read |
deployments | read/write | read |
issues | read/write | read |
metadata | read | read |
packages | read/write | read |
pull-requests | read/write | read |
repository-projects | read/write | read |
statuses | read/write | read |
If you need a token that requires permissions that aren't available in the GITHUB_TOKEN
, you can create a personal access token and set it as a secret in your repository:
- Use or create a token with the appropriate permissions for that repository. For more information, see "Creating a personal access token."
- Add the token as a secret in your workflow's repository, and refer to it using the
${{ secrets.SECRET_NAME }}
syntax. For more information, see "Creating and using encrypted secrets."