Javier Aguirre
Posted on November 29, 2019
In TNP we’ve moved everything to GitHub Actions and we’re very happy about it. :-)
But… this article is not about how happy we are using it but a small tip on how we could simplify every day debugging with some simple improvements.
As a good metric oriented company, We measure and monitor everything we believe relevant, this is a solution to control which release we have in production and being able to monitor its breaking changes in a simple way.
We decided to add the git release tag to our deploy and our app footers, with the following steps.
First, We push to production only when a git tag (a release) is created on GitHub.
jobs:
...
deploy_production:
...
if: success() && contains(github.ref, 'tags')
We deploy to Heroku where is super easy to set a config variable via API, so we decided to:
- Get the release tag from the current release
- Update a
RELEASE_VERSION
variable on Heroku every time a new deploy is successful. - Profit!
steps:
- name: Push to Heroku
run: git push -f https://heroku:${{ secrets.HEROKU_API_TOKEN }}@git.heroku.com/${{ secrets.HEROKU_APP_PRODUCTION }}.git origin/master:master
- name: Update RELEASE_VERSION on Heroku production
if: success()
run: |
curl -n -X PATCH https://api.heroku.com/apps/${{ secrets.HEROKU_APP_PRODUCTION }}/config-vars \
-d '{
"RELEASE_VERSION”: "${{ github.ref }}",
}’ \
-H "Authorization: Bearer ${{ secrets.GITHUB_API_TOKEN }}"
-H "Content-Type: application/json" \
-H "Accept: application/vnd.heroku+json; version=3"
We need to set two variables:
-
HEROKU_API_TOKEN
: Your personal token, you can get it from your account settings. -
HEROKU_APP_PRODUCTION
: Your production app name on Heroku, we don’t hardcode it, so it’s easier to share these recipes in other projects.
That’s It! You’ll have something like this on your Heroku app if all goes well.
Cover Image Garett Mizunaka - Unsplash
Posted on November 29, 2019
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.