Skip to content

Commit

Permalink
Remove commit-msg hook; improve version-bump script
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed Apr 17, 2024
1 parent 873bab0 commit 479eb4a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 36 deletions.
12 changes: 6 additions & 6 deletions scripts/hooks/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Git Hooks

A few hooks to ensure consistency and automation. Please setup the hooks if you contribute to pagy with PRs.
A hook to ensure consistency and automation. Please setup the hook if you contribute to pagy with PRs.

See also the brief description inside the hook file.

See also the brief description inside each hook file.

## Setup

### Symlink

Symlink the hooks into the `.git/hooks` dir:
Symlink the hook into the `.git/hooks` dir:

```shell
# from the repo root
ln -s ../../scripts/hooks/{pre-commit,commit-msg} .git/hooks
ln -s ../../scripts/hooks/pre-commit .git/hooks
```

### Copy
Expand All @@ -21,5 +21,5 @@ Only for filesystem that don't support symlinks: copy the hooks into the `.git/h

```shell
# from the repo root
cp scripts/hooks/{pre-commit,commit-msg} .git/hooks
cp scripts/hooks/pre-commit .git/hooks
```
18 changes: 0 additions & 18 deletions scripts/hooks/commit-msg

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ gem_changes=$(git diff --cached --name-status --relative=gem)
if [[ -n "$gem_changes" ]]
then
branch=$(git rev-parse --abbrev-ref HEAD)
if [[ $branch == master* ]]
if [[ "$branch" == master* ]]
then
cat <<-EOF
Error: The following changes in the "gem" root path
Expand Down
28 changes: 17 additions & 11 deletions scripts/version-bump.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

set -e

# Exit if the working tree is dirty
test -n "$(git status --porcelain)" && echo "Working tree dirty!" && exit 1
# Abort if the working tree is dirty
[[ -z "$(git status --porcelain)" ]] || (>&2 echo "Working tree dirty!" && exit 1)

# Set the root path
dir="$(dirname -- "$0")"
Expand All @@ -15,10 +15,14 @@ old_vers=$(ruby -Igem/lib -rpagy -e 'puts Pagy::VERSION')
echo "Current Pagy::VERSION: $old_vers"
read -rp 'Enter the new version> ' new_vers

# Check the new version
[[ -z $new_vers ]] && echo 'Missing new version!' && exit 1
# Abort if the version is invalid
[[ -n $new_vers ]] || ( >&2 echo 'Missing new version!' && exit 1)
num=$(echo "$new_vers" | grep -o '\.' | wc -l)
[[ $num == 2 ]] || (echo 'Incomplete semantic version!' && exit 1)
[[ $num == 2 ]] || (>&2 echo 'Incomplete semantic version!' && exit 1)

# Abort if there is no gem change
[[ -n $(git diff --name-only --relative=gem "$old_vers"..HEAD) ]] || \
(>&2 echo "No gem changes since version $old_vers!" && exit 1)

# Bump version in files
esc_old_vers=${old_vers//./\\.}
Expand Down Expand Up @@ -48,20 +52,22 @@ cd "$ROOT/src"
pnpm run build
cd "$ROOT"

# Set TMPLOG to the commit messages marked as [GEM] (changes in the "gem" root path)
# Set TMPLOG to the commit messages that have changes in the "gem" root path
TMPLOG=$(mktemp)
# Iterate through the new commits
for commit in $(git rev-list "$old_vers"..HEAD)
do
msg=$(git show --no-patch --format="%s%n%b" $commit)
if [[ $msg == \[GEM\]\ * ]] # if gem changes
if [[ -n $(git show --pretty="format:" --name-only --relative=gem) ]]
then
sed 's/^/\ \ /; s/^\ \ \[GEM\]/-/' <<<"$msg" >> "$TMPLOG" # append to the temp file
git show --no-patch --format="- %s" $commit >> "$TMPLOG"
body=$(git show --no-patch --format="%b" $commit)
if [[ -n "$body" ]]
then
sed 's/^/\ \ /' <<<"$body" >> "$TMPLOG"
fi
fi
done

[[ -s "$TMPLOG" ]] || read -p 'The CHANGELOG is empty! (enter)> '

# Insert the changes in the the release body file used by .github/workflows/create_release.yml
# which is triggered by the :rubygem_release task (push tag)
lead='^<!-- changes start -->$'
Expand Down

0 comments on commit 479eb4a

Please sign in to comment.