Reusable Workflows - GitHub Actions
Overview:
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.
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.
The diagram below shows an in-progress workflow run that uses a reusable workflow.
- After each of three build jobs on the left of the diagram completes successfully, a dependent job called "Deploy" is run.
- The "Deploy" 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.
- When a job targets an environment, the workflow run displays a progress bar that shows the number of steps in the job. In the diagram below, the "Production" job contains 8 steps, with step 6 currently being processed.
- Using a reusable workflow to run deployment jobs allows you to run those jobs for each build without duplicating code in workflows.
- Workflow reuse also promotes best practice by helping you to use workflows that are well designed, have already been tested, and have been proven to be effective.
A workflow that uses another workflow is referred to as a "caller" workflow. The reusable workflow is a "called" workflow. One caller workflow can use multiple called workflows. Each called workflow is referenced in a single line. The result is that the caller workflow file may contain just a few lines of YAML, but may perform a large number of tasks when it's run. When you reuse a workflow, the entire called workflow is used, just as if it was part of the caller workflow.
This is Reusable workflow and it is been called in different workflow jobs to perform automation. reusable-workflow.yml
name: called Reusable workflow
on: workflow_call: inputs: my-input: required: true jobs: called-job: runs-on: ubuntu-latest steps: - name: Print Input Value run: echo "The input value is ${{ inputs.my-input }}"
And this is caller Workflow
name: caller Workflow on: push: branches: - main jobs: My-input: uses: ./.github/workflows/reusable-workflow.yml with: my-input: 2030938
This is sample example only official documentation check below.
https://docs.github.com/en/actions/using-workflows/reusing-workflows
Comments
Post a Comment