GitHub Workflow description in YAML does not support anchors.
There are several workarounds => anyway they come to building-editing workflow yaml from source.
So I suggest yet another one make-workflows.sh
based on YAML tool yq
version 4.
<spoiler>All these code and repo is written around yq eval 'explode(.)'
</spoiler>
- Install
make-workflows.sh
to reachable place inside or outside of your repo, i.e. '.github/' - Put your workflows to
.github/*.src.yml
- (recommended)
pre-commit install
and edit.pre-commit-config.yaml
according to wheremake-workflows.sh
is placed. (altenative optional) Copy or linkpre-commit-hook.sh
to.git/hooks/pre-commit
Likeln -s ../../.github/pre-commit-hook.sh .git/hooks/pre-commit
$ ./make-workflows.sh --help
make-workflows:
This script expands '*.src.yml' from $1..$[N-1] (default: REPO_ROOT/.github/)
to $N (default:REPO_ROOT/.github/workflows/) with corresponding name '*.yml'
Main goal is to dereference YAML anchors.
Deals only with Git cached/indexed files until --worktree passed.
DEBUG: use option -x
NOTE: spaces in filenames are not allowed to keep code simplicity.
Usage:
make-workflows.sh [--worktree] [dirs_from... [dir_to]]
make-workflows.sh [--help]
Options:
--worktree List files and get contents from working tree
instead of git index
-h, --help show this help
-x, --trace, +x, --no-trace enable/disable bash trace
-i, --install
--update
-V, --version
There is a nice tool pre-commit to do checks and some actions just before commit. The tool is called by Git pre-commit hook.
Making workflows is better being automated – just
$ pre-commit install
and add next sample to .pre-commit-config.yaml
repos:
- repo: local
hooks:
- id: make-workflows
name: Make GitHub workflows from *.src.yml
entry: bash -c '.github/make-workflows.sh && git add .github/workflows'
language: system
files: '.github/.*\.src\.ya?ml'
pass_filenames: false
NOTE: pay attention to path to
make-workflows.sh
NOTE2: pay attention to path(s) where source files are stored
files: 'PATH_REGEXP'
- raw by hand
curl 'https://raw.githubusercontent.com/kuvaldini/make-workflows.sh/main/make-workflows.sh' -LsSf >make-workflows.sh && chmod +x make-workflows.sh
- using own facility, installs to /usr/local/bin
curl 'https://raw.githubusercontent.com/kuvaldini/make-workflows.sh/main/make-workflows.sh' -LsSf | bash -s -- --install
NOTE: may require
...| sudo bash...
- node package manager
npm install kuvaldini/make-workflows.sh
or npm install git+https://github.com/kuvaldini/make-workflows.sh
- TODO webinstall
- https://stackoverflow.com/questions/67368724/share-same-steps-for-different-github-actions-jobs
- https://github.community/t/support-for-yaml-anchors/16128/60
- https://github.com/mithro/actions-includes
- https://github.com/allejo/gha-workflows
- this repo https://github.com/kuvaldini/make-workflows.sh
Authored by @Kuvaldini, 2021.
Please keep links to the source code this repo
Creation of this repo was inspired by @karfau