From e8548b87be2ab2408cfd63421412d5cb0958c46b Mon Sep 17 00:00:00 2001 From: Harshitha D Date: Tue, 26 May 2026 12:08:27 +0530 Subject: [PATCH] Update check-version-bump.yml --- .github/workflows/check-version-bump.yml | 41 ++++++++++-------------- 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/.github/workflows/check-version-bump.yml b/.github/workflows/check-version-bump.yml index 8e71000..35a58c2 100644 --- a/.github/workflows/check-version-bump.yml +++ b/.github/workflows/check-version-bump.yml @@ -22,40 +22,33 @@ jobs: FILES=$(git diff --name-only HEAD~1 HEAD) fi VERSION_FILES_CHANGED=false - echo "$FILES" | grep -qx 'package.json' && VERSION_FILES_CHANGED=true + echo "$FILES" | grep -qx 'lib/contentstack/version.rb' && VERSION_FILES_CHANGED=true echo "$FILES" | grep -qx 'CHANGELOG.md' && VERSION_FILES_CHANGED=true echo "version_files_changed=$VERSION_FILES_CHANGED" >> $GITHUB_OUTPUT - # Only lib/, webpack/, dist/, package.json count as release-affecting; .github/ and test/ do not + # Only lib/ counts as release-affecting; .github/ and spec/ do not CODE_CHANGED=false - echo "$FILES" | grep -qE '^lib/|^webpack/|^dist/' && CODE_CHANGED=true - echo "$FILES" | grep -qx 'package.json' && CODE_CHANGED=true + echo "$FILES" | grep -qE '^lib/' && CODE_CHANGED=true echo "code_changed=$CODE_CHANGED" >> $GITHUB_OUTPUT - name: Skip when only test/docs/.github changed if: steps.detect.outputs.code_changed != 'true' run: | - echo "No release-affecting files changed (e.g. only test/docs/.github). Skipping version-bump check." + echo "No release-affecting files changed (e.g. only spec/docs/.github). Skipping version-bump check." exit 0 - name: Fail when version bump was missed if: steps.detect.outputs.code_changed == 'true' && steps.detect.outputs.version_files_changed != 'true' run: | - 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." + 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." exit 1 - - name: Setup Node - if: steps.detect.outputs.code_changed == 'true' && steps.detect.outputs.version_files_changed == 'true' - uses: actions/setup-node@v4 - with: - node-version: '22.x' - - name: Check version bump if: steps.detect.outputs.code_changed == 'true' && steps.detect.outputs.version_files_changed == 'true' run: | set -e - PKG_VERSION=$(node -p "require('./package.json').version.replace(/^v/, '')") - if [ -z "$PKG_VERSION" ]; then - echo "::error::Could not read version from package.json" + GEM_VERSION=$(sed -n 's/.*VERSION = "\(.*\)".*/\1/p' lib/contentstack/version.rb) + if [ -z "$GEM_VERSION" ]; then + echo "::error::Could not read version from lib/contentstack/version.rb" exit 1 fi git fetch --tags --force 2>/dev/null || true @@ -66,21 +59,21 @@ jobs: fi LATEST_VERSION="${LATEST_TAG#v}" LATEST_VERSION="${LATEST_VERSION%%-*}" - if [ "$(printf '%s\n' "$LATEST_VERSION" "$PKG_VERSION" | sort -V | tail -1)" != "$PKG_VERSION" ]; then - 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." + if [ "$(printf '%s\n' "$LATEST_VERSION" "$GEM_VERSION" | sort -V | tail -1)" != "$GEM_VERSION" ]; then + echo "::error::Version bump required: lib/contentstack/version.rb ($GEM_VERSION) is not greater than latest tag ($LATEST_TAG). Please bump Contentstack::VERSION." exit 1 fi - if [ "$PKG_VERSION" = "$LATEST_VERSION" ]; then - echo "::error::Version bump required: package.json version ($PKG_VERSION) equals latest tag ($LATEST_TAG). Please bump the version in package.json." + if [ "$GEM_VERSION" = "$LATEST_VERSION" ]; then + echo "::error::Version bump required: lib/contentstack/version.rb ($GEM_VERSION) equals latest tag ($LATEST_TAG). Please bump Contentstack::VERSION." exit 1 fi - CHANGELOG_VERSION=$(sed -nE 's/^## \[v?([0-9]+\.[0-9]+\.[0-9]+).*/\1/p' CHANGELOG.md | head -1) + CHANGELOG_VERSION=$(sed -nE 's/^## Version ([0-9]+\.[0-9]+\.[0-9]+).*/\1/p' CHANGELOG.md | head -1) if [ -z "$CHANGELOG_VERSION" ]; then - echo "::error::Could not find a version entry in CHANGELOG.md (expected line like '## [v1.0.0](...)')." + echo "::error::Could not find a version entry in CHANGELOG.md (expected line like '## Version 1.0.0')." exit 1 fi - if [ "$CHANGELOG_VERSION" != "$PKG_VERSION" ]; then - 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." + if [ "$CHANGELOG_VERSION" != "$GEM_VERSION" ]; then + 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." exit 1 fi - echo "Version bump check passed: package.json and CHANGELOG.md are at $PKG_VERSION (latest tag: $LATEST_TAG)." + echo "Version bump check passed: lib/contentstack/version.rb and CHANGELOG.md are at $GEM_VERSION (latest tag: $LATEST_TAG)."