From 25cc15957c16347986722631cc090f8fba9755c7 Mon Sep 17 00:00:00 2001 From: Alex Zolotko Date: Thu, 30 Nov 2023 13:13:22 +0100 Subject: [PATCH] Bug: gitlabProjectId was never used (#92) Co-authored-by: Alex Zolotko --- README.md | 18 ++++++++++++++---- .../nl/zolotko/sbt/gitlab/GitlabPlugin.scala | 14 +++++--------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 8b9ea1d..035ceef 100644 --- a/README.md +++ b/README.md @@ -56,11 +56,10 @@ gitlabRepositories ++= Seq( ) ``` -### Publishing to GitLab via GitLab CI/CD +### Publishing from GitLab CI/CD -Utilizing the sbt publish command within GitLab CI/CD should require no additional configuration. This plugin -automatically pulls the following GitLab environment variables which should always be provided by default within GitLab -Pipelines +Doing `sbt publish` from GitLab CI/CD should require no additional configuration. +This plugin automatically pulls the following GitLab environment variables provided by GitLab Pipelines: ```shell $CI_JOB_TOKEN # Access Token to authorize read/writes to the GitLab package registry @@ -70,6 +69,17 @@ $CI_GROUP_ID # GitLab Group ID. Used for fetching Artifacts published under t $CI_SERVER_HOST # The host name for GitLab defaults to gitlab.com ``` +### Publishing outside GitLab CI/CD + +For `sbt publish` to work outside GitLab CI/CD, at least `gitlabDomain` and `gitlabProjectId` need to be defined: + +```sbt +gitlabDomain := "gitlab.your-company.com" +gitlabProjectId := GitlabProjectId("unicorn").some +``` + +(remember to set up the [Credentials](#Credentials)) + ### Testing Run `test` for regular unit tests (there are none at the moment). diff --git a/src/main/scala/nl/zolotko/sbt/gitlab/GitlabPlugin.scala b/src/main/scala/nl/zolotko/sbt/gitlab/GitlabPlugin.scala index cd7c5f9..65b211e 100644 --- a/src/main/scala/nl/zolotko/sbt/gitlab/GitlabPlugin.scala +++ b/src/main/scala/nl/zolotko/sbt/gitlab/GitlabPlugin.scala @@ -92,9 +92,7 @@ object GitlabPlugin extends AutoPlugin { ) } - private lazy val gitlabProjectSettings: Seq[Def.Setting[?]] = { - val gitlabProjectId = sys.env.get("CI_PROJECT_ID").map(GitlabProjectId.apply) - + private lazy val gitlabProjectSettings: Seq[Def.Setting[?]] = Seq( publishMavenStyle := true, gitlabDomain := sys.env.getOrElse("CI_SERVER_HOST", "gitlab.com"), @@ -117,12 +115,11 @@ object GitlabPlugin extends AutoPlugin { updateSbtClassifiers := updateSbtClassifiers .dependsOn(gitlabHeaderAuthHandler) .value, - publish := publish.dependsOn(gitlabHeaderAuthHandler).value, + publish := publish.dependsOn(gitlabHeaderAuthHandler).value, + gitlabProjectId := sys.env.get("CI_PROJECT_ID").map(GitlabProjectId.apply), publishTo := (ThisProject / publishTo).value.orElse( - gitlabProjectId - .map( - GitlabProjectRepository(gitlabDomain.value, _).resolver - ) + gitlabProjectId.value + .map(GitlabProjectRepository(gitlabDomain.value, _).resolver) ), gitlabRepositories := Seq.empty, resolvers ++= gitlabRepositories.value.map(_.resolver), @@ -142,5 +139,4 @@ object GitlabPlugin extends AutoPlugin { allGitlabCredentials.value ) ) - } }