Skip to content

Commit 02a6aa3

Browse files
fix version check workflow
1 parent 245366f commit 02a6aa3

1 file changed

Lines changed: 17 additions & 24 deletions

File tree

.github/workflows/check-version-bump.yml

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,40 +22,33 @@ jobs:
2222
FILES=$(git diff --name-only HEAD~1 HEAD)
2323
fi
2424
VERSION_FILES_CHANGED=false
25-
echo "$FILES" | grep -qx 'package.json' && VERSION_FILES_CHANGED=true
25+
echo "$FILES" | grep -qx 'lib/contentstack/version.rb' && VERSION_FILES_CHANGED=true
2626
echo "$FILES" | grep -qx 'CHANGELOG.md' && VERSION_FILES_CHANGED=true
2727
echo "version_files_changed=$VERSION_FILES_CHANGED" >> $GITHUB_OUTPUT
28-
# Only lib/, webpack/, dist/, package.json count as release-affecting; .github/ and test/ do not
28+
# Only lib/ counts as release-affecting; .github/ and spec/ do not
2929
CODE_CHANGED=false
30-
echo "$FILES" | grep -qE '^lib/|^webpack/|^dist/' && CODE_CHANGED=true
31-
echo "$FILES" | grep -qx 'package.json' && CODE_CHANGED=true
30+
echo "$FILES" | grep -qE '^lib/' && CODE_CHANGED=true
3231
echo "code_changed=$CODE_CHANGED" >> $GITHUB_OUTPUT
3332
3433
- name: Skip when only test/docs/.github changed
3534
if: steps.detect.outputs.code_changed != 'true'
3635
run: |
37-
echo "No release-affecting files changed (e.g. only test/docs/.github). Skipping version-bump check."
36+
echo "No release-affecting files changed (e.g. only spec/docs/.github). Skipping version-bump check."
3837
exit 0
3938
4039
- name: Fail when version bump was missed
4140
if: steps.detect.outputs.code_changed == 'true' && steps.detect.outputs.version_files_changed != 'true'
4241
run: |
43-
echo "::error::This PR has code changes but no version bump. Please bump the version in package.json and add an entry in CHANGELOG.md."
42+
echo "::error::This PR has code changes but no version bump. Please bump the version in lib/contentstack/version.rb and add an entry in CHANGELOG.md."
4443
exit 1
4544
46-
- name: Setup Node
47-
if: steps.detect.outputs.code_changed == 'true' && steps.detect.outputs.version_files_changed == 'true'
48-
uses: actions/setup-node@v4
49-
with:
50-
node-version: '22.x'
51-
5245
- name: Check version bump
5346
if: steps.detect.outputs.code_changed == 'true' && steps.detect.outputs.version_files_changed == 'true'
5447
run: |
5548
set -e
56-
PKG_VERSION=$(node -p "require('./package.json').version.replace(/^v/, '')")
57-
if [ -z "$PKG_VERSION" ]; then
58-
echo "::error::Could not read version from package.json"
49+
GEM_VERSION=$(sed -n 's/.*VERSION = "\(.*\)".*/\1/p' lib/contentstack/version.rb)
50+
if [ -z "$GEM_VERSION" ]; then
51+
echo "::error::Could not read version from lib/contentstack/version.rb"
5952
exit 1
6053
fi
6154
git fetch --tags --force 2>/dev/null || true
@@ -66,21 +59,21 @@ jobs:
6659
fi
6760
LATEST_VERSION="${LATEST_TAG#v}"
6861
LATEST_VERSION="${LATEST_VERSION%%-*}"
69-
if [ "$(printf '%s\n' "$LATEST_VERSION" "$PKG_VERSION" | sort -V | tail -1)" != "$PKG_VERSION" ]; then
70-
echo "::error::Version bump required: package.json version ($PKG_VERSION) is not greater than latest tag ($LATEST_TAG). Please bump the version in package.json."
62+
if [ "$(printf '%s\n' "$LATEST_VERSION" "$GEM_VERSION" | sort -V | tail -1)" != "$GEM_VERSION" ]; then
63+
echo "::error::Version bump required: lib/contentstack/version.rb ($GEM_VERSION) is not greater than latest tag ($LATEST_TAG). Please bump Contentstack::VERSION."
7164
exit 1
7265
fi
73-
if [ "$PKG_VERSION" = "$LATEST_VERSION" ]; then
74-
echo "::error::Version bump required: package.json version ($PKG_VERSION) equals latest tag ($LATEST_TAG). Please bump the version in package.json."
66+
if [ "$GEM_VERSION" = "$LATEST_VERSION" ]; then
67+
echo "::error::Version bump required: lib/contentstack/version.rb ($GEM_VERSION) equals latest tag ($LATEST_TAG). Please bump Contentstack::VERSION."
7568
exit 1
7669
fi
77-
CHANGELOG_VERSION=$(sed -nE 's/^## \[v?([0-9]+\.[0-9]+\.[0-9]+).*/\1/p' CHANGELOG.md | head -1)
70+
CHANGELOG_VERSION=$(sed -nE 's/^## Version ([0-9]+\.[0-9]+\.[0-9]+).*/\1/p' CHANGELOG.md | head -1)
7871
if [ -z "$CHANGELOG_VERSION" ]; then
79-
echo "::error::Could not find a version entry in CHANGELOG.md (expected line like '## [v1.0.0](...)')."
72+
echo "::error::Could not find a version entry in CHANGELOG.md (expected line like '## Version 1.0.0')."
8073
exit 1
8174
fi
82-
if [ "$CHANGELOG_VERSION" != "$PKG_VERSION" ]; then
83-
echo "::error::CHANGELOG version mismatch: CHANGELOG.md top version ($CHANGELOG_VERSION) does not match package.json version ($PKG_VERSION). Please add or update the CHANGELOG entry for $PKG_VERSION."
75+
if [ "$CHANGELOG_VERSION" != "$GEM_VERSION" ]; then
76+
echo "::error::CHANGELOG version mismatch: CHANGELOG.md top version ($CHANGELOG_VERSION) does not match lib/contentstack/version.rb ($GEM_VERSION). Please add or update the CHANGELOG entry for $GEM_VERSION."
8477
exit 1
8578
fi
86-
echo "Version bump check passed: package.json and CHANGELOG.md are at $PKG_VERSION (latest tag: $LATEST_TAG)."
79+
echo "Version bump check passed: lib/contentstack/version.rb and CHANGELOG.md are at $GEM_VERSION (latest tag: $LATEST_TAG)."

0 commit comments

Comments
 (0)