Merge branch 'master' of github.com:HariSekhon/DevOps-Bash-tools

pull/16/head
Hari Sekhon 2 years ago
commit 88f4000c03

@ -99,6 +99,8 @@ alias br=branch
alias fetch='git fetch' alias fetch='git fetch'
alias stash="git stash" alias stash="git stash"
alias tag="githg tag" alias tag="githg tag"
alias tags='git tag'
alias tagr='git_tag_release.sh'
alias gitlogwc='git log --oneline | wc -l' alias gitlogwc='git log --oneline | wc -l'
alias um=updatemodules alias um=updatemodules
#type browse &>/dev/null || alias browse=gbrowse #type browse &>/dev/null || alias browse=gbrowse

@ -649,6 +649,7 @@ etc.
- `git_log_empty_commits.sh` - find empty commits in git history (eg. if a `git filter-branch` was run but `--prune-empty` was forgotten, leaking metadata like subjects containing file names or other sensitive info) - `git_log_empty_commits.sh` - find empty commits in git history (eg. if a `git filter-branch` was run but `--prune-empty` was forgotten, leaking metadata like subjects containing file names or other sensitive info)
- `git_files_in_history.sh` - finds all filename / file paths in the git log history, useful for prepping for `git filter-branch` - `git_files_in_history.sh` - finds all filename / file paths in the git log history, useful for prepping for `git filter-branch`
- `git_filter_branch_fix_author.sh` - rewrites Git history to replace author/committer name & email references (useful to replace default account commits). Powerful, read `--help` and `man git-filter-branch` carefully. Should only be used by Git Experts. - `git_filter_branch_fix_author.sh` - rewrites Git history to replace author/committer name & email references (useful to replace default account commits). Powerful, read `--help` and `man git-filter-branch` carefully. Should only be used by Git Experts.
- `git_tag_release.sh` - creates a Git tag, auto-incrementing a `.N` suffix on the year/month/day date format if no exact version given
- `git_submodules_update_repos.sh` - updates submodules (pulls and commits latest upstream github repo submodules) - used to cascade submodule updates throughout all my repos - `git_submodules_update_repos.sh` - updates submodules (pulls and commits latest upstream github repo submodules) - used to cascade submodule updates throughout all my repos
- `github_*.sh` - [GitHub](https://github.com/) API / CLI scripts: - `github_*.sh` - [GitHub](https://github.com/) API / CLI scripts:
- `github_api.sh` - queries the GitHub [API](https://docs.github.com/en/rest/reference). Can infer GitHub user, repo and authentication token from local checkout or environment (`$GITHUB_USER`, `$GITHUB_TOKEN`) - `github_api.sh` - queries the GitHub [API](https://docs.github.com/en/rest/reference). Can infer GitHub user, repo and authentication token from local checkout or environment (`$GITHUB_USER`, `$GITHUB_TOKEN`)

@ -0,0 +1,91 @@
#!/usr/bin/env bash
# vim:ts=4:sts=4:sw=4:et
#
# Author: Hari Sekhon
# Date: 2022-07-12 14:18:52 +0100 (Tue, 12 Jul 2022)
#
# https://github.com/HariSekhon/DevOps-Bash-tools
#
# License: see accompanying Hari Sekhon LICENSE file
#
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
#
# https://www.linkedin.com/in/HariSekhon
#
set -euo pipefail
[ -n "${DEBUG:-}" ] && set -x
srcdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck disable=SC1090
. "$srcdir/lib/github.sh"
# shellcheck disable=SC2034,SC2154
usage_description="
Creates a Git Tag for the current repo checkout, auto-incrementing the default vYYYY.NN release if one isn't given
The first argument is an optional version, which is recommended to set to vN.N.N eg. v1.0.0 as per semantic versioning standards
If the first argument is 'day' or 'date', will determine the next available release in the format vYYYYMMDD.NN where NN is incremented from 1
If the first argument is 'month', will determine the next available release in the format vYYYYMM.NN
If the first argument is 'year', will determine the next available release in the format vYYYY.NN
If no argument is given, defaults to generating a 'year' version in the format vYYYY.NN
These formats don't have dashes in them like ISO dates so that if you move from YYYY to YYYYMM format or YYYYMMDD format, software will recognize the newer format as the highest version number ie. the latest version
Requires the Git command to be installed
Don't forget to 'git push --tags' to send the tag upstream
"
# used by usage() in lib/utils.sh
# shellcheck disable=SC2034
usage_args="[<version> <commit>]"
help_usage "$@"
#min_args 1 "$@"
version="${1:-year}"
commit="${2:-HEAD}"
shift || :
shift || :
generate_version=0
prefix='v'
if [ -n "${NO_GIT_RELEASE_PREFIX:-}" ]; then
prefix=''
fi
if [ "$version" = year ]; then
version="${prefix}$(date '+%Y')"
generate_version=1
elif [ "$version" = month ]; then
version="${prefix}$(date '+%Y%m')"
generate_version=1
elif [ "$version" = day ] || [ "$version" = date ]; then
version="${prefix}$(date '+%Y%m%d')"
generate_version=1
fi
if [ "$generate_version" = 1 ]; then
existing_tags="$(git tags)"
number="$(grep -Eo "^$version"'\.\d+' <<< "$existing_tags" | head -n 1 | sed "s/^$version\\.//" || echo 1)"
# increment the number
while grep -Fxq "$version.$number" <<< "$existing_tags"; do
((number+=1))
if [ $number -gt 9999 ]; then
die "FAILED to find unused tag version in format '$version.NN'"
fi
done
version+=".$number"
fi
timestamp "Generating tag '$version' on commit '$commit'"
git tag "$version" "$commit"
timestamp "Generated release tag '$version'"

@ -22,7 +22,7 @@ srcdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck disable=SC2034,SC2154 # shellcheck disable=SC2034,SC2154
usage_description=" usage_description="
Creates a GitHub Release and Git Tag, auto-incrementing the default vYYYY.NN release if one isn't given Creates a GitHub Release and Git Tag for the current repo checkout, auto-incrementing the default vYYYY.NN release if one isn't given
Determines the GitHub repository to create a release in from the local checkout from which it is executed, Determines the GitHub repository to create a release in from the local checkout from which it is executed,
unless \$GITHUB_OWNER_REPO is set in the environment or '-R <owner>/<repo>' are given as the final args unless \$GITHUB_OWNER_REPO is set in the environment or '-R <owner>/<repo>' are given as the final args
@ -31,7 +31,9 @@ The first argument is the version, which is recommended to set to vN.N.N eg. v1.
If the first argument is 'day' or 'date', will determine the next available release in the format vYYYYMMDD.NN where NN is incremented from 1 If the first argument is 'day' or 'date', will determine the next available release in the format vYYYYMMDD.NN where NN is incremented from 1
If the first argument is 'month', will determine the next available release in the format vYYYYMM.NN If the first argument is 'month', will determine the next available release in the format vYYYYMM.NN
If the first argument is 'year', will determine the next available release in the format vYYYY.NN (the default if no version is specified) If the first argument is 'year', will determine the next available release in the format vYYYY.NN
If no argument is given, defaults to generating a 'year' version in the format vYYYY.NN
These formats don't have dashes in them like ISO dates so that if you move from YYYY to YYYYMM format or YYYYMMDD format, GitHub will recognize the newer format as the Latest release These formats don't have dashes in them like ISO dates so that if you move from YYYY to YYYYMM format or YYYYMMDD format, GitHub will recognize the newer format as the Latest release
@ -75,7 +77,7 @@ if [ "$version" = year ]; then
elif [ "$version" = month ]; then elif [ "$version" = month ]; then
version="${prefix}$(date '+%Y%m')" version="${prefix}$(date '+%Y%m')"
generate_version=1 generate_version=1
elif [ "$version" = day ] [ "$version" = date ]; then elif [ "$version" = day ] || [ "$version" = date ]; then
version="${prefix}$(date '+%Y%m%d')" version="${prefix}$(date '+%Y%m%d')"
generate_version=1 generate_version=1
fi fi

Loading…
Cancel
Save