diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4c54fc98e91f9b151f447059816f34f9c7f3f454..20ff683569dc7418e70959141bbacd5fa948c278 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: