You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/actions/learn-github-actions/reusing-workflows.md
+13-14Lines changed: 13 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,9 +18,9 @@ topics:
18
18
19
19
## Overview
20
20
21
-
Rather than copying and pasting from one workflow to another, you can make workflows reusable. You and anyone with access to the reusable workflow can then call the reusable workflow from another workflow.
21
+
Rather than copying and pasting from one workflow to another, you can make workflows reusable. You and anyone with access to the reusable workflow can then call the reusable workflow from another workflow.
22
22
23
-
Reusing workflows avoids duplication. This makes workflows easier to maintain and allows you to create new workflows more quickly by building on the work of others, just as you do with actions. Workflow reuse also promotes best practice by helping you to use workflows that are well designed, have already been tested, and have been proved to be effective. Your organization can build up a library of reusable workflows that can be centrally maintained.
23
+
Reusing workflows avoids duplication. This makes workflows easier to maintain and allows you to create new workflows more quickly by building on the work of others, just as you do with actions. Workflow reuse also promotes best practice by helping you to use workflows that are well designed, have already been tested, and have been proved to be effective. Your organization can build up a library of reusable workflows that can be centrally maintained.
24
24
25
25
The diagram below shows three build jobs on the left of the diagram. After each of these jobs completes successfully a dependent job called "Deploy" runs. This job calls a reusable workflow that contains three jobs: "Staging", "Review", and "Production." The "Production" deployment job only runs after the "Staging" job has completed successfully. Using a reusable workflow to run deployment jobs allows you to run those jobs for each build without duplicating code in workflows.
26
26
@@ -67,7 +67,6 @@ Called workflows can access self-hosted runners from caller's context. This mean
67
67
* Reusable workflows can't call other reusable workflows.
68
68
* Reusable workflows stored within a private repository can only be used by workflows within the same repository.
69
69
* 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 about the `env` context, see "[Context and expression syntax for GitHub Actions](/actions/reference/context-and-expression-syntax-for-github-actions#env-context)."
70
-
* You can't set the concurrency of a called workflow from the caller workflow. For more information about `jobs.<job_id>.concurrency`, see "[Workflow syntax for GitHub Actions](/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idconcurrency)."
71
70
* The `strategy` property is not supported in any job that calls a reusable workflow.
72
71
73
72
## Creating a reusable workflow
@@ -77,13 +76,13 @@ Reusable workflows are YAML-formatted files, very similar to any other workflow
77
76
For a workflow to be reusable, the values for `on` must include `workflow_call`:
78
77
79
78
```yaml
80
-
on:
79
+
on:
81
80
workflow_call:
82
81
```
83
82
84
83
### Using inputs and secrets in a reusable workflow
85
84
86
-
You can define inputs and secrets, which can be passed from the caller workflow and then used within the called workflow. There are three stages to using an input or a secret in a reusable workflow.
85
+
You can define inputs and secrets, which can be passed from the caller workflow and then used within the called workflow. There are three stages to using an input or a secret in a reusable workflow.
87
86
88
87
1. In the reusable workflow, use the `inputs` and `secrets` keywords to define inputs or secrets that will be passed from a caller workflow.
89
88
{% raw %}
@@ -112,10 +111,10 @@ You can define inputs and secrets, which can be passed from the caller workflow
112
111
- uses: ./.github/actions/my-action@v1
113
112
with:
114
113
username: ${{ inputs.username }}
115
-
token: ${{ secrets.envPAT }}
114
+
token: ${{ secrets.envPAT }}
116
115
```
117
116
{% endraw %}
118
-
In the example above, `envPAT` is an environment secret that's been added to the `production` environment. This environment is therefore referenced within the job.
117
+
In the example above, `envPAT` is an environment secret that's been added to the `production` environment. This environment is therefore referenced within the job.
119
118
120
119
{% note %}
121
120
@@ -153,7 +152,7 @@ jobs:
153
152
- uses: ./.github/actions/my-action@v1
154
153
with:
155
154
username: ${{ inputs.username }}
156
-
token: ${{ secrets.token }}
155
+
token: ${{ secrets.token }}
157
156
```
158
157
{% endraw %}
159
158
@@ -163,7 +162,7 @@ You call a reusable workflow by using the `uses` keyword. Unlike when you are us
You reference reusable workflow files using the syntax:
165
+
You reference reusable workflow files using the syntax:
167
166
168
167
`{owner}/{repo}/{path}/{filename}@{ref}`
169
168
@@ -191,7 +190,7 @@ When you call a reusable workflow, you can only use the following keywords in th
191
190
192
191
{% note %}
193
192
194
-
**Note:**
193
+
**Note:**
195
194
196
195
* If `jobs.<job_id>.permissions` is not specified in the calling job, the called workflow will have the default permissions for the `GITHUB_TOKEN`. For more information, see "[Authentication in a workflow](/actions/reference/authentication-in-a-workflow#permissions-for-the-github_token)."
197
196
* The `GITHUB_TOKEN` permissions passed from the caller workflow can be only downgraded (not elevated) by the called workflow.
@@ -226,7 +225,7 @@ jobs:
226
225
227
226
## Using outputs from a reusable workflow
228
227
229
-
A reusable workflow may generate data that you want to use in the caller workflow. To use these outputs, you must specify them as the outputs of the reusable workflow.
228
+
A reusable workflow may generate data that you want to use in the caller workflow. To use these outputs, you must specify them as the outputs of the reusable workflow.
230
229
231
230
The following reusable workflow has a single job containing two steps. In each of these steps we set a single word as the output: "hello"and "world." In the `outputs` section of the job, we map these step outputs to job outputs called: `output1` and `output2`. In the `on.workflow_call.outputs` section we then define two outputs for the workflow itself, one called `firstword` which we map to `output1`, and one called `secondword` which we map to `output2`.
0 commit comments