How to share/extend/reuse/reference GitHub Workflow?
Asked Answered
H

2

7

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?

Hachmin answered 8/5, 2020 at 21:26 Comment(2)
Does this answer your question? Does Github Actions have templatesOquendo
Unfortunately not. The best one can do now is to create an action, which offers little to no benefit tbhOquendo
C
4

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

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.

Chapatti answered 12/10, 2021 at 12:38 Comment(0)
U
1

At this time, reusing one workflow YAML in another, is not possible.

This is (was) discussed in several places:

As for your particular problem, not all hope is lost.

I have been using Kojo - a command line utility that generates files from templates - for exactly this purpose. I have one template file and I generate two workflows - one for stage, one for production. Perhaps it will be of use to you until a more formal solution from GitHub is available.

(Disclaimer: I am Kojo's author).

Uvular answered 10/5, 2020 at 15:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.