GithubHelp home page GithubHelp logo

kuvaldini / make-workflows.sh Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 1.0 17 KB

A tool to support YAML anchors for GitHub Actions Workflows – do not repeat code, DRY for GHA

Shell 100.00%
github-actions yaml-anchors dry github-workflow

make-workflows.sh's Introduction

make-workflows.sh for GitHub Actions

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>

USAGE

  1. Install make-workflows.sh to reachable place inside or outside of your repo, i.e. '.github/'
  2. Put your workflows to .github/*.src.yml
  3. (recommended) pre-commit install and edit .pre-commit-config.yaml according to where make-workflows.sh is placed. (altenative optional) Copy or link pre-commit-hook.sh to .git/hooks/pre-commit
    Like ln -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

Automate using pre-commit (recommended)

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'

Ways to install

  1. 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
  1. 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...

  1. node package manager
npm install kuvaldini/make-workflows.sh

or npm install git+https://github.com/kuvaldini/make-workflows.sh

  1. TODO webinstall

Links

  1. https://stackoverflow.com/questions/67368724/share-same-steps-for-different-github-actions-jobs
  2. https://github.community/t/support-for-yaml-anchors/16128/60
  3. https://github.com/mithro/actions-includes
  4. https://github.com/allejo/gha-workflows
  5. this repo https://github.com/kuvaldini/make-workflows.sh

License, Authors

Authored by @Kuvaldini, 2021.
Please keep links to the source code this repo

Creation of this repo was inspired by @karfau

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.