Enable github workflow on multiple repos easily

I am trying to deploy a Github workflow across all of the repos in our org ( a few 100 ) . What is the best way to do this programmatically ?

I have explored the option of a Workflow Template . This would still require some manual intervention per repo.
Any way that a privileged user or admin of an org enable this workflow for all repos in the org in one click or something on similar lines .

I came across this page

which talks about setting a workflow across several repos. Is this the best way to go about it ?

Thank you

I’d do something like:

repos.list:

udplume/publictest

Add .github config one temporary repository at a time

for a in $(cat repos.list); do (
rm -rf temp-repo
git clone --depth 1 git@github.com:$a temp-repo &&
cd temp-repo &&
rsync -a ~/my-template/.github . &&
git add .github &&
git commit -m 'Adding workflows' &&
git push origin HEAD
); done

Obviously you should understand what commands that random people on the internet suggest do before doing them.

But, conceptually this should work.

Add .github config using multiple concurrent temporary repositories

You could be fancier and run a bunch of them in parallel, but I’m not sure I’d bother:

for a in $(cat repos.list); do (
scratch=$(mktemp -d) &&
cd $scratch &&
git clone --depth 1 git@github.com:$a . &&
rsync -a ~/my-template/.github . &&
git add .github &&
git commit -m 'Adding workflows' &&
git push origin HEAD &&
cd &&
rm -rf $scratch
) & done

Note: doing it this way you could of course run out of disk space or cpu. So, you probably don’t really want to do this.

Establish a link with your workflow repository

In theory, if you’re being adventurous, you could instead try merging in a template repository. That would let you pull in updates from the template repository.

(workflows_repo is a org/repo)

workflows_dir=$(mktemp -d)
git clone git@github.com:$workflows_repo $workflows_dir
for a in $(cat repos.list); do (
rm -rf temp-repo
git clone --depth 1 git@github.com:$a temp-repo &&
cd temp-repo &&
git pull $workflows_dir HEAD:FETCH_HEAD &&
git merge FETCH_HEAD --allow-unrelated-histories -m 'Adding workflows' &&
git push origin HEAD
); done

Disclaimer: I haven’t run any of these commands.

The -m in each case is totally up to you. I’d suggest you pick a better message, e.g. including the url and sha of the original workflow templates…

Thank you @jsoref for your response. Those scripts are pretty useful . I do understand what you are trying to do in these scripts . I’ll keep exploring

1 Like