Github Actions
Github Actions are a way to run code and processes remotely on Github’s servers. In particular, they allow one to build and test code that is in a repository on Github.
- Start off by creating a public repository on Github, called “test-github-actions” or similar.
Github Actions
Every Github repository has an “Actions” tab.
Adding an Example Github Action
- Click on the Actions tab
If you have no actions, you will see this.
- Click “set up a workflow yourself”.
Which will open an editor where we can put our workflow.
- Copy in the following example workflow:
name: learn-github-actions
run-name: ${{ github.actor }} is learning GitHub Actions
on: [push]
jobs:
check-bats-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '14'
- run: npm install -g bats
- run: bats -v
- Then click “Commit Changes…”
Once you commit the changes, navigate back to the Actions tab. You should see a process running there now, executing your Github Action.
Adding an R Github Action
In the Github Actions tab,
- Click on “New Workflow”, then “set up a workflow yourself”
We are back to the editor.
- Copy in the following code:
on: [push]
name: Run R code example
jobs:
run-some-R-code:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: r-lib/actions/setup-r@v2
- run: Rscript -e 'print("hello world")'
- And hit “commit Changes…”
Now you have two Github Actions running. Go back to the Github Actions scren. Once they finish running, you should see something like this:
Notice that our latest commit triggered both actions.
You can click on each workflow to view the jobs its running or has run. And you can click on each job to view the steps and the log files from the code being run.