Skip to content

Commit

Permalink
fix(bash): enhance update-repo-tags to detect annotated tags
Browse files Browse the repository at this point in the history
and support prerel versions

Signed-off-by: Kevin O'Donnell <kevin@blockchaintp.com>
  • Loading branch information
scealiontach committed Sep 29, 2021
1 parent 19789ad commit 8ed4e34
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
14 changes: 7 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ default_language_version:
python: python3
repos:
- repo: https://github.com/commitizen-tools/commitizen
rev: v2.17.6
rev: v2.19.0
hooks:
- id: commitizen
stages: [commit-msg]
- repo: https://github.com/gruntwork-io/pre-commit
rev: v0.1.12
rev: v0.1.15
hooks:
- id: helmlint
- repo: https://github.com/gherynos/pre-commit-java
Expand Down Expand Up @@ -44,11 +44,11 @@ repos:
- "2"
- -ci
- repo: https://github.com/markdownlint/markdownlint
rev: master
rev: v0.11.0
hooks:
- id: markdownlint_docker
- id: markdownlint
- repo: https://github.com/pre-commit/mirrors-eslint
rev: v7.26.0
rev: v8.0.0-rc.0
hooks:
- id: eslint
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand Down Expand Up @@ -89,12 +89,12 @@ repos:
- id: fmt
- id: cargo-check
- repo: https://github.com/adrienverge/yamllint
rev: v1.26.1
rev: v1.26.3
hooks:
- id: yamllint
exclude: ".*/templates/.*"
- repo: https://github.com/IamTheFij/docker-pre-commit
rev: v2.0.0
rev: v2.0.1
hooks:
- id: docker-compose-check
- id: docker-compose-check
Expand Down
38 changes: 31 additions & 7 deletions bash/update-repo-tags
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ options::add -o t -d "target directory to examine and update" -a -m \
-e TARGET_DIR
options::add -o p -d "Patch tag" \
-x PATCH_TAG
options::add -o n -d "Don't annotate tag" \
-x DONT_ANNOTATE_TAG
options::add -o b -d "proceed to bump minor version if breaking changes are found" \
-x ALLOW_BREAKING
options::add -o c -d "generate and commit change before tagging" \
Expand All @@ -40,11 +38,23 @@ options::parse "$@"
pushd "$TARGET_DIR" >/dev/null || exit 1

LATEST_TAG=$(git::cmd describe --tags --match 'v*' --abbrev=0) || exit 1
DONT_ANNOTATE_TAG=false
if ! LATEST_ANNOTATED_TAG=$(git::cmd describe --match 'v*' --abbrev=0 2>/dev/null); then
log::notice "No prior tag was annotated"
DONT_ANNOTATE_TAG=true
else
if [ "$LATEST_TAG" != "$LATEST_ANNOTATED_TAG" ] || [ -z "$LATEST_ANNOTATED_TAG" ]; then
DONT_ANNOTATE_TAG=true
else
DONT_ANNOTATE_TAG=false
fi
fi

LATEST_VERSION=$(echo "$LATEST_TAG" | cut -c2-)
BREAKING_CHANGES=$(git::cmd log "$LATEST_TAG"..HEAD | grep -c "BREAKING CHANGE")
CHANGES=$(git::cmd log "$LATEST_TAG"..HEAD | grep -c "^commit")

log::notice "$LATEST_VERSION $CHANGES changes $BREAKING_CHANGES breaks"
log::notice "Since $LATEST_VERSION $CHANGES changes $BREAKING_CHANGES breaks"

skip="true"
if [ "$BREAKING_CHANGES" -gt 0 ]; then
Expand All @@ -56,9 +66,18 @@ if [ "$BREAKING_CHANGES" -gt 0 ]; then
exit 1
fi
elif [ "$CHANGES" -gt 0 ]; then
TAG=$("$(dirs::of)/semver" bump patch "$LATEST_VERSION")
# if we can't annotate tag then we must do a prerel bump
if [ "${DONT_ANNOTATE_TAG}" = "true" ]; then
PREREL=$("$(dirs::of)/semver" get prerel "$LATEST_VERSION")
((PREREL++))
TAG=$("$(dirs::of)/semver" bump prerel "$PREREL" "$LATEST_VERSION")
TAG=${TAG/"-$PREREL"/"p$PREREL"}
else
TAG=$("$(dirs::of)/semver" bump patch "$LATEST_VERSION")
fi
skip="false"
else
log::notice "No changes since $LATEST_VERSION"
TAG="$LATEST_VERSION"
skip="true"
fi
Expand All @@ -68,12 +87,17 @@ TAG="v${TAG}"
if [ "$skip" = "false" ]; then
log::notice "Will tag as $TAG"
if [ "$DONT_ANNOTATE_TAG" = "true" ]; then
log::notice "No changelog updates for prerel builds"
git::cmd tag "$TAG"
else
if [ "$GENERATE_CHANGELOG" = "true" ]; then
"$(dirs::of)"/changelog -l | sed -e "s/Unreleased/$TAG/" >CHANGELOG.md
git add CHANGELOG.md
git commit --no-verify -m "ci: Update CHANGELOG releasing $TAG" CHANGELOG.md
if [ -r "CHANGELOG.md" ]; then
"$(dirs::of)"/changelog -l | sed -e "s/Unreleased/$TAG/" >CHANGELOG.md
git add CHANGELOG.md
git commit --no-verify -m "ci: Update CHANGELOG releasing $TAG" CHANGELOG.md
else
log::notice "No prior changelog found. Will not generate a new one."
fi
fi
git::cmd tag -a -s "$TAG" -m "Auto Tagging $TAG"
fi
Expand Down

0 comments on commit 8ed4e34

Please sign in to comment.