Skip to content

Commit

Permalink
Restrict publications to specific repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
gesellix committed Jul 28, 2022
1 parent 0efb34c commit 18aeda9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
run: |
echo "RELEASE_VERSION=$(echo '${{ github.event.release.tag_name }}' | sed -e s/^v//)" >> $GITHUB_ENV
- name: build publish
run: ./gradlew -Pgradle.publish.key="${{ secrets.GRADLE_PUBLISH_KEY }}" -Pgradle.publish.secret="${{ secrets.GRADLE_PUBLISH_SECRET }}" clean build publish publishPlugins closeAndReleaseStagingRepository -x publishPluginMavenPublicationToGitHubPackagesRepository -x publishPluginMavenPublicationToSonatypeRepository --info --stacktrace -Pversion="${{ env.RELEASE_VERSION }}"
run: ./gradlew -Pgradle.publish.key="${{ secrets.GRADLE_PUBLISH_KEY }}" -Pgradle.publish.secret="${{ secrets.GRADLE_PUBLISH_SECRET }}" clean build publish publishPlugins closeAndReleaseStagingRepository --info --stacktrace -Pversion="${{ env.RELEASE_VERSION }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.GPG_SIGNING_KEY }}
Expand Down
16 changes: 16 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,19 @@ tasks.register("publishTo${gitHubPackagesRepositoryName}") {
it.repository == publishing.repositories[gitHubPackagesRepositoryName]
})
}

val isStandardMavenPublication = { repository: MavenArtifactRepository, publication: MavenPublication ->
publication == publishing.publications[publicationName]
&& repository.name in listOf("sonatype", gitHubPackagesRepositoryName)
}
val isGradlePluginPublish = { repository: MavenArtifactRepository, publication: MavenPublication ->
publication == publishing.publications["pluginMaven"]
&& repository.name !in listOf("sonatype", gitHubPackagesRepositoryName)
}

tasks.withType<PublishToMavenRepository>().configureEach {
onlyIf {
isStandardMavenPublication(repository, publication)
|| isGradlePluginPublish(repository, publication)
}
}

0 comments on commit 18aeda9

Please sign in to comment.