Continous Deployment via a GitHub Actions Reminder
1 minute read
At Ashby, we leverage GitHub Actions for lots of small automated tasks. We recently introduced a reminder to deploy changes to production when the number of commits in the deploy passes a specified threshold.
For some background, we deploy by merging develop
into master
(via a merge commit). develop
consists of commits squashed from pull requests. We default to smaller pull requests, so commits may pile up on develop
if nobody needs to deploy to production right away. Suppose a production issue happens after a deploy and the deploy has lots of commits. In that case, it's harder for our team to roll back (e.g., it has database migrations) and harder to identify the commit(s) that caused the issue.
To avoid letting deploys accumulate lots of commits, we wanted to figure out a continuous deployment strategy that would keep deploys small. We considered several strategies and, for now, landed on this automated reminder. The reminder has several benefits:
- Deploys are always attended. We wanted to avoid issues where an automated solution might deploy right when everyone signs off for the day in North America or Europe.
- No changes to our deploy process were needed. We're hiring roles to dedicate more time to improving our deployments, but we wanted to reduce deploy size while minimizing immediate effort.
Here's our GitHub Action in its entirety:
1name: Please Deploy
2on:
3 push:
4 branches:
5 - 'develop'
6
7jobs:
8 please-deploy:
9 runs-on: ubuntu-latest
10 steps:
11 - name: Check out repository code
12 uses: actions/checkout@v3
13 with:
14 fetch-depth: 0
15 - name: Maybe Ask for Deploy
16 run: |
17 if [ "$(git rev-list --count origin/develop ^origin/master)" -gt "$MAX_COMMITS_BEFORE_NOTIFY" ]; then
18 curl -X POST \
19 --data '{ "channel": "C02D678LP29", "text": ":rotating_light: The deploy is getting too big! Can someone (on-call?:pray:) please deploy? https://github.com/ashbyhq/Ashby/compare/master...develop :rotating_light:" }'\
20 -H 'Content-Type: application/json; charset=utf-8'\
21 -H "Authorization: Bearer $PROD_NOTIFY_SLACK_TOKEN"\
22 https://slack.com/api/chat.postMessage
23 fi
24 env:
25 PROD_NOTIFY_SLACK_TOKEN: ${{ secrets.PROD_NOTIFY_SLACK_TOKEN }}
26 MAX_COMMITS_BEFORE_NOTIFY: 4
The GitHub Action sends an automated message to our #ping-engineering channel when develop
is behind master
by five commits, ensuring that we keep the ship shipping throughout the day!