An Interest In:
Web News this Week
- April 25, 2024
- April 24, 2024
- April 23, 2024
- April 22, 2024
- April 21, 2024
- April 20, 2024
- April 19, 2024
./bin/commits-since-last-production-deploy
When you work in a team, with multiple people taking on responsibility for moving work into production, it can mean that you are never 100% confident whether the current main
/master
branch has been fully deployed or not. What's running on prod?
Or rather, what's NOT running on prod yet?
Can I deploy my new commits merged into main
through to production because they are all mine, and mine alone?
Or are there some gnarly new contributions that have been foisted on to the shared work branch, and you thoroughly want to review them before you take responsibility for sending them off into production, and potentially causing problems for customers, support team, and then the dev team in a few minutes or hours?
I wrote a script to that I have started adding to every Heroku-hosted project ./bin/commits-since-last-production-deploy
that is shown below and hosted on a Gist.
To compare the current branch against a specific Heroku application:
./bin/commits-since-last-production-deploy -a myapp-stg
Any additional args are forwarded on to the git log
command, such as --oneline
:
./bin/commits-since-last-production-deploy -a myapp-stg --oneline
If you have a default heroku
remote so you can git push heroku HEAD:main
like a wild thing, then you can drop the -a
flag:
./bin/commits-since-last-production-deploy
The script is below, and is hosted on a Gist
#!/bin/bashhelp() { echo "Usage: ./bin/commits-since-last-production-deploy [-a myapp ] [ -h ]" exit 2}if ! command -v heroku &>/dev/null; then echo "Install 'heroku' CLI" exit 1fiif ! command -v jq &>/dev/null; then echo "Install 'jq' CLI" exit 1fiwhile getopts 'a:h' opt; do case "$1" in -a) appname="$2" shift 2 ;; -h | --help) help exit 2 ;; esacdonelast_deploy_result=$(heroku releases ${appname:+-a $appname} --json | jq -r ".[0].description")if [[ $last_deploy_result =~ ^(Deploy (.*)) ]]; then sha="${BASH_REMATCH[2]}" git log "$sha"..HEAD "$@"else echo "Last deploy to production did not succeed" echo "--> $last_deploy_result" exit 1fi
Fundamentally, this runs heroku releases
on your app, gets the Git SHA-1 that was deployed, then compares it against the list of commits on the current branch.
If you see no output, then there are no new commits that are not yet on production. You are free. Production is all yours. BWAHAHA.
Original Link: https://dev.to/drnic/bincommits-since-last-production-deploy-4ka8
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To