In the previous exercise 09-Manual-Workflow.md, you created a workflow that could be triggered manually.
In this exercise, we will modify that same workflow to be called by other workflows. This model can be used with public or internal repository workflows in order to create a centralized set of workflows. This can reduce workflow configuration across your organization, saving time and effort.
In any examples below, replace main
with your default branch name:
- Checkout the default branch of your repository
- Open the file named
.github/workflows/manual.yaml
(if you don't have this file, follow the instructions in 09-Manual-Workflow.md) - Replace the contents of the file with:
name: Manual & Shared Workflow
on:
workflow_dispatch:
inputs:
choice-example:
description: Choice Example
required: true
default: warning
type: choice
options:
- info
- warning
- debug
string-example:
description: String Example
required: true
default: input
type: string
workflow_call:
inputs:
choice-example:
description: Choice Example
required: true
default: warning
type: string
string-example:
description: String Example
required: true
default: input
type: string
jobs:
do-things:
name: Do Things Manually
runs-on: ubuntu-latest
steps:
- name: Do A Thing
run: echo "I've done a thing manually with '${{ inputs.choice-example }}' and '${{ inputs.string-example }}'!"
Notice that the choice-example
input cannot be of type choice
for workflow_call
.
- Add, commit, and push your changes to the default branch.
- Go to your repository, and view the Actions tab to see the workflow you created (
Manual & Shared Workflow
)
The result will be a button a workflow that is still manually executable
- Checkout the default branch of your repository
- Create a new file named
.github/workflows/shared.yaml
- Replace the contents of the file with:
name: Using Shared Workflow
on:
push:
branches: main
jobs:
centralized-job:
uses: ./.github/workflows/manual.yaml
with:
choice-example: debug
string-example: a thing
- Add, commit, and push your changes to the default branch.
- Go to your repository, and view the Actions tab to see the workflow you created (
Manual & Shared Workflow
)
The result will be an execution of the workflow Manual & Shared Workflow
, that will output the values passed to it from the with
option.
No further steps are needed as you committed directly to the default branch.
- When using a shared workflow from a public or internal repository, the syntax will be slightly different:
<owner>/<repo>/<path-to-workflow>@<release-tag>
- Workflows shared from an internal repository must have the appropriate repository settings (see instructions here)