Using bashew in GitHub Actions

GitHub Actions, used in countless CI/CD setups, are a good example of the ubiquity of bash scripting. Most of the run: lines in an Action YML document are nothing but (a sequence of) bash command lines. I knew it would be a good match for bashew scripts, but I only found some time to try that out last weekend.

TL;DR: bashew scripts are a great way to streamline your GitHub Actions

bashew in GitHub Action scripts

shot-scraper

I got inspired by Automating screenshots using shot-scraper via Hacker News. The shot-scraper documentation describes how to set it up for using GitHub Actions to do the actual screen grabbing. I used that as a starting point and I distilled it into an efficient example project: pforret/bashew_github_action.

bashew_github_action

I created 3 sub commands in the bashew_github_action.sh script:

The YML code to run each of them in sequence, is super easy:

    - name: gha:before
      run: |
        ./bashew_github_action.sh gha:before
    - name: gha:execute
      run: |
        ./bashew_github_action.sh gha:execute
    - name: gha:after
      run: |-
        ./bashew_github_action.sh gha:after

This is one of the screenshots it generates: automatic screenshot via shot-scraper

Advantages:

Using a bashew script to streamline your GitHub Actions is a good idea because:

Try it out

# install bashew, if necessary
basher install pforret/bashew
# add a new bashew script to your project
bashew script
# add subcommands setup/payload/wrapup, or gha:before,gha:execute,gha:after

or even easier:

# clone the example repo
git clone https://github.com/pforret/bashew_github_action.git
# copy bashew_github_action.sh and .github/workflows/shots.yml to your project
# start editing the gha:before and gha:execute subcommands
  gha:before)
    [[ -z "${RUNNER_OS:-}" ]] && IO:die "Only run inside a Github Action"
    Os:require pip python3
    pip install shot-scraper
    shot-scraper install
    ;;
💬 bash 🏷 bashew 🏷 github 🏷 action 🏷 runner 🏷 ci