Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to share/extend/reuse/reference GitHub Workflow?

I have two workflows. One deploys on push to master to a test environment. The other deploys on release to prod environment. They are 90% identical, code copy&paste.

Is there a concept such as extracting part of the duplicate logic and putting it into its own file/partial/fragment?

like image 523
phifa Avatar asked Oct 16 '22 03:10

phifa


1 Answers

Reusing workflows in GitHub Actions is available in public beta now:

  • Reusing Workflows
  • The GitHub Blog

To summarize, the workflow that has to be reused needs workflow_call trigger. The caller workflows can then refer it directly within a job by using uses keyword as shown in the following example which is quoted directly from the GitHub page.

jobs:
  call-workflow-1:
    uses: octo-org/this-repo/.github/workflows/workflow-1.yml@172239021f7ba04fe7327647b213799853a9eb89
  call-workflow-2:
    uses: octo-org/another-repo/.github/workflows/workflow-2.yml@v1

It does have some limitations though.

like image 58
kamimanzoor Avatar answered Oct 19 '22 23:10

kamimanzoor