Skip to content

Commit

Permalink
allow manually passing a profile id
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielittner committed Jun 19, 2024
1 parent c2df28d commit b6a9185
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/publish-snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Publish Snapshot
on:
push:
branches:
- main
- '**'
tags:
- '**'

Expand All @@ -26,9 +26,15 @@ jobs:
java-version: 11

- name: Set version
if: ${{ github.ref_name == 'main' || startsWith(github.ref, 'refs/tags/') }}
run: |
echo "ORG_GRADLE_PROJECT_VERSION_NAME=$(git describe --tags --abbrev=0 | awk -F. '/[0-9]+\./{$NF++;print}' OFS=.)-SNAPSHOT" >> $GITHUB_ENV
- name: Set version for branch
if: ${{ github.ref_name != 'main' && !startsWith(github.ref, 'refs/tags/') }}
run: |
echo "ORG_GRADLE_PROJECT_VERSION_NAME=${{ github.ref_name }}-SNAPSHOT" | sed 's#/#-#g' >> $GITHUB_ENV
- uses: gradle/gradle-build-action@v3

- name: Publish
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ class Nexus(
return candidateProfiles[0]
}

private fun createStagingRepository(group: String, profile: StagingProfile): String {
println("Creating repository in profile: ${profile.name}")
private fun createStagingRepository(group: String, profileId: String): String {
println("Creating repository in profile with id: $profileId")

val response = service.createRepository(profile.id, CreateRepositoryInput(CreateRepositoryInputData("Repository for $group"))).execute()
val response = service.createRepository(profileId, CreateRepositoryInput(CreateRepositoryInputData("Repository for $group"))).execute()
if (!response.isSuccessful) {
throw IOException("Cannot create repository: ${response.errorBody()?.string()}")
}
Expand All @@ -95,9 +95,9 @@ class Nexus(
return id
}

fun createRepositoryForGroup(group: String): String {
val profile = findStagingProfile(group)
return createStagingRepository(group, profile)
fun createRepositoryForGroup(group: String, profileId: String): String {
// val profile = findStagingProfile(group)
return createStagingRepository(group, profileId)
}

private fun getProfileRepositories(): List<Repository>? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ internal abstract class SonatypeRepositoryBuildService :

internal interface Params : BuildServiceParameters {
val sonatypeHost: Property<SonatypeHost>
val stagingProfileId: Property<String>
val groupId: Property<String>
val versionIsSnapshot: Property<Boolean>
val repositoryUsername: Property<String>
Expand Down Expand Up @@ -122,7 +123,7 @@ internal abstract class SonatypeRepositoryBuildService :
uploadId = if (parameters.sonatypeHost.get().isCentralPortal) {
UUID.randomUUID().toString()
} else {
nexus.createRepositoryForGroup(parameters.groupId.get())
nexus.createRepositoryForGroup(parameters.groupId.get(), parameters.stagingProfileId.get())
}

endOfBuildActions += EndOfBuildAction.Close(searchForRepositoryIfNoIdPresent = false)
Expand Down Expand Up @@ -325,6 +326,7 @@ internal abstract class SonatypeRepositoryBuildService :
automaticRelease: Boolean,
rootBuildDirectory: Provider<Directory>,
): Provider<SonatypeRepositoryBuildService> {
val profileId = project.providers.gradleProperty("SONATYPE_STAGING_PROFILE_ID")
val okhttpTimeout = project.providers.gradleProperty("SONATYPE_CONNECT_TIMEOUT_SECONDS")
.map { it.toLong() }
.orElse(60)
Expand All @@ -334,6 +336,7 @@ internal abstract class SonatypeRepositoryBuildService :
val service = gradle.sharedServices.registerIfAbsent(NAME, SonatypeRepositoryBuildService::class.java) {
it.maxParallelUsages.set(1)
it.parameters.sonatypeHost.set(sonatypeHost)
it.parameters.stagingProfileId.set(profileId)
it.parameters.groupId.set(groupId)
it.parameters.versionIsSnapshot.set(versionIsSnapshot)
it.parameters.repositoryUsername.set(repositoryUsername)
Expand Down

0 comments on commit b6a9185

Please sign in to comment.