From a2bb22cd69c6e221c00b5cfe32ba2092f2d077f0 Mon Sep 17 00:00:00 2001 From: plastikfan Date: Mon, 22 Jan 2024 09:33:52 +0000 Subject: [PATCH 1/3] script(chore): apply corrections defined by script check linter (#132) --- scripts/git-workflow.gum.sh | 245 ++++++++++++++++++++++++++++++++++++ 1 file changed, 245 insertions(+) create mode 100644 scripts/git-workflow.gum.sh diff --git a/scripts/git-workflow.gum.sh b/scripts/git-workflow.gum.sh new file mode 100644 index 0000000..db9aa1d --- /dev/null +++ b/scripts/git-workflow.gum.sh @@ -0,0 +1,245 @@ +#!/usr/bin/env bash + +# 🍯 git dev workflow commands; This script makes use of nerdfonts.com glyphs, eg ξ‚  +# + +function get-def-branch() { + echo master +} + +function get-tracking-branch() { + git config "branch.$(git_current_branch).remote" +} + +function check-upstream-branch() { + upstream_branch=$(get-tracking-branch) + feature_branch=$(git_current_branch) + + if [ -z "$upstream_branch" ]; then + echo "===> πŸ› No upstream branch detected for : 'πŸŽ€ $feature_branch'" + + if ! are-you-sure; then + return 1 + fi + fi + + return 0 +} + +# this may no longer be required, becaause the gum confirm can be +# integrated into teh call site +are-you-sure() { # ξ‚  + echo "πŸ‘Ύ Are you sure❓ (type 'y' to confirm)" + # $(gum input --placeholder "scope") + + # squashed=$(gum input --placeholder "scope") + + read -r squashed + + if [ "$squashed" = "y" ]; then + return 0 + else + echo "β›” Aborted!" + return 1 + fi +} + +start-feat() { + if [[ -n $1 ]]; then + echo "===> πŸš€ START FEATURE: 'πŸŽ€ $1'" + git checkout -b "$1" + return 0 + else + echo "!!! πŸ˜• Please specify a feature branch" + fi + return 1 +} + +end-feat() { + if ! are-you-sure "$1"; then + return 1 + fi + + feature_branch=$(git_current_branch) + default_branch=$(get-def-branch) + + echo "About to end feature 🎁 '$feature_branch' ... have you squashed commits? (type 'y' to confirm)" + read -r squashed + + if [ "$squashed" = "y" ]; then + echo "<=== ✨ END FEATURE: '$feature_branch'" + + if [ "$feature_branch" != master ] && [ "$feature_branch" != main ]; then + git branch --unset-upstream + # can't reliably use prune here, because we have in effect + # a race condition, depending on how quickly github deletes + # the upstream branch after Pull Request "Rebase and Merge" + # + # gcm && git fetch --prune + # have to wait a while and perform the prune or delete + # local branch manually. + # + git checkout "$default_branch" + git pull origin "$default_branch" + echo "Done! βœ”οΈ" + else + echo "!!! πŸ˜• Not on a feature branch ($feature_branch)" + fi + else + echo "β›” Aborted!" + fi +} + +push-feat() { + if ! are-you-sure "$1"; then + return 1 + fi + + current_branch=$(git_current_branch) + default_branch=$(get-def-branch) + + if [ "$current_branch" = "$default_branch" ]; then + echo "!!! β›” Aborted! still on default branch($default_branch) branch ($current_branch)" + return 1 + fi + + if ! git push origin --set-upstream "$current_branch"; then + echo "!!! β›” Aborted! Failed to push feature for branch: $current_branch" + return 1 + fi + + echo "pushed feature to $current_branch, ok! βœ”οΈ" + return 0 +} + +function check-tag() { + rel_tag=$1 + if ! [[ $rel_tag =~ ^[0-9] ]]; then + echo "!!! β›” Aborted! invalid tag" + return 1 + fi + return 0 +} + +# release , !!! do not specify the v prefix, added automatically +# should be run from the root directory otherwise relative paths won't work properly. +function release() { + if ! are-you-sure "$1"; then + return 1 + fi + + if [[ -n $1 ]]; then + if ! check-tag "$1"; then + return 1 + fi + + # these string initialisers should probably e changed, don't + # need the surrounding quotes, but it works so why fiddle? + # + raw_version=$1 + version_number=v$1 + current_branch=$(git_current_branch) + default_branch=$(get-def-branch) + + if [[ $raw_version == v* ]]; then + # the # in ${raw_version#v} is a parameter expansion operator + # that removes the shortest match of the pattern "v" from the beginning + # of the string variable. + # + version_number=$raw_version + raw_version=${raw_version#v} + fi + + if [ "$current_branch" != "$default_branch" ]; then + echo "!!! β›” Aborted! not on default($default_branch) branch; current($current_branch)" + return 1 + fi + + echo "===> πŸš€ START RELEASE: '🎁 $version_number'" + release_branch=release/$version_number + + if ! git checkout -b "$release_branch"; then + echo "!!! β›” Aborted! Failed to create the release branch: $release_branch" + return 1 + fi + + if [ -e ./VERSION ]; then + if ! echo "$version_number" > ./VERSION; then + echo "!!! β›” Aborted! Failed to update VERSION file" + return 1 + fi + + + if ! git add ./VERSION; then + echo "!!! β›” Aborted! Failed to git add VERSION file" + return + fi + + if [ -e ./VERSION-PATH ]; then + version_path=$(more ./VERSION-PATH) + echo "$raw_version" > "$version_path" + + if ! git add "$version_path"; then + echo "!!! β›” Aborted! Failed to git add VERSION-PATH file ($version_path)" + return + fi + fi + + if ! git commit -m "Bump version to $version_number"; then + echo "!!! β›” Aborted! Failed to commit VERSION file" + return 1 + fi + + if ! git push origin --set-upstream "$release_branch"; then + echo "!!! β›” Aborted! Failed to push release $version_number upstream" + return 1 + fi + + echo "Done! βœ…" + return 0 + else + echo "!!! β›” Aborted! VERSION file is missing. (In root dir?)" + fi + else + echo "!!! πŸ˜• Please specify a semantic version to release" + fi + return 1 +} + +# tag-rel , !!! do not specify the v prefix, added automatically +tag-rel() { + if ! are-you-sure "$1"; then + return 1 + fi + + if [[ -n "$1" ]]; then + version_number="v$1" + current_branch=$(git_current_branch) + default_branch=$(get-def-branch) + + if [ "$current_branch" != "$default_branch" ]; then + echo "!!! β›” Aborted! not on default($default_branch) branch; current($current_branch)" + return 1 + fi + + echo "===> 🏷️ PUSH TAG: '$version_number'" + + + if ! git tag -a "$version_number" -m "Release $version_number"; then + echo "!!! β›” Aborted! Failed to create annotated tag: $version_number" + return 1 + fi + + + if ! git push origin "$version_number"; then + echo "!!! β›” Aborted! Failed to push tag: $version_number" + return 1 + fi + + echo "Done! βœ…" + return 0 + else + echo "!!! πŸ˜• Please specify a release semantic version to tag" + fi + return 1 +} From 78ea209608d070c548842498202460a25b0baf26 Mon Sep 17 00:00:00 2001 From: plastikfan Date: Mon, 22 Jan 2024 19:31:38 +0000 Subject: [PATCH 2/3] chore(script): add gum prompting to git workflow (#132) --- scripts/git-workflow.gum.sh | 169 +++++++++++++++++++++++++++--------- 1 file changed, 128 insertions(+), 41 deletions(-) diff --git a/scripts/git-workflow.gum.sh b/scripts/git-workflow.gum.sh index db9aa1d..ee15535 100644 --- a/scripts/git-workflow.gum.sh +++ b/scripts/git-workflow.gum.sh @@ -1,12 +1,32 @@ #!/usr/bin/env bash +# some snippets: +# +# gum confirm "Commit changes?" && git commit -m "$SUMMARY" -m "$DESCRIPTION" + +# 🍭 gum utility +# + +# +# 🍭 end gum utility + # 🍯 git dev workflow commands; This script makes use of nerdfonts.com glyphs, eg ξ‚  # +# === πŸ₯₯ git-operations ======================================================== + function get-def-branch() { echo master } +function gad() { + if [ -z "$(git status -s -uno | grep -v '^ ' | awk '{print $2}')" ]; then + gum confirm "Stage all?" && git add . + fi + + return 0 +} + function get-tracking-branch() { git config "branch.$(git_current_branch).remote" } @@ -26,8 +46,35 @@ function check-upstream-branch() { return 0 } +# === πŸ₯₯ prompt ================================================================ + +function _prompt() { + # gum confirm exits with status 0 if confirmed and status 1 if cancelled + # message="$1" + # result=$(gum confirm "$message") + + # return "$result" + + message="$1" + gum confirm "$message" + + return $? +} + +function _prompt-are-you-sure { + _prompt "are you sure? πŸ‘Ύ" + result=$? + + if [ ! "$result" -eq 0 ]; then + echo "β›” Aborted!" + fi + + return $result +} + # this may no longer be required, becaause the gum confirm can be -# integrated into teh call site +# integrated into the call site; or define a prompt_ wrapper function +# are-you-sure() { # ξ‚  echo "πŸ‘Ύ Are you sure❓ (type 'y' to confirm)" # $(gum input --placeholder "scope") @@ -36,37 +83,38 @@ are-you-sure() { # ξ‚  read -r squashed - if [ "$squashed" = "y" ]; then - return 0 - else + if [ ! "$squashed" = "y" ]; then echo "β›” Aborted!" + return 1 fi + + return 0 } -start-feat() { +# === πŸ₯₯ start-feat ============================================================ + +function start-feat() { if [[ -n $1 ]]; then echo "===> πŸš€ START FEATURE: 'πŸŽ€ $1'" + git checkout -b "$1" - return 0 else echo "!!! πŸ˜• Please specify a feature branch" - fi - return 1 -} -end-feat() { - if ! are-you-sure "$1"; then return 1 fi + return 0 +} + +# === πŸ₯₯ end-feat ============================================================== + +function _do-end-feat() { feature_branch=$(git_current_branch) default_branch=$(get-def-branch) - echo "About to end feature 🎁 '$feature_branch' ... have you squashed commits? (type 'y' to confirm)" - read -r squashed - - if [ "$squashed" = "y" ]; then + if _prompt "About to end feature 🎁 '$feature_branch' ... have you squashed commits"; then echo "<=== ✨ END FEATURE: '$feature_branch'" if [ "$feature_branch" != master ] && [ "$feature_branch" != main ]; then @@ -81,61 +129,73 @@ end-feat() { # git checkout "$default_branch" git pull origin "$default_branch" - echo "Done! βœ”οΈ" + echo "Done! βœ…" else echo "!!! πŸ˜• Not on a feature branch ($feature_branch)" + + return 1 fi else echo "β›” Aborted!" - fi -} -push-feat() { - if ! are-you-sure "$1"; then return 1 fi + return 0 +} + +function end-feat() { + _prompt-are-you-sure && _do-end-feat +} + +# === πŸ₯₯ push-feat ============================================================= + +function _do-push-feat() { current_branch=$(git_current_branch) default_branch=$(get-def-branch) if [ "$current_branch" = "$default_branch" ]; then echo "!!! β›” Aborted! still on default branch($default_branch) branch ($current_branch)" + return 1 fi if ! git push origin --set-upstream "$current_branch"; then echo "!!! β›” Aborted! Failed to push feature for branch: $current_branch" + return 1 fi - echo "pushed feature to $current_branch, ok! βœ”οΈ" + echo "pushed feature to $current_branch, ok! βœ…" + return 0 } +function push-feat() { + _prompt-are-you-sure && _do-push-feat +} + +# === πŸ₯₯ check-tag ============================================================= + function check-tag() { rel_tag=$1 if ! [[ $rel_tag =~ ^[0-9] ]]; then echo "!!! β›” Aborted! invalid tag" + return 1 fi + return 0 } -# release , !!! do not specify the v prefix, added automatically -# should be run from the root directory otherwise relative paths won't work properly. -function release() { - if ! are-you-sure "$1"; then - return 1 - fi +# === πŸ₯₯ do-release ============================================================ +function _do-release() { if [[ -n $1 ]]; then if ! check-tag "$1"; then return 1 fi - # these string initialisers should probably e changed, don't - # need the surrounding quotes, but it works so why fiddle? - # raw_version=$1 version_number=v$1 current_branch=$(git_current_branch) @@ -152,6 +212,7 @@ function release() { if [ "$current_branch" != "$default_branch" ]; then echo "!!! β›” Aborted! not on default($default_branch) branch; current($current_branch)" + return 1 fi @@ -160,19 +221,22 @@ function release() { if ! git checkout -b "$release_branch"; then echo "!!! β›” Aborted! Failed to create the release branch: $release_branch" + return 1 fi if [ -e ./VERSION ]; then if ! echo "$version_number" > ./VERSION; then echo "!!! β›” Aborted! Failed to update VERSION file" + return 1 fi if ! git add ./VERSION; then echo "!!! β›” Aborted! Failed to git add VERSION file" - return + + return 1 fi if [ -e ./VERSION-PATH ]; then @@ -181,37 +245,47 @@ function release() { if ! git add "$version_path"; then echo "!!! β›” Aborted! Failed to git add VERSION-PATH file ($version_path)" - return + + return 1 fi fi if ! git commit -m "Bump version to $version_number"; then echo "!!! β›” Aborted! Failed to commit VERSION file" + return 1 fi if ! git push origin --set-upstream "$release_branch"; then echo "!!! β›” Aborted! Failed to push release $version_number upstream" + return 1 fi echo "Done! βœ…" - return 0 else echo "!!! β›” Aborted! VERSION file is missing. (In root dir?)" + + return 1 fi else echo "!!! πŸ˜• Please specify a semantic version to release" - fi - return 1 -} -# tag-rel , !!! do not specify the v prefix, added automatically -tag-rel() { - if ! are-you-sure "$1"; then return 1 fi + return 0 +} + +# release , !!! do not specify the v prefix, added automatically +# should be run from the root directory otherwise relative paths won't work properly. +function release() { + _prompt-are-you-sure && _do-release "$1" +} + +# === πŸ₯₯ tag-rel =============================================================== + +function _do-tag-rel() { if [[ -n "$1" ]]; then version_number="v$1" current_branch=$(git_current_branch) @@ -219,6 +293,7 @@ tag-rel() { if [ "$current_branch" != "$default_branch" ]; then echo "!!! β›” Aborted! not on default($default_branch) branch; current($current_branch)" + return 1 fi @@ -227,19 +302,31 @@ tag-rel() { if ! git tag -a "$version_number" -m "Release $version_number"; then echo "!!! β›” Aborted! Failed to create annotated tag: $version_number" + return 1 fi if ! git push origin "$version_number"; then echo "!!! β›” Aborted! Failed to push tag: $version_number" + return 1 fi echo "Done! βœ…" - return 0 else echo "!!! πŸ˜• Please specify a release semantic version to tag" + + reurn 1 fi - return 1 + + return 0 +} + +# tag-rel , !!! do not specify the v prefix, added automatically +function tag-rel() { + _prompt-are-you-sure && _do-tag-rel "$1" } + +# +# 🍯 end git dev workflow commands From bfaedbeadbb6c592c055523a6e7036024eee65ae Mon Sep 17 00:00:00 2001 From: plastikfan Date: Wed, 24 Jan 2024 15:44:21 +0000 Subject: [PATCH 3/3] chore(script): add initial gum glamour to workflows (#132) --- go.mod | 14 +- go.sum | 32 ++-- scripts/git-workflow.gum.sh | 288 ++++++++++++++++++++++++++++-------- 3 files changed, 247 insertions(+), 87 deletions(-) diff --git a/go.mod b/go.mod index bd01c47..6351ed1 100644 --- a/go.mod +++ b/go.mod @@ -3,8 +3,8 @@ module github.com/snivilised/pixa go 1.21 require ( - github.com/onsi/ginkgo/v2 v2.14.0 - github.com/onsi/gomega v1.30.0 + github.com/onsi/ginkgo/v2 v2.15.0 + github.com/onsi/gomega v1.31.1 github.com/pkg/errors v0.9.1 github.com/samber/lo v1.39.0 github.com/snivilised/extendio v0.6.0 @@ -13,7 +13,7 @@ require ( github.com/spf13/viper v1.18.2 go.uber.org/zap v1.26.0 go.uber.org/zap/exp v0.2.0 - golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc + golang.org/x/exp v0.0.0-20240119083558-1b970713d09a ) require ( @@ -21,15 +21,15 @@ require ( github.com/go-logr/logr v1.4.1 // indirect github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect github.com/google/go-cmp v0.6.0 // indirect - github.com/google/pprof v0.0.0-20231229205709-960ae82b1e42 // indirect - github.com/google/uuid v1.5.0 // indirect + github.com/google/pprof v0.0.0-20240117000934-35fc243c5815 // indirect + github.com/google/uuid v1.6.0 // indirect github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect github.com/onsi/ginkgo v1.16.5 // indirect github.com/sagikazarmark/locafero v0.4.0 // indirect github.com/sagikazarmark/slog-shim v0.1.0 // indirect github.com/sourcegraph/conc v0.3.0 // indirect go.uber.org/multierr v1.11.0 // indirect - golang.org/x/tools v0.16.1 // indirect + golang.org/x/tools v0.17.0 // indirect gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect ) @@ -49,7 +49,7 @@ require ( github.com/spf13/pflag v1.0.5 github.com/subosito/gotenv v1.6.0 // indirect go.uber.org/mock v0.4.0 - golang.org/x/net v0.19.0 // indirect + golang.org/x/net v0.20.0 // indirect golang.org/x/sys v0.16.0 // indirect golang.org/x/text v0.14.0 gopkg.in/ini.v1 v1.67.0 // indirect diff --git a/go.sum b/go.sum index 693f76f..1c36dc4 100644 --- a/go.sum +++ b/go.sum @@ -36,10 +36,10 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/pprof v0.0.0-20231229205709-960ae82b1e42 h1:dHLYa5D8/Ta0aLR2XcPsrkpAgGeFs6thhMcQK0oQ0n8= -github.com/google/pprof v0.0.0-20231229205709-960ae82b1e42/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik= -github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU= -github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/pprof v0.0.0-20240117000934-35fc243c5815 h1:WzfWbQz/Ze8v6l++GGbGNFZnUShVpP/0xffCPLL+ax8= +github.com/google/pprof v0.0.0-20240117000934-35fc243c5815/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= @@ -66,12 +66,12 @@ github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= -github.com/onsi/ginkgo/v2 v2.14.0 h1:vSmGj2Z5YPb9JwCWT6z6ihcUvDhuXLc3sJiqd3jMKAY= -github.com/onsi/ginkgo/v2 v2.14.0/go.mod h1:JkUdW7JkN0V6rFvsHcJ478egV3XH9NxpD27Hal/PhZw= +github.com/onsi/ginkgo/v2 v2.15.0 h1:79HwNRBAZHOEwrczrgSOPy+eFTTlIGELKy5as+ClttY= +github.com/onsi/ginkgo/v2 v2.15.0/go.mod h1:HlxMHtYF57y6Dpf+mc5529KKmSq9h2FpCF+/ZkwUxKM= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= -github.com/onsi/gomega v1.30.0 h1:hvMK7xYz4D3HapigLTeGdId/NcfQx1VHMJc60ew99+8= -github.com/onsi/gomega v1.30.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= +github.com/onsi/gomega v1.31.1 h1:KYppCUK+bUgAZwHOu7EXVBKyQA6ILvOESHkn/tgoqvo= +github.com/onsi/gomega v1.31.1/go.mod h1:y40C95dwAD1Nz36SsEnxvfFe8FFfNxzI5eJ0EYGyAy0= github.com/pelletier/go-toml/v2 v2.1.1 h1:LWAJwfNvjQZCFIDKWYQaM62NcYeYViCmWIwmOStowAI= github.com/pelletier/go-toml/v2 v2.1.1/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -90,10 +90,6 @@ github.com/samber/lo v1.39.0 h1:4gTz1wUhNYLhFSKl6O+8peW0v2F4BCY034GRpU9WnuA= github.com/samber/lo v1.39.0/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA= github.com/snivilised/cobrass v0.4.3 h1:uDXEgPRhC4Bc/n5qCK1ItMp62UL7tcw5Vz52QebEtv8= github.com/snivilised/cobrass v0.4.3/go.mod h1:zY/ECw09lrTDrH1ynTCiCsIYsDNEaDRj7mxOKj2BsFE= -github.com/snivilised/extendio v0.5.5 h1:AOae2RpW43Om2wOPKdo9VeN333M27Z9BSpKElXE+Mts= -github.com/snivilised/extendio v0.5.5/go.mod h1:wn3atq3GVwcnKrlLpBdpTi/bxtUNlGzFA0Vmq1/Dnmo= -github.com/snivilised/extendio v0.5.6 h1:lUCNJ0WoQCqQQRQ1Vf8XkqtCjcOF/ZYW7n0Hs6yE7Yw= -github.com/snivilised/extendio v0.5.6/go.mod h1:wn3atq3GVwcnKrlLpBdpTi/bxtUNlGzFA0Vmq1/Dnmo= github.com/snivilised/extendio v0.6.0 h1:wrKIAmbBVsemOCmD5LcEMeIY4m1agakwcYcJ8U5iWb0= github.com/snivilised/extendio v0.6.0/go.mod h1:wn3atq3GVwcnKrlLpBdpTi/bxtUNlGzFA0Vmq1/Dnmo= github.com/snivilised/lorax v0.4.4 h1:fxuuew+88yUC9JkTq2iQhGx8tvECBzj2ugjssWlTI6A= @@ -135,16 +131,16 @@ go.uber.org/zap/exp v0.2.0/go.mod h1:t0gqAIdh1MfKv9EwN/dLwfZnJxe9ITAZN78HEWPFWDQ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc h1:ao2WRsKSzW6KuUY9IWPwWahcHCgR0s52IfwutMfEbdM= -golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI= +golang.org/x/exp v0.0.0-20240119083558-1b970713d09a h1:Q8/wZp0KX97QFTc2ywcOE0YRjZPVIx+MXInMzdvQqcA= +golang.org/x/exp v0.0.0-20240119083558-1b970713d09a/go.mod h1:idGWGoKP1toJGkd5/ig9ZLuPcZBC3ewk7SzmH0uou08= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c= -golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U= +golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo= +golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -166,8 +162,8 @@ golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.16.1 h1:TLyB3WofjdOEepBHAU20JdNC1Zbg87elYofWYAY5oZA= -golang.org/x/tools v0.16.1/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0= +golang.org/x/tools v0.17.0 h1:FvmRgNOcs3kOa+T20R1uhfP9F6HgG2mfxDv1vrx1Htc= +golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/scripts/git-workflow.gum.sh b/scripts/git-workflow.gum.sh index ee15535..9e9675b 100644 --- a/scripts/git-workflow.gum.sh +++ b/scripts/git-workflow.gum.sh @@ -1,14 +1,147 @@ #!/usr/bin/env bash +# use https://coolors.co to help create colur schemes +# glyphs: +# - https://github.com/ryanoasis/nerd-fonts/wiki/Glyph-Sets-and-Code-Points +# - https://b.agaric.net/page/agave +# - https://github.com/blobject/agave +# - https://www.nerdfonts.com/cheat-sheet + +# +# +# +# +# +# +# +# use a red/pink colour for error: f72585 + # some snippets: # # gum confirm "Commit changes?" && git commit -m "$SUMMARY" -m "$DESCRIPTION" +# +# This series of colours does not POP enough +# +# gum style "Hello, there! Welcome to $(gum style --foreground "#85c0ff" 'Jordy Blue')." +# gum style "Hello, there! Welcome to $(gum style --foreground "#94b0da" 'Powder Blue')." +# gum style "Hello, there! Welcome to $(gum style --foreground "#8f91a2" 'Cool gray')." +# gum style "Hello, there! Welcome to $(gum style --foreground "#505a5b" 'Davys gray')." +# gum style "Hello, there! Welcome to $(gum style --foreground "#343f3e" 'Outer space')." + +_col_promt="#fbf8cc" +_col_remedy="#fde4cf" +_col_error="#ffcfd2" +_col_branch="#f1c0e8" +_col_action="#cfbaf0" +_col_item="#a3c4f3" +_col_query="#98f5e1" +_col_git="#b9fbc0" +_col_msg="#90dbf4" +_col_affirm="#8eecf5" + +# common emojis: +# πŸ˜• 😎 +# 🍭 πŸŽ€ 🎁 +# βœ… +# πŸš€ πŸ”† +# πŸ₯₯ +# πŸ”₯ β›” ❌ +# -# 🍭 gum utility +# pastello pallette # +# +# +# +# +# +# +# +# +# +# +# +# + +# 🍭 gum utility # -# 🍭 end gum utility + +function _text() { + # when you call this function, the colour must be inside quotes, eg: + # _text greetings "#98f5e1" + # + text=$1 + colour=$2 + gum style --foreground "$colour" "$text" +} + +function _a() { # action + text=$1 + colour=#cfbaf0 + _text "$text" "$colour" +} + +function _b() { # branch + text=$1 + colour=#f1c0e8 + _text "$text" "$colour" +} + +function _e() { # error + text=$1 + colour=#ffcfd2 + _text "β›” $text" "$colour" +} + +function _g() { # git-command + text=$1 + colour=#b9fbc0 + _text "ξ‚  $text" "$colour" +} + +function _i() { # item + text=$1 + colour=#a3c4f3 + _text "$text" "$colour" +} + +function _m() { # msg + text=$1 + colour=#90dbf4 + _text "$text" "$colour" +} + +function _o() { # ok + text=$1 + colour=#94fbab + _text "βœ… $text" "$colour" +} + +function _p() { # prompt + text=$1 + colour=#fbf8cc + _text "πŸ˜• $text" "$colour" +} + +function _q() { # query + text=$1 + colour=#98f5e1 + _text "$text" "$colour" +} + +function _r() { # remedy + text=$1 + colour=#fde4cf + _text "$text" "$colour" +} + +function _w() { # warning + text=$1 + colour=#f63e02 + _text "$text" "$colour" +} + # 🍯 git dev workflow commands; This script makes use of nerdfonts.com glyphs, eg ξ‚  # @@ -21,7 +154,7 @@ function get-def-branch() { function gad() { if [ -z "$(git status -s -uno | grep -v '^ ' | awk '{print $2}')" ]; then - gum confirm "Stage all?" && git add . + gum confirm "$(_text 'Stage all?' $_col_query)" && git add . fi return 0 @@ -36,9 +169,10 @@ function check-upstream-branch() { feature_branch=$(git_current_branch) if [ -z "$upstream_branch" ]; then - echo "===> πŸ› No upstream branch detected for : 'πŸŽ€ $feature_branch'" + # echo "===> πŸ› No upstream branch detected for : 'πŸŽ€ $feature_branch'" + gum style "===> πŸ› No upstream branch detected for : πŸŽ€ $(_text "$feature_branch" $_col_item)" - if ! are-you-sure; then + if ! _prompt-are-you-sure; then return 1 fi fi @@ -46,17 +180,39 @@ function check-upstream-branch() { return 0 } -# === πŸ₯₯ prompt ================================================================ +# +# 🍭 end gum utility -function _prompt() { - # gum confirm exits with status 0 if confirmed and status 1 if cancelled - # message="$1" - # result=$(gum confirm "$message") +# this is currently un-tested, so needs to be checked first +# also, add a conform prompt +# function _do_start-interactive-rebase() { +# # Get the number of commits on the current branch +# num_commits=$(git rev-list --count HEAD) + +# # Check if there are commits to rebase +# if [ "$num_commits" -gt 0 ]; then +# # Start interactive rebase for all commits on the current branch +# git rebase -i HEAD~"$num_commits" +# else +# gym style "$(_w 'No commits to rebase.')" - # return "$result" +# return 1 +# fi +# return 0 +# } + +# function start-interactive-rebase() { +# _prompt-are-you-sure && (_do_start-interactive-rebase || gum style "$(_a "interactive rebase cancelled")") +# } + +# Call the function + +# === πŸ₯₯ prompt ================================================================ + +function _prompt() { message="$1" - gum confirm "$message" + gum confirm "$(_m "$message")" return $? } @@ -66,41 +222,24 @@ function _prompt-are-you-sure { result=$? if [ ! "$result" -eq 0 ]; then - echo "β›” Aborted!" + gum style "$(_e "Aborted!")" fi return $result } -# this may no longer be required, becaause the gum confirm can be -# integrated into the call site; or define a prompt_ wrapper function -# -are-you-sure() { # ξ‚  - echo "πŸ‘Ύ Are you sure❓ (type 'y' to confirm)" - # $(gum input --placeholder "scope") - - # squashed=$(gum input --placeholder "scope") - - read -r squashed - - if [ ! "$squashed" = "y" ]; then - echo "β›” Aborted!" - - return 1 - fi - - return 0 -} - # === πŸ₯₯ start-feat ============================================================ function start-feat() { + feature_branch=$1 + if [[ -n $1 ]]; then - echo "===> πŸš€ START FEATURE: 'πŸŽ€ $1'" + gum style "===> πŸš€ $(_a 'START FEATURE'): 'πŸŽ€ $(_b "$feature_branch")'" git checkout -b "$1" else - echo "!!! πŸ˜• Please specify a feature branch" + # echo "!!! πŸ˜• Please specify a feature branch" + gum style "!!! $(_r 'Please specify a feature branch')" return 1 fi @@ -115,7 +254,7 @@ function _do-end-feat() { default_branch=$(get-def-branch) if _prompt "About to end feature 🎁 '$feature_branch' ... have you squashed commits"; then - echo "<=== ✨ END FEATURE: '$feature_branch'" + gum style "<=== ✨ $(_a 'END FEATURE'): $(_b "$feature_branch")" if [ "$feature_branch" != master ] && [ "$feature_branch" != main ]; then git branch --unset-upstream @@ -129,14 +268,16 @@ function _do-end-feat() { # git checkout "$default_branch" git pull origin "$default_branch" - echo "Done! βœ…" + + gum style "$(_o 'Done!')" else - echo "!!! πŸ˜• Not on a feature branch ($feature_branch)" + # echo "!!! πŸ˜• Not on a feature branch ($feature_branch)" + gum style "!!! $(_e 'Not on a feature branch') ($(_b "$feature_branch"))" return 1 fi else - echo "β›” Aborted!" + gum style "$(_e "Aborted!")" return 1 fi @@ -155,18 +296,22 @@ function _do-push-feat() { default_branch=$(get-def-branch) if [ "$current_branch" = "$default_branch" ]; then - echo "!!! β›” Aborted! still on default branch($default_branch) branch ($current_branch)" + # echo "!!! β›” Aborted! still on default branch($default_branch) branch ($current_branch)" + gum style "!!! $(_e 'Aborted! still on default branch') " \ + "($(_b "$default_branch")) branch ($(_b "$current_branch"))" return 1 fi if ! git push origin --set-upstream "$current_branch"; then - echo "!!! β›” Aborted! Failed to push feature for branch: $current_branch" + # echo "!!! β›” Aborted! Failed to push feature for branch: $current_branch" + gum style "!!! $(_e 'Aborted! Failed to push feature for branch:') " \ + "$(_b "$current_branch")" return 1 fi - echo "pushed feature to $current_branch, ok! βœ…" + gum style "$(_o 'pushed feature to') $(_b "$current_branch") ok!" return 0 } @@ -180,7 +325,8 @@ function push-feat() { function check-tag() { rel_tag=$1 if ! [[ $rel_tag =~ ^[0-9] ]]; then - echo "!!! β›” Aborted! invalid tag" + # echo "!!! β›” Aborted! invalid tag" + gum style "!!! $(_e 'Aborted! invalid tag')" return 1 fi @@ -211,30 +357,37 @@ function _do-release() { fi if [ "$current_branch" != "$default_branch" ]; then - echo "!!! β›” Aborted! not on default($default_branch) branch; current($current_branch)" + # echo "!!! β›” Aborted! not on default($default_branch) branch; current($current_branch)" #error/branch + + gum style "!!! $(_e 'Aborted! not on default')($(_b "$default_branch")) " \ + "branch; current($(_b "$current_branch"))" return 1 fi - echo "===> πŸš€ START RELEASE: '🎁 $version_number'" - release_branch=release/$version_number + # echo "===> πŸš€ START RELEASE: '🎁 $version_number'" + gum style "===> πŸš€ $(_a 'START RELEASE'): '🎁 $(_i "$version_number")'" + release_branch="release/$version_number" if ! git checkout -b "$release_branch"; then - echo "!!! β›” Aborted! Failed to create the release branch: $release_branch" + # echo "!!! β›” Aborted! Failed to create the release branch: $release_branch" #error/branch + gum style "!!! $(_e 'Aborted! Failed to create the release branch:') $(_b "$release_branch")" return 1 fi if [ -e ./VERSION ]; then if ! echo "$version_number" > ./VERSION; then - echo "!!! β›” Aborted! Failed to update VERSION file" + # echo "!!! β›” Aborted! Failed to update VERSION file" #error/item + gum style "!!! $(_e 'Aborted! Failed to update VERSION file')" return 1 fi if ! git add ./VERSION; then - echo "!!! β›” Aborted! Failed to git add VERSION file" + # echo "!!! Aborted! Failed to git add VERSION file" #error/item + gum style "$(_e "!!! Aborted! Failed to git add $(_i 'VERSION') file")" return 1 fi @@ -244,32 +397,38 @@ function _do-release() { echo "$raw_version" > "$version_path" if ! git add "$version_path"; then - echo "!!! β›” Aborted! Failed to git add VERSION-PATH file ($version_path)" + # echo "!!! β›” Aborted! Failed to git add VERSION-PATH file ($version_path)" #error/item + gum style "!!! $(_e 'Aborted! Failed to git add VERSION-PATH file') ($("_i $version_path"))" return 1 fi fi if ! git commit -m "Bump version to $version_number"; then - echo "!!! β›” Aborted! Failed to commit VERSION file" + # echo "!!! β›” Aborted! Failed to commit VERSION file" #error/item + gum style "!!! $(_e 'Aborted! Failed to commit VERSION file')" return 1 fi if ! git push origin --set-upstream "$release_branch"; then - echo "!!! β›” Aborted! Failed to push release $version_number upstream" + # echo "!!! β›” Aborted! Failed to push release $version_number upstream" #error/item + gum style "$(e "!!! Aborted! Failed to push release $(_i "$version_number") upstream")" return 1 fi - echo "Done! βœ…" + # echo "Done! βœ…" + gum style "$(_o 'Done!')" else - echo "!!! β›” Aborted! VERSION file is missing. (In root dir?)" + # echo "!!! β›” Aborted! VERSION file is missing. (In root dir?)" #error + gum style "!!! $(_e "Aborted! $(_i 'VERSION') file is missing. (In root dir?)")" return 1 fi else - echo "!!! πŸ˜• Please specify a semantic version to release" + # echo "!!! πŸ˜• Please specify a semantic version to release" #remedy + gum style "!!! $(_r 'Please specify a semantic version to release')" return 1 fi @@ -292,30 +451,35 @@ function _do-tag-rel() { default_branch=$(get-def-branch) if [ "$current_branch" != "$default_branch" ]; then - echo "!!! β›” Aborted! not on default($default_branch) branch; current($current_branch)" + # echo "!!! β›” Aborted! not on default($default_branch) branch; current($current_branch)" #error/branch + gum style "$(_e "!!! Aborted! not on default($(_b "$default_branch")) " \ + "branch; current($(_b "$current_branch"))")" return 1 fi - echo "===> 🏷️ PUSH TAG: '$version_number'" - + gum style "$(_a "===> 🏷️ PUSH TAG: '$(_i "$version_number")'")" if ! git tag -a "$version_number" -m "Release $version_number"; then - echo "!!! β›” Aborted! Failed to create annotated tag: $version_number" + # echo "!!! β›” Aborted! Failed to create annotated tag: $version_number" #error + gum style "$(_e "!!! Aborted! Failed to create annotated tag: $(_i "$version_number")")" return 1 fi if ! git push origin "$version_number"; then - echo "!!! β›” Aborted! Failed to push tag: $version_number" + # echo "!!! β›” Aborted! Failed to push tag: $version_number" #error + gum style "$(_e "!!! Aborted! Failed to push tag: $(_i "$version_number")")" return 1 fi - echo "Done! βœ…" + # echo "Done! βœ…" + gum style "$(_o 'Done!')" else - echo "!!! πŸ˜• Please specify a release semantic version to tag" + # echo "!!! πŸ˜• Please specify a release semantic version to tag" # remedy + gum style "$(_r '!!! Please specify a release semantic version to tag')" reurn 1 fi