Skip to content

Commit 0e565a3

Browse files
committed
ci(workflows): up bump increment logic
1 parent 6a1bddd commit 0e565a3

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

.github/workflows/bump-version.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,4 @@ jobs:
3232
PR_BODY_BUMP_KEY: ${{ vars.PR_BODY_BUMP_KEY }}
3333
PR_BODY_IMAGE_KEY: ${{ vars.PR_BODY_IMAGE_KEY }}
3434
run: |
35-
BRANCH_NAME=${GITHUB_REF#refs/heads/}
36-
./scripts/bump_version.sh "$BRANCH_NAME"
35+
make bump-version

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Local development
2+
*.bak

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ DEVCONTAINER_TEST_GLOBAL_FLAGS=--global-scenarios-only
1818
DEVCONTAINER_TEST_AUTOGENERATED_FLAGS=--skip-scenarios -f $(FEATURES) -i $(BASE_IMAGE)
1919
DEVCONTAINER_TEST_SCENARIOS_FLAGS=-f $(FEATURES) --skip-autogenerated --skip-duplicated
2020

21+
# Bump
22+
SCRIPTS_PATH=./scripts
23+
BUMP_VERSION_SCRIPT=$(SCRIPTS_PATH)/bump_version.sh
24+
2125
.PHONY: help
2226
help: ## Display this help message.
2327
@echo "Usage: make [TARGET]"
@@ -41,4 +45,5 @@ test-scenarios: ## Run scenario tests for a specific feature. Argument: FEATURES
4145

4246
.PHONY: bump-version
4347
bump-version: ## Run bump_version.sh script. Arguments: DRY_RUN.
44-
./scripts/bump_version.sh $(DRY_RUN)
48+
chmod +x $(BUMP_VERSION_SCRIPT)
49+
$(BUMP_VERSION_SCRIPT) $(DRY_RUN)

scripts/bump_version.sh

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#
1010
# This script will:
1111
#
12-
# Install the necessary tools ( jq , gh , semver )
12+
# Install the necessary tools (npm and system dependencies[git, curl, jq])
1313
# Get the commit type
1414
# Get the equivalent version increment
1515
# Get the latest version
@@ -89,13 +89,12 @@ install_tools() {
8989
get_version_increment() {
9090
local feature_name=$(basename $feature)
9191
local last_tag=$(git describe --tags --abbrev=0)
92-
local previous_tag=$(git describe --tags --abbrev=0 $last_tag^)
93-
local commit_types=$(git log --pretty=%B $previous_tag..$last_tag -- src/$feature_name | grep -oE '^(feat|fix|BREAKING CHANGE)')
94-
if echo $commit_types | grep -q 'BREAKING CHANGE'; then
92+
local commit_messages=$(git log --pretty=format:"%s%n%n%b" $last_tag..HEAD -- src/$feature_name)
93+
if echo "$commit_messages" | grep -qE 'BREAKING CHANGE'; then
9594
echo 'major'
96-
elif echo $commit_types | grep -q 'feat'; then
95+
elif echo "$commit_messages" | grep -qE '^feat(\(.+\))?:'; then
9796
echo 'minor'
98-
elif echo $commit_types | grep -q 'fix'; then
97+
elif echo "$commit_messages" | grep -qE '^fix(\(.+\))?:'; then
9998
echo 'patch'
10099
else
101100
echo ''
@@ -111,7 +110,8 @@ get_latest_version() {
111110
if [ -z "$tags" ]; then
112111
echo $DEFAULT_VERSION
113112
else
114-
echo $tags | tr ' ' '\n' | sort -V | tail -n 1
113+
# Filter out non-numeric tags, sort the remaining tags, and select the last one
114+
echo $tags | tr ' ' '\n' | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -n 1
115115
fi
116116
}
117117

@@ -240,14 +240,13 @@ main() {
240240
for feature in src/*; do
241241
feature_name=$(basename $feature)
242242
echo
243-
log_info "ℹ️ Checking if files in $feature_name were changed in the last tag..."
244243
last_tag=$(git describe --tags --abbrev=0)
245-
previous_tag=$(git describe --tags --abbrev=0 $last_tag^)
246-
if ! git diff --name-only $previous_tag $last_tag | grep -q "$feature_name"; then
247-
log_info "No changes for $feature_name in the last tag. Skipping version bump."
244+
log_info "ℹ️ [\033[1;36m$feature_name\033[0m] \033[1;32m[$last_tag]\033[0m Checking for diffs..."
245+
if ! git diff --name-only $last_tag..HEAD -- $feature_name | grep -q "$feature_name"; then
246+
log_info "No changes detected. Skipping version bump."
248247
continue
249248
fi
250-
log_warn "OK. Changes found for $feature in the last tag."
249+
log_warn "OK. Changes found for $feature in the current tag."
251250

252251
log_info "ℹ️ Getting version increment..."
253252
version_increment=$(get_version_increment)

0 commit comments

Comments
 (0)