Skip to content

Latest commit

 

History

History
103 lines (72 loc) · 9.37 KB

File metadata and controls

103 lines (72 loc) · 9.37 KB
title Reusable workflows reference
shortTitle Reusable workflows
intro Learn how to avoid duplication when creating a workflow by reusing existing workflows.
versions
fpt ghec ghes
*
*
*
redirect_from
/actions/reference/reusable-workflows-reference

Access to reusable workflows

A reusable workflow can be used by another workflow if any of the following is true:

  • Both workflows are in the same repository.

  • The called workflow is stored in a public repository{% ifversion ghes %} on {% data variables.product.prodname_ghe_server %}.

    You cannot directly use reusable workflows defined on {% data variables.product.prodname_dotcom_the_website %}. Instead store a copy of the reusable workflow on {% data variables.location.product_location %}, and call the workflow from that path.

    {% elsif actions-workflow-policy %}, and your {% ifversion ghec %}enterprise{% else %}organization{% endif %} allows you to use public reusable workflows.{% endif %}{% ifversion ghes or ghec %}

  • The called workflow is stored in an internal repository and the settings for that repository allow it to be accessed. For more information, see AUTOTITLE.{% endif %}

  • The called workflow is stored in a private repository and the settings for that repository allow it to be accessed. For more information, see {% ifversion ghes or ghec %}AUTOTITLE.{% else %}AUTOTITLE and AUTOTITLE.{% endif %}

The following table shows the accessibility of reusable workflows to a caller workflow, depending on the visibility of the host repository.

Caller repository Accessible workflows repositories
private private{% ifversion ghes or ghec %}, internal,{% endif %} and public
{% ifversion ghes or ghec %}
internal internal, and public
{% endif %}
public public

The Actions permissions on the callers repository's Actions settings page must be configured to allow the use of actions and reusable workflows - see AUTOTITLE.

For {% ifversion ghes or ghec %}internal or {% endif %}private repositories, the Access policy on the Actions settings page of the called workflow's repository must be explicitly configured to allow access from repositories containing caller workflows - see AUTOTITLE.

{% data reusables.actions.actions-redirects-workflows %}

Limitations

  • You can connect up to four levels of workflows. For more information, see Nesting reusable workflows.

  • You can call a maximum of 20 unique reusable workflows from a single workflow file. This limit includes any trees of nested reusable workflows that may be called starting from your top-level caller workflow file.

    For example, top-level-caller-workflow.ymlcalled-workflow-1.ymlcalled-workflow-2.yml counts as 2 reusable workflows.

  • Any environment variables set in an env context defined at the workflow level in the caller workflow are not propagated to the called workflow. For more information, see AUTOTITLE and AUTOTITLE.

  • Similarly, environment variables set in the env context, defined in the called workflow, are not accessible in the env context of the caller workflow. Instead, you must use outputs of the reusable workflow. For more information, see Using outputs from a reusable workflow.

  • To reuse variables in multiple workflows, set them at the organization, repository, or environment levels and reference them using the vars context. For more information see AUTOTITLE and AUTOTITLE.

  • Reusable workflows are called directly within a job, and not from within a job step. You cannot, therefore, use GITHUB_ENV to pass values to job steps in the caller workflow.

Supported keywords for jobs that call a reusable workflow

When you call a reusable workflow, you can only use the following keywords in the job containing the call:

How reusable workflows use runners

{% data variables.product.github %}-hosted runners

The assignment of {% data variables.product.prodname_dotcom %}-hosted runners is always evaluated using only the caller's context. Billing for {% data variables.product.prodname_dotcom %}-hosted runners is always associated with the caller. The caller workflow cannot use {% data variables.product.prodname_dotcom %}-hosted runners from the called repository. For more information, see AUTOTITLE.

Self-hosted runners

Called workflows that are owned by the same user or organization{% ifversion ghes or ghec %} or enterprise{% endif %} as the caller workflow can access self-hosted runners from the caller's context. This means that a called workflow can access self-hosted runners that are:

  • In the caller repository
  • In the caller repository's organization{% ifversion ghes or ghec %} or enterprise{% endif %}, provided that the runner has been made available to the caller repository

Access and permissions for nested workflows

A workflow that contains nested reusable workflows will fail if any of the nested workflows is inaccessible to the initial caller workflow. For more information, see Access to reusable workflows.

GITHUB_TOKEN permissions can only be the same or more restrictive in nested workflows. For example, in the workflow chain A > B > C, if workflow A has package: read token permission, then B and C cannot have package: write permission. For more information, see AUTOTITLE.

For information on how to use the API to determine which workflow files were involved in a particular workflow run, see AUTOTITLE.

Behavior of reusable workflows when re-running jobs

{% data reusables.actions.partial-reruns-with-reusable %}

github context

When a reusable workflow is triggered by a caller workflow, the github context is always associated with the caller workflow. The called workflow is automatically granted access to github.token and secrets.GITHUB_TOKEN. For more information about the github context, see AUTOTITLE.