Loading README.md +15 −12 Original line number Diff line number Diff line Loading @@ -138,16 +138,7 @@ In addition to logs in the console, this job produces the following reports, kep The sbt template supports [publishing](https://www.scala-sbt.org/1.x/docs/Publishing.html): * snapshot artifacts (on any branch change), * and/or release artifacts (on versioned tags such as `RELEASES/x.y.z`) It uses the following environment variables : | name | description | default value | |-----------------------------------------|---------------------------------------------------|---------------| | `MAVEN_REPOSITORY_PUBLISH_SNAPSHOT_URL` | Destination repository to publish snpashot artifacts | N/A | | `MAVEN_REPOSITORY_PUBLISH_RELEASE_URL` | Destination repository to publish release artifacts | N/A | | `MAVEN_REPOSITORY_PUBLISH_USERNAME` | | `MAVEN_REPOSITORY_PUBLISH_PASSWORD` | * and/or release artifacts (on versioned tags such as `x.y.z`) The expected behavior of publish jobs is controlled with the `SBT_PUBLISH_MODE` variable, supporting one of the following values: Loading @@ -170,6 +161,17 @@ You shall handle them in the following way: 2. [define the target repositories and the credentials](https://www.scala-sbt.org/1.x/docs/Publishing.html#Credentials) with a dedicated sbt file such as `publish.sbt` **in your project home directory** Example: Define the following environment variables : | name | description | |-----------------------------------------|---------------------------------------------------| | `MAVEN_REPOSITORY_PUBLISH_SNAPSHOT_URL` | Destination repository to publish snpashot artifacts | | `MAVEN_REPOSITORY_PUBLISH_RELEASE_URL` | Destination repository to publish release artifacts | | `MAVEN_REPOSITORY_PUBLISH_USERNAME` | Repository Username | | `MAVEN_REPOSITORY_PUBLISH_PASSWORD` | Repository Password | ```sbt credentials ++= { Loading Loading @@ -215,7 +217,8 @@ It is based on the [sbt-release](https://github.com/sbt/sbt-release) plugin. You `project/plugins.sbt`: ```sbt addSbtPlugin("com.github.sbt" % "sbt-release" % "1.1.0") // Check for newer releases : https://search.maven.org/artifact/com.github.sbt/sbt-release // Check for newer releases : https://search.maven.org/artifact/com.github.sbt/sbt-release addSbtPlugin("com.github.sbt" % "sbt-release" % "1.1.0") ``` #### SCM authentication Loading templates/gitlab-ci-sbt.yml +18 −16 Original line number Diff line number Diff line Loading @@ -65,6 +65,8 @@ variables: PROD_REF: '/^(master|main)$/' # default integration ref name (pattern) INTEG_REF: '/^develop$/' # default release tag name (pattern) RELEASE_REF: '/^v?[0-9]+\.[0-9]+\.[0-9]+$/' SBT_TEST_ARGS: coverage test coverageAggregate SBT_BUILD_ARGS: clean package Loading Loading @@ -349,15 +351,19 @@ sbt-publish-snapshot: # else: if $SBT_PUBLISH_MODE is set - if: $SBT_PUBLISH_MODE sbt-publish-on-tag: sbt-publish-stable: extends: .sbt-base stage: publish script: - version=${CI_COMMIT_TAG#RELEASES/} - assert_defined "$version" "Couldn't get the version from the release tags from CI_COMMIT_TAG value '$CI_COMMIT_TAG'" - sbt $SBT_CLI_OPTS ${TRACE+-v} $java_proxy_args "set version:=\"$version\"" publish - if [[ "$CI_COMMIT_TAG" =~ ([0-9]+\.[0-9]+\.[0-9]+) ]]; then tag_version="${BASH_REMATCH[1]}"; fi - assert_defined "$tag_version" "Couldn't determine the version from the release tag ($CI_COMMIT_TAG)" - sbt $SBT_CLI_OPTS ${TRACE+-v} $java_proxy_args "set version:=\"$tag_version\"" publish rules: - if: '$CI_COMMIT_TAG =~ /^RELEASES\/.+/ && $SBT_PUBLISH_MODE == "ontag"' # exclude if $SBT_PUBLISH_MODE not 'ontag' or 'release' - if: '$SBT_PUBLISH_MODE != "ontag" && $SBT_PUBLISH_MODE != "release"' when: never # on tag with release pattern: auto - if: '$CI_COMMIT_TAG =~ $RELEASE_REF' sbt-release: extends: .sbt-base Loading @@ -373,28 +379,24 @@ sbt-release: - echo "$GIT_PRIVATE_KEY" | ssh-add - - mkdir -m 700 $HOME/.ssh - ssh-keyscan -H $CI_SERVER_HOST >> ~/.ssh/known_hosts - echo "----- Fixing git setup for branch $CI_COMMIT_REF_NAME" - log_info "--- Fixing Git setup for branch $CI_COMMIT_REF_NAME" - git reset --hard - git clean -fd - git checkout ${CI_COMMIT_REF_NAME} - git pull origin ${CI_COMMIT_REF_NAME} - git config user.name $GITLAB_USER_ID - git config user.email $GITLAB_USER_EMAIL - echo "----- Switching to a SSH GIT access to allow write access through private key" - log_info "--- Switching to a SSH GIT access to allow write access through private key" - git remote set-url origin "git@${CI_SERVER_HOST}:$(echo $CI_REPOSITORY_URL | cut -d'/' -f4-)" script: sbt $SBT_CLI_OPTS ${TRACE+-v} $java_proxy_args '; set releaseIgnoreUntrackedFiles:=true; set releaseCommitMessage:="[ci skip] "+releaseCommitMessage.value; set releaseTagComment:="[ci skip] "+releaseTagComment.value; set releaseNextCommitMessage:="[ci skip] "+releaseNextCommitMessage.value; release with-defaults' rules: # on production branch(es): manual & non-blocking if $SBT_PUBLISH_MODE is 'release' - if: '$SBT_PUBLISH_MODE == "release" && $CI_COMMIT_REF_NAME =~ $PROD_REF' when: manual allow_failure: true # on integration branch(es): manual & non-blocking if $MAVEN_DEPLOY_ENABLED is 'release' - if: '$SBT_PUBLISH_MODE == "release" && $CI_COMMIT_REF_NAME =~ $INTEG_REF' # exclude if $SBT_PUBLISH_MODE not 'release' - if: '$SBT_PUBLISH_MODE != "release"' when: never # on production or integration branch: manual, non blocking - if: '$CI_COMMIT_REF_NAME =~ $PROD_REF || $CI_COMMIT_REF_NAME =~ $INTEG_REF' when: manual allow_failure: true Loading
README.md +15 −12 Original line number Diff line number Diff line Loading @@ -138,16 +138,7 @@ In addition to logs in the console, this job produces the following reports, kep The sbt template supports [publishing](https://www.scala-sbt.org/1.x/docs/Publishing.html): * snapshot artifacts (on any branch change), * and/or release artifacts (on versioned tags such as `RELEASES/x.y.z`) It uses the following environment variables : | name | description | default value | |-----------------------------------------|---------------------------------------------------|---------------| | `MAVEN_REPOSITORY_PUBLISH_SNAPSHOT_URL` | Destination repository to publish snpashot artifacts | N/A | | `MAVEN_REPOSITORY_PUBLISH_RELEASE_URL` | Destination repository to publish release artifacts | N/A | | `MAVEN_REPOSITORY_PUBLISH_USERNAME` | | `MAVEN_REPOSITORY_PUBLISH_PASSWORD` | * and/or release artifacts (on versioned tags such as `x.y.z`) The expected behavior of publish jobs is controlled with the `SBT_PUBLISH_MODE` variable, supporting one of the following values: Loading @@ -170,6 +161,17 @@ You shall handle them in the following way: 2. [define the target repositories and the credentials](https://www.scala-sbt.org/1.x/docs/Publishing.html#Credentials) with a dedicated sbt file such as `publish.sbt` **in your project home directory** Example: Define the following environment variables : | name | description | |-----------------------------------------|---------------------------------------------------| | `MAVEN_REPOSITORY_PUBLISH_SNAPSHOT_URL` | Destination repository to publish snpashot artifacts | | `MAVEN_REPOSITORY_PUBLISH_RELEASE_URL` | Destination repository to publish release artifacts | | `MAVEN_REPOSITORY_PUBLISH_USERNAME` | Repository Username | | `MAVEN_REPOSITORY_PUBLISH_PASSWORD` | Repository Password | ```sbt credentials ++= { Loading Loading @@ -215,7 +217,8 @@ It is based on the [sbt-release](https://github.com/sbt/sbt-release) plugin. You `project/plugins.sbt`: ```sbt addSbtPlugin("com.github.sbt" % "sbt-release" % "1.1.0") // Check for newer releases : https://search.maven.org/artifact/com.github.sbt/sbt-release // Check for newer releases : https://search.maven.org/artifact/com.github.sbt/sbt-release addSbtPlugin("com.github.sbt" % "sbt-release" % "1.1.0") ``` #### SCM authentication Loading
templates/gitlab-ci-sbt.yml +18 −16 Original line number Diff line number Diff line Loading @@ -65,6 +65,8 @@ variables: PROD_REF: '/^(master|main)$/' # default integration ref name (pattern) INTEG_REF: '/^develop$/' # default release tag name (pattern) RELEASE_REF: '/^v?[0-9]+\.[0-9]+\.[0-9]+$/' SBT_TEST_ARGS: coverage test coverageAggregate SBT_BUILD_ARGS: clean package Loading Loading @@ -349,15 +351,19 @@ sbt-publish-snapshot: # else: if $SBT_PUBLISH_MODE is set - if: $SBT_PUBLISH_MODE sbt-publish-on-tag: sbt-publish-stable: extends: .sbt-base stage: publish script: - version=${CI_COMMIT_TAG#RELEASES/} - assert_defined "$version" "Couldn't get the version from the release tags from CI_COMMIT_TAG value '$CI_COMMIT_TAG'" - sbt $SBT_CLI_OPTS ${TRACE+-v} $java_proxy_args "set version:=\"$version\"" publish - if [[ "$CI_COMMIT_TAG" =~ ([0-9]+\.[0-9]+\.[0-9]+) ]]; then tag_version="${BASH_REMATCH[1]}"; fi - assert_defined "$tag_version" "Couldn't determine the version from the release tag ($CI_COMMIT_TAG)" - sbt $SBT_CLI_OPTS ${TRACE+-v} $java_proxy_args "set version:=\"$tag_version\"" publish rules: - if: '$CI_COMMIT_TAG =~ /^RELEASES\/.+/ && $SBT_PUBLISH_MODE == "ontag"' # exclude if $SBT_PUBLISH_MODE not 'ontag' or 'release' - if: '$SBT_PUBLISH_MODE != "ontag" && $SBT_PUBLISH_MODE != "release"' when: never # on tag with release pattern: auto - if: '$CI_COMMIT_TAG =~ $RELEASE_REF' sbt-release: extends: .sbt-base Loading @@ -373,28 +379,24 @@ sbt-release: - echo "$GIT_PRIVATE_KEY" | ssh-add - - mkdir -m 700 $HOME/.ssh - ssh-keyscan -H $CI_SERVER_HOST >> ~/.ssh/known_hosts - echo "----- Fixing git setup for branch $CI_COMMIT_REF_NAME" - log_info "--- Fixing Git setup for branch $CI_COMMIT_REF_NAME" - git reset --hard - git clean -fd - git checkout ${CI_COMMIT_REF_NAME} - git pull origin ${CI_COMMIT_REF_NAME} - git config user.name $GITLAB_USER_ID - git config user.email $GITLAB_USER_EMAIL - echo "----- Switching to a SSH GIT access to allow write access through private key" - log_info "--- Switching to a SSH GIT access to allow write access through private key" - git remote set-url origin "git@${CI_SERVER_HOST}:$(echo $CI_REPOSITORY_URL | cut -d'/' -f4-)" script: sbt $SBT_CLI_OPTS ${TRACE+-v} $java_proxy_args '; set releaseIgnoreUntrackedFiles:=true; set releaseCommitMessage:="[ci skip] "+releaseCommitMessage.value; set releaseTagComment:="[ci skip] "+releaseTagComment.value; set releaseNextCommitMessage:="[ci skip] "+releaseNextCommitMessage.value; release with-defaults' rules: # on production branch(es): manual & non-blocking if $SBT_PUBLISH_MODE is 'release' - if: '$SBT_PUBLISH_MODE == "release" && $CI_COMMIT_REF_NAME =~ $PROD_REF' when: manual allow_failure: true # on integration branch(es): manual & non-blocking if $MAVEN_DEPLOY_ENABLED is 'release' - if: '$SBT_PUBLISH_MODE == "release" && $CI_COMMIT_REF_NAME =~ $INTEG_REF' # exclude if $SBT_PUBLISH_MODE not 'release' - if: '$SBT_PUBLISH_MODE != "release"' when: never # on production or integration branch: manual, non blocking - if: '$CI_COMMIT_REF_NAME =~ $PROD_REF || $CI_COMMIT_REF_NAME =~ $INTEG_REF' when: manual allow_failure: true