Automation with GitHub Actions

Hugo Gruson

March 2022

Why and what to automate?

What if xkcd was wrong?

  • Requires to be online & available when the task needs to run
  • Not reproducible
  • Mental load

Examples

Good for repetitive, menial tasks.

More time for watching movies focusing on more interesting tasks.

Benefits of GitHub Actions over alternatives

Most famous automation system: cron

GitHub Actions:

  • Scheduling system (and extra triggers) ← cron
  • Server to run code
  • Notification system

Automation code is open-source as well

Syntax

name: GitHub Actions Demo
on: [push]
jobs:
  Explore-GitHub-Actions:
    runs-on: ubuntu-latest
    steps:
      - run: echo "πŸŽ‰ The job was automatically triggered by a ${{ github.event_name }} event."
      - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
      - run: echo "πŸ”Ž The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
      - name: Check out repository code
        uses: actions/checkout@v2
      - run: echo "πŸ’‘ The ${{ github.repository }} repository has been cloned to the runner."
      - run: echo "πŸ–₯️ The workflow is now ready to test your code on the runner."
      - name: List files in the repository
        run: |
          ls ${{ github.workspace }}
      - run: echo "🍏 This job's status is ${{ job.status }}."

Syntax: re-using existing blocks

Syntax: re-using existing blocks

# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
  push:
    branches: [main, master]
  pull_request:
    branches: [main, master]

name: R-CMD-check

jobs:
  R-CMD-check:
    runs-on: ubuntu-latest
    env:
      GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
      R_KEEP_PKG_SOURCE: yes
    steps:
      - uses: actions/checkout@v2

      - uses: r-lib/actions/setup-r@v2
        with:
          use-public-rspm: true

      - uses: r-lib/actions/setup-r-dependencies@v2
        with:
          extra-packages: any::rcmdcheck
          needs: check

      - uses: r-lib/actions/check-r-package@v2

Resources

Over to you

  • Do you think you could benefit from using GitHub Actions?
  • What kind of task do you have to do on a regular basis?
  • How can I support you in using GitHub Actions?

Missing features

  • No way to centralize infrastructure / updates for organisations
  • Difficult to test locally. https://github.com/nektos/act looks nice but I can’t get it to work for complex cases, where I need it the most

Final words

All automation needs to be done in the context of a reflection on our economic system.