-
Contents of .gitlab-ci.yml file.
# pipeline for publishing a package to the grendel UPM repository publish: image: node:latest stage: deploy rules: # See https://docs.gitlab.com/ci/variables/predefined_variables # CI_COMMIT_TAG The commit tag name. Available only in pipelines for tags. # Prevent pipeline being triggered recursively by tag push. - if: $CI_COMMIT_TAG when: never - if: $CI_COMMIT_BRANCH == 'main' || $CI_COMMIT_BRANCH == 'develop' changes: - Package/package.json script: # change to the package subdirectory - cd ./Package - npm config set -- '//upm.grendelgames.com/:_authToken' "${NPM_TOKEN}" # Extract a few values from package.json - NPM_PACKAGE_NAME=$(node -p "require('./package.json').name") - NPM_PACKAGE_VERSION=$(node -p "require('./package.json').version") # Compare the version in package.json to all published versions. # If the package.json version has not yet been published, run `npm publish`. - | if [[ $(npm view "${NPM_PACKAGE_NAME}" versions) != *"'${NPM_PACKAGE_VERSION}'"* ]]; then # Publish package to http://upm.grendelgames.com, see .npmrc file. npm publish echo "Successfully published version ${NPM_PACKAGE_VERSION} of ${NPM_PACKAGE_NAME}" git tag "${NPM_PACKAGE_VERSION}" # # Uncomment for debugging. #git remote --verbose # origin http://gitlab-ci-token:[MASKED]@gitlab.grendelgames.com/upm/dummy.git (fetch) # origin http://gitlab-ci-token:[MASKED]@gitlab.grendelgames.com/upm/dummy.git (push) # # Option 1a: git remote set-url origin ${CI_PROJECT_URL/gitlab.com/oauth2:${PAT}@gitlab.com}.git # Option 1b: # Option 2: git remote set-url origin https://gitlab-ci-token:${ACCESS_TOKEN}@gitlab.com/<group>/<repo-name>.git # Option 3: git push https://gitlab-ci-token:<access_token>@gitlab.com/myuser/myrepo.git <branch_name> # Option 3b: git push --tags http://root:$ACCESS_TOKEN@$CI_SERVER_HOST/$CI_PROJECT_PATH.git HEAD:master # Option 4: git remote add origin https://<access-token-name>:<access-token>@gitlab.com/myuser/myrepo.git # Option 5: git remote add gitlab_origin https://oauth2:$ACCESS_TOKEN@gitlab.com/path-to-project.git # Option 6: git remote set-url origin https://oauth2:${AUTOMATION_ACCESS_TOKEN}@${CI_PROJECT_URL#https://}.git # # Push a single tag: git push origin tag <tag_name> # Push all tags (not recommended): git push --tags # Sane option introduced in Git 1.8.3: git push --follow-tags # #echo "Configure git." # # Option 1a: git remote set-url origin ${CI_PROJECT_URL/gitlab.grendelgames.com/oauth2:${CICD_PUSH_TOKEN}@gitlab.grendelgames.com}.git # Works, using parameter expansion. # Option 1b: git remote set-url origin http://oauth2:${CICD_PUSH_TOKEN}@gitlab.grendelgames.com/upm/dummy.git # Works. # Option 2: git remote set-url origin http://gitlab-ci-token:${CICD_PUSH_TOKEN}@gitlab.grendelgames.com/upm/dummy.git # Works. # Option 3a: git push --tags http://gitlab-ci-token:${CICD_PUSH_TOKEN}@gitlab.grendelgames.com/upm/dummy.git # Works. # Option 3b: git push --tags -o ci.skip http://gitlab-ci-token:${CICD_PUSH_TOKEN}@gitlab.grendelgames.com/upm/dummy.git # Works, but -o "ci.skip" is n ot needed. # Option 4: git remote add origin https://gitlab-ci-token:${CICD_PUSH_TOKEN}@gitlab.grendelgames.com/upm/dummy.git # Fails. # Replace https by http and try again. # Option 5: git remote add origin https://oauth2:${CICD_PUSH_TOKEN}@gitlab.grendelgames.com/upm/dummy.git # Fails. # error: remote origin already exists. # Option 6a: git remote set-url origin http://oauth2:${CICD_PUSH_TOKEN}@${CI_PROJECT_URL#http://}.git # Works, using parameter expansion. # Option 6b: git remote set-url origin http://oauth2:${CICD_PUSH_TOKEN}@gitlab.grendelgames.com/upm/dummy.git # Works. # echo "Pushing tags." git push --tags http://gitlab-ci-token:${CICD_PUSH_TOKEN}@gitlab.grendelgames.com/upm/dummy.git # Works. # # Uncomment for debugging. #git remote --verbose # origin http://gitlab-ci-token:[MASKED]@gitlab.grendelgames.com/upm/dummy.git (fetch) # Before. # origin http://gitlab-ci-token:[MASKED]@gitlab.grendelgames.com/upm/dummy.git (push) # Before. # origin http://oauth2:[MASKED]@gitlab.grendelgames.com/upm/dummy.git (fetch) # Option 1a. # origin http://oauth2:[MASKED]@gitlab.grendelgames.com/upm/dummy.git (push) # Option 1a. # origin http://oauth2:@gitlab.grendelgames.com/upm/dummy.git (fetch) # Option 1b. # origin http://oauth2:@gitlab.grendelgames.com/upm/dummy.git (push) # Option 1b. # origin http://gitlab-ci-token:[MASKED]@gitlab.grendelgames.com/upm/dummy.git (fetch) # Option 2. # origin http://gitlab-ci-token:[MASKED]@gitlab.grendelgames.com/upm/dummy.git (push) # Option 2. # origin http://gitlab-ci-token:[MASKED]@gitlab.grendelgames.com/upm/dummy.git (fetch) # Option 3b. # origin http://gitlab-ci-token:[MASKED]@gitlab.grendelgames.com/upm/dummy.git (push) # Option 3b. # origin http://gitlab-ci-token:[MASKED]@gitlab.grendelgames.com/upm/dummy.git (fetch) # Option 4. # origin http://gitlab-ci-token:[MASKED]@gitlab.grendelgames.com/upm/dummy.git (push) # Option 4. # #echo "Pushing tags." # Don't trigger pipeline again. # The -o ci.skip is a not well known Gitlab Git option which allows skipping new CI. # Without ci.skip option CI would be triggered recursively by tag push. # #git push --tags -o ci.skip #git push --tags else echo "Version ${NPM_PACKAGE_VERSION} of ${NPM_PACKAGE_NAME} has already been published, so no new version has been published." fi environment: name: production