GitHub Actions

Step to check variables and redistribute as env

The following step does ..

  • check of given variables are set, if not, exit with an error that is visible in the action’s log

  • provide the given input as environment variable in GITHUB_ENV

- name: configuration
      env:
        VAR1: ${{ needs.configure.outputs.something }}
        VAR2: ${{ vars.SOMETHING_OTHER }}/
        VAR3: "something_other_other"
      run: |
        for var in VAR1 VAR2 VAR3; do [ -n "${!var}" ] || { echo "$var is missing"; exit 1; }; echo "$var=${!var}" >> "$GITHUB_ENV"; done

Matrix Builds

strategy:
  matrix:
    node: [14, 16, 18]
steps:
  - uses: actions/setup-node@v3
    with:
      node-version: ${{ matrix.node }}

Cache Dependencies

- uses: actions/cache@v3
  with:
    path: ~/.npm
    key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
    restore-keys: |
      ${{ runner.os }}-node-

Run job only for main branch

if: github.ref == 'refs/heads/main'

Reuse workflows

jobs:
  build:
    uses: ./.github/workflows/build.yml

Use Secrets

env:
  MY_TOKEN: ${{ secrets.MY_SECRET }}

Conditional Steps

if: success() && github.event_name == 'push'

GitHub CLI

Login

gh auth login

Create Pull Request

gh pr create --title "Fix bug" --body "Details..."

Checkout Pull Request

gh pr checkout 123

Get repository info

gh repo view --web