From 95de745ebdaa0a4f16b41cd6769981f295407e8f Mon Sep 17 00:00:00 2001 From: Lembot Date: Sun, 14 Dec 2025 21:14:31 -0500 Subject: [PATCH] feat: add CI check to require version bump when package files change MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds a check-version-bump job that runs on MRs and branch pushes to ensure that when package-related files (src/, package.json, webpack.config.js, tsconfig.json) are modified, the package version must also be bumped. This prevents merging changes that would result in an outdated published package. Closes #5 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .gitlab-ci.yml | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4c54fc9..20ff683 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,5 @@ stages: + - check - build - publish - docker @@ -10,6 +11,57 @@ variables: # NPM registry URL for GitLab packages NPM_REGISTRY: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/npm/" +# Check that package version is bumped when package files change +check-version-bump: + stage: check + script: + - | + echo "Checking if package version needs to be bumped..." + + # Get the target branch (main for MRs, or compare with previous commit) + TARGET_BRANCH="${CI_MERGE_REQUEST_TARGET_BRANCH_NAME:-main}" + + # Fetch the target branch to compare against + git fetch origin "$TARGET_BRANCH" --depth=1 + + # Get current version + CURRENT_VERSION=$(node -p "require('./package.json').version") + echo "Current version: $CURRENT_VERSION" + + # Get target branch version + TARGET_VERSION=$(git show "origin/${TARGET_BRANCH}:package.json" | node -p "JSON.parse(require('fs').readFileSync('/dev/stdin', 'utf8')).version") + echo "Target branch version: $TARGET_VERSION" + + # Define files that require a version bump when changed + PACKAGE_FILES="src/ package.json webpack.config.js tsconfig.json" + + # Check if any package files changed + CHANGED_FILES=$(git diff --name-only "origin/${TARGET_BRANCH}" -- $PACKAGE_FILES || true) + + if [ -n "$CHANGED_FILES" ]; then + echo "Package files changed:" + echo "$CHANGED_FILES" + + if [ "$CURRENT_VERSION" = "$TARGET_VERSION" ]; then + echo "" + echo "ERROR: Package files have changed but version was not bumped!" + echo "Current version ($CURRENT_VERSION) is the same as $TARGET_BRANCH branch." + echo "Please update the version in package.json before merging." + exit 1 + else + echo "Version was bumped from $TARGET_VERSION to $CURRENT_VERSION. OK!" + fi + else + echo "No package files changed. Version bump not required." + fi + rules: + # Run on merge requests + - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' + # Also run on branches (not main) to catch issues early + - if: '$CI_COMMIT_REF_NAME != "main" && $CI_PIPELINE_SOURCE == "push"' + tags: + - public-runner-docker + # Install dependencies once and cache them .node_dependencies: cache: -- GitLab