0
GitHub Actions
Target repository: data.table
Generative Art — Made with Unity
1
Native CI/CD platform/tool in GitHub.
Provides automation for various purposes within a GitHub repository.
Build, Deploy, Publish, Test, etc.
Reliable, flexible, and comes with support for multiple technologies.
Completely Free! (Private repositories: 2k minutes/month)
GitHub Actions?
3
Runner: Virtual machine (or container environment) where workflows are run.
Step: An individual task defined by programming commands.
Job: A set of steps that execute on the same runner.
Action: A collection of tasks that you combine as steps to create one or more jobs.
Workflow: Configurable file written in YAML that is used to define the automation.
Secrets: Encrypted variables used to authenticate workflows store sensitive information.
Artifacts: Files created during the execution of our workflow, or as an output of the process.
Terminology
4
Any specific activity on GitHub that triggers a workflow run.
The ‘trigger’ can be something as simple as a push (most common) or pull/PR.
Deployments, forks, page builds, discussions, wikis (gollum), comments, etc. - tons of options!
They can also be scheduled - use cron syntax.
Further specifications can be made to a selected trigger to narrow it down further.
Events
5
A pull request acts as the trigger.
Types: Opened, Synchronized, Labeled, etc.
Filters: Branches, Paths, Files, etc.
Let’s look at an example - one of the workflows I created for directlabels.
Events: PRs
6
7
Briefly, it uses atime to generate plots that show possible performance regression occurring from changes in a PR. The plots compare between different versions (base, merge-base, CRAN, HEAD) for specific tests that are defined.
name: Autocomment atime-based regression analysis plot on PRs
Let’s create a new test while I run you through my workflow :)
My action
8
At present, I want my action to run on:
a) All target branches
b) All commits in a PR
on:
pull_request:
branches:
- '*'
types:
- opened
- reopened
- synchronize
Events: PRs
9
Specify your virtual environment:
jobs:
comment:
runs-on: ubuntu-latest
container: ghcr.io/iterative/cml:0-dvc2-base1
runs-on key
I’m using a custom setup that helps me comment on PRs without much hassle.
10
Used to fetch your repository's current contents into the runner's file system, allowing your workflows to access and work with your project's source code in the right branch.
Default checkout directory is given by the $GITHUB_WORKSPACE environment variable.
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
checkout
A fetch-depth set to 1 fetches the most recent commit only, whereas setting it to 0 means all commits, branches, and tags (entire history) will be fetched.
11
Always remember to authenticate using a personal access token (PAT) for git-based operations.
Git specifies a restriction on running commands within foreign directories for security purposes.
- name: safe-dir-check
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
run: |
git config --global --add safe.directory /__w/data.table
git ops
Disabling the safe directory check on our repository enables us to bypass that.
12
Always remember to authenticate using a personal access token (PAT) for git-based operations.
Essential to switch to the correct branches for atime to pick up the right environment variables.
- name: git-switch
run: |
git switch "${GITHUB_BASE_REF}"
git switch "${GITHUB_HEAD_REF}"
shell: bash
git ops
13
Using the RStudio Package Manager is a convenient way to set up the latest version of R.
Follow up with any/all dependencies to be used for running our R code.
- name: R Setup
uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true
- name: Install R dependencies
run: |
Rscript -e 'install.packages(c("ggplot2", "devtools", "remotes"))'
setup-r
14
The atime package requires git2r, and in turn, libgit2 is required for git2r.
Need to install them in order thus:
- name: Set up required system dependencies (libgit2 and git2r)
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
run: |
sudo apt-get update -y
sudo apt-get install -y libgit2-dev
git clone https://github.com/ropensci/git2r.git
cd git2r && make install
cd ..
Version control dependencies
15
Time to set up atime! Ensure to install from GitHub for the latest version.
I run the atime_pkg method on our repository: (the workspace as allocated by a proper checkout)
- name: Set up R packages composing the test infrastructure (atime + customized data.table) and initiate magic
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
run: |
R -e 'remotes::install_github("tdhock/atime")'
R -e 'atime::atime_pkg(Sys.getenv("GITHUB_WORKSPACE"))'
atime
16
The resultant output consists of multiple files (a plot with all the tests + plots of each individual test, R script with the tests + Rdata) that may be useful to others apart from the commented plot, thus they are uploaded as an artifact.
v4 allows artifacts to be identifiable within a workflow, as an artifact ID is generated that is available within the succeeding steps of the workflow (with reference to the upload step).
- name: Upload results
id: artifact-upload-step
uses: actions/upload-artifact@v4
with:
name: atime-results
path: inst/atime/
upload-artifact
17
Time to publish our results/outputs to everyone via the GitHub Actions bot!
Everything goes into a markdown file - A plot, the commit ID everything is based upon, and the link to download the artifact (URL being constructed using various environment variables).
- name: Push generated plots with relevant information on the PR thread as a GH-bot comment
env:
repo_token: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "" >> report.md
echo "\nGenerated via commit ${{ github.event.pull_request.head.sha }}" >> report.md
echo "\nDownload link for the artifact containing the test results: [↓ atime-results.zip](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts/${{ steps.artifact-upload-step.outputs.artifact-id }})" >> report.md
cml comment create report.md
Final step: cml
18
Let’s check back on the results of the live demo!
Test results
19
– Ani the skeptical, 5th March ‘24