GitHub Actions Day 28: Repository Automation
This is day 28 of my GitHub Actions Advent Calendar. If you want to see the whole list of tips as they're published, see the index.
Advent calendars usually run through Christmas, but I'm going to keep posting about GitHub Actions through the end of December. Consider it bonus content!
This month we've looked at a lot of different ways to build and test your code when a pull request is opened, or when a pull request is merged into the master branch. And we've looked at different ways to deploy your code to a package registry or to a cloud provider.
But GitHub Actions provides triggers for any operation that happens in your repository, not just the ones start CI/CD workflows. Here's some simple examples that display information about the event and are a good basis to build on.
The issue_comment
event
is triggered whenever someone adds a comment on an issue or a
pull request. The payload provides information about the issue and
the comment that was added.
Here's a workflow that uses jq
to get the issue comment
out of the payload.
When this workflow runs it will print the comment.
The gollum
event
is triggered whenever someone changes the repository's wiki. The payload
provides information about the wiki pages that were changed.
Here's a workflow that uses jq
to get the wiki information
out of the payload.
When this workflow runs it will print the URL to the first wiki page that was changed.
You don't have to run a workflow based on any activity in your repository
at all; you can also run workflows on a schedule. When you use the
schedule
trigger, you can specify when the workflow should run using
crontab(5)
syntax.
on:
schedule:
- cron: 0 2 1 * *
In this case, the workflow will run at 2:00 AM every morning on the first day of every month (UTC). cron syntax is tricky, so be sure to consult the documentation if you haven't worked with it before.
Although GitHub Actions provides great functionality for CI/CD workflows, there are triggers for almost every operation in your repository that you can use to automate functionality. With the last few days of the month, we'll look at a more concrete example.