DevTips -- GitHub Actions

moon indicating dark mode
sun indicating light mode

GitHub Event Path

The environment variable `GITHUB_EVENT_PATH`contains the full payload for the event that triggered this run of your \@github action

name: Cat Webhook Payload
on: [push]
jobs:
test:
runs-on: ubuntu-latest
steps:
- run: cat $GITHUB_EVENT_PATH

GitHub Workspace

The environment variable `GITHUB_WORKSPACE` is automatically populated if you use the `actions/checkout` \@github action

name: Test Package
on: [push]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- run: cd $GITHUB_WORKSPACE
- run: ls

Using Yarn

Yarn comes pre-installed on \@github action environments. No extra work required

name: Test Package
on: [push]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 12
- run: yarn
- run: yarn test

triggering actions

\@github actions can be triggered by pushes, webhooks, or on a schedule like cron jobs https://egghead.io/lessons/github-scheduling-github-actions-with-cron?pl=github-actions-at-work-ad05f3ff?af=7h4hd0

name: CI
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Run a one-line script
run: echo Hello, world!
- name: Run a multi-line script
run: |
echo Add other actions to build,
echo test, and deploy your project.
name: From Webhook
on: repository_dispatch
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Run a one-line script
run: echo Hello, world!
- name: Run a multi-line script
run: |
echo Add other actions to build,
echo test, and deploy your project.
name: Nightly Build
on:
schedule:
- cron: "*/5 * * * *"
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Run a one-line script
run: echo Hello, world!
- name: Run a multi-line script
run: |
echo Add other actions to build,
echo test, and deploy your project.