diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index bfccbb93bd86a90e4bca6a8f2d44d87c9f836a8f..4c54fc98e91f9b151f447059816f34f9c7f3f454 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -47,13 +47,22 @@ publish: - echo "@peerverity:registry=${NPM_REGISTRY}" >> .npmrc - echo "//${CI_SERVER_HOST}/api/v4/projects/${CI_PROJECT_ID}/packages/npm/:_authToken=${CI_JOB_TOKEN}" >> .npmrc script: - - npm publish + - | + PACKAGE_NAME=$(node -p "require('./package.json').name") + PACKAGE_VERSION=$(node -p "require('./package.json').version") + echo "Checking if ${PACKAGE_NAME}@${PACKAGE_VERSION} already exists..." + + # Check if version exists in registry (npm view exits 0 if found) + if npm view "${PACKAGE_NAME}@${PACKAGE_VERSION}" version 2>/dev/null; then + echo "Version ${PACKAGE_VERSION} already published, skipping." + else + echo "Publishing ${PACKAGE_NAME}@${PACKAGE_VERSION}..." + npm publish + fi rules: - # Automatically publish on main branch + # Only publish on main branch - if: '$CI_COMMIT_REF_NAME == "main"' when: on_success - # Allow manual publish on other branches - - when: manual tags: - public-runner-docker