Skip to content

Instantly share code, notes, and snippets.

@dannysauer
Created March 10, 2021 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dannysauer/e0dd0f738d79362e5b1a70cd58ac570c to your computer and use it in GitHub Desktop.
Save dannysauer/e0dd0f738d79362e5b1a70cd58ac570c to your computer and use it in GitHub Desktop.
git tag promotion aliases
✔ /tmp/testrepo [main L|✔]
10:04 $ sed -n '/alias/,$p' .git/config
[alias]
show-tag-date = tag --list --format "%(taggerdate:unix)"
flux-latest-stage-tag = describe --abbrev=0 --tags --match 'stage/*' main
flux-latest-prod-tag = describe --abbrev=0 --tags --match 'prod/*' main
flux-state = show --oneline --no-patch main stage prod
# git flux-rollback [stage|prod]
flux-rollback = "!git branch -f $1 $( git describe --abbrev=0 --tags --match="$1/*" ${1}^ ) && git tag -m \"rollback $1\" ${1}/$(date +'%F-%H-%M-%S')/rollback $1 #"
flux-stage = !git tag -m 'promote to stage' stage/$(date +'%F-%H-%M-%S') refs/heads/main && git branch -f stage $( git flux-latest-stage-tag )
flux-promote = "!if [[ $(git show-tag-date $(git flux-latest-stage-tag)) -le $(git show-tag-date $(git flux-latest-prod-tag --exclude '*/rollback')) ]]; \
then echo \"stage's $(git flux-latest-stage-tag) isn't newer than prod's $(git flux-latest-prod-tag --exclude '*/rollback')\"; \
else git tag -f -m 'promote to prod' prod/$(date +'%F-%H-%M-%S') $( git describe --abbrev=0 --tags --match 'stage/*' main )'^{commit}' && git branch -f prod $( git describe --abbrev=0 --tags --match 'prod/*' main ); fi"
#else git tag -f -m 'promote to prod' prod/$(date +'%F-%H-%M-%S') $( git rev-list -1 $( git describe --abbrev=0 --tags --match 'stage/*' main ) ) && git branch -f prod $( git describe --abbrev=0 --tags --match 'prod/*' main ); fi"
@dannysauer
Copy link
Author

dannysauer commented Mar 10, 2021

Demo recording:
asciicast

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment