We have a repo that contains a bunch of workflows that we want to share amongst all of our dev repositories.
github-common-workflows repository:
workflows/build.yml
workflows/test.yml
Is there a way to import the repo above as a submodule or subtree within our dev repos, e.g.:
dev-repo repository:
.github/<point to the github-common-workflows repo>
BECAUSE - when using submodules, github actions will not recognize any workflows at all Hence no github workflow will be triggered (e.g. upon push)
Any ideas how to achieve a single place that contains all the workflows and shared amongst all repos?
CodePudding user response:
Having .github/workflows as a submodule won't work since github can't see the workflows defined in the target repo.
Solution:
Workflows can be defined in a common separate workflows repo and can be reused by multiple repositories, using the caller/called reusable workflow syntax (workflow_call) official docs can be found here:
https://docs.github.com/en/actions/using-workflows/reusing-workflows
CodePudding user response:
A possible solution for private repos is to upload the shareable repo as an artifact, e.g. a compressed archive and host it somewhere accessible. When the caller workflow kicks in, simply download the archive and extract it into the current context.
E.g.:
Assuming $archive-url =https://example.org/shareable-workflow.tar: workflow.yml
jobs:
- name: Checkout context repo
run: actions/checkout@v2
- name: Download the shareable workflow
run: curl $archive-url | tar xzf -
- uses: ./workflow.yml