Skip to content

Commit

Permalink
fix(workflows/release): regex corrections (#6)
Browse files Browse the repository at this point in the history
* misc: update regex link

* fix(workflows/release): parse * and _ in markdown h1, correct release title

* fix(workflows/release): correct regex, add missing line numbers

* docs: document global DRY_RUN var better
  • Loading branch information
tcodes0 authored Sep 2, 2024
1 parent b55ba19 commit 5585e57
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Initial Release v0.1.0 _(2024-08-30)_
# Initial Release: v0.1.0 _(2024-08-30)_

## Features

Expand Down
22 changes: 11 additions & 11 deletions workflows/release/tag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ validate() {
done < <(git log --oneline --decorate)

if ! [[ $main_head =~ $release_re ]]; then
log "main head not a release commit: $main_head"
log $LINENO "main head not a release commit: $main_head"
exit 0
fi
}
Expand All @@ -50,8 +50,8 @@ validate() {
# Example : tags="$(parse_changelog_tags)"
parse_changelog_tags() {
local tags=() newest_date tag date
# https://regex101.com/r/67rzeb/4
local changelog_h1_re="#[[:blank:]]+(?:[a-zA-Z0-9 !%&*()-+]+:)?[[:blank:]]*([a-zA-Z0-9\/.]+)[[:blank:]]+\*\(([[:digit:]]+-[[:digit:]]+-[[:digit:]]+)"
# https://regex101.com/r/67rzeb/6
local changelog_h1_re="#[[:blank:]]+([a-zA-Z0-9 !%&*()-+]+:)?[[:blank:]]*([a-zA-Z0-9\/.]+)[[:blank:]]+[*_]\(([[:digit:]]+-[[:digit:]]+-[[:digit:]]+)"

while read -r line; do
if ! [[ "$line" =~ $changelog_h1_re ]]; then
Expand All @@ -60,8 +60,8 @@ parse_changelog_tags() {
continue
fi

tag="${BASH_REMATCH[1]}"
date="${BASH_REMATCH[2]}"
tag="${BASH_REMATCH[2]}"
date="${BASH_REMATCH[3]}"

if [ ! "${newest_date:-}" ]; then
# want to push tags for the newest release only
Expand Down Expand Up @@ -90,18 +90,18 @@ validate_tags() {
local tags=("$@")

if [ ${#tags[@]} == 0 ]; then
fatal "no tags found"
fatal $LINENO "no tags found"
fi

for tag in "${tags[@]}"; do
echo "$tag"
if git rev-parse --verify "$tag" >/dev/null; then
fatal "tag already exists: $tag"
if git rev-parse --verify "$tag" >/dev/null 2>&1; then
fatal $LINENO "tag already exists: $tag"
fi
done
}

# Description: Creates and pushes git tags
# Globals : DRY_RUN (set to echo to dry run)
# Args : words separated by spaces
# STDOUT : Prints each tag created, plus git output
# STDERR : Git might output
Expand All @@ -110,10 +110,10 @@ validate_tags() {
tag_and_push() {
for tag in "$@"; do
msgln "$tag"
git tag "$tag" HEAD
$DRY_RUN git tag "$tag" HEAD
done

git push origin --tags
$DRY_RUN git push origin --tags
}

##############
Expand Down

0 comments on commit 5585e57

Please sign in to comment.