Skip to content

Commit e76eed7

Browse files
Update Sonatype publishing to use OSSRH Staging Repository
1 parent 7ad7107 commit e76eed7

3 files changed

Lines changed: 77 additions & 14 deletions

File tree

.github/workflows/publish.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Publish to Maven Central
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
publish:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v5
14+
15+
- name: Set up JDK
16+
uses: actions/setup-java@v4
17+
with:
18+
java-version: 11
19+
distribution: 'temurin'
20+
21+
- name: Publish to Maven Central
22+
run: ./gradlew publish
23+
env:
24+
ORG_GRADLE_PROJECT_NEXUS_USERNAME: ${{ secrets.NEXUS_USERNAME }}
25+
ORG_GRADLE_PROJECT_NEXUS_PASSWORD: ${{ secrets.NEXUS_PASSWORD }}
26+
ORG_GRADLE_PROJECT_SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
27+
ORG_GRADLE_PROJECT_SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
28+
ORG_GRADLE_PROJECT_SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
29+
30+
- name: Check version
31+
id: version
32+
run: |
33+
version=$(grep "attributeCachingFilesystemVersion" gradle.properties | cut -d'=' -f2 | tr -d ' ')
34+
if [[ "$version" != *"SNAPSHOT"* ]]; then
35+
echo "is_release=true" >> $GITHUB_OUTPUT
36+
else
37+
echo "is_release=false" >> $GITHUB_OUTPUT
38+
fi
39+
40+
- name: Notify Central Publisher Portal
41+
if: steps.version.outputs.is_release == 'true'
42+
run: |
43+
token=$(echo -n "${{ secrets.NEXUS_USERNAME }}:${{ secrets.NEXUS_PASSWORD }}" | base64)
44+
curl -X POST \
45+
--max-time 30 \
46+
--fail-with-body \
47+
-H "Authorization: Bearer $token" \
48+
"https://ossrh-staging-api.central.sonatype.com/manual/upload/defaultRepository/com.pkware.filesystem?publishing_type=automatic"

README.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,21 @@ val cachingPath = cachingFilesystem.convertToCachingPath(path)
6464
```
6565

6666
## Releasing:
67+
6768
1. Make and checkout a release branch on github.
68-
2. Change the version in gradle.properties to a non-SNAPSHOT version.
69-
3. Update the CHANGELOG.md for the impending release.
69+
2. Change the version in gradle.properties to a non-SNAPSHOT version if needed.
70+
3. Update the CHANGELOG.md for the impending release for non-SNAPSHOT versions.
7071
4. Run `git commit -am "Release X.Y.Z."` (where X.Y.Z is the new version) in the terminal or
7172
command line.
7273
5. Make a PR with your changes.
7374
6. Merge the release PR after approval, tag the commit on the main branch with
7475
`git tag -a X.Y.Z -m "X.Y.Z"`(X.Y.Z is the new version).
7576
7. Run `git push --tags`.
76-
8. Run `./gradlew publish` in the terminal or command line.
77-
9. Visit [Sonatype Nexus] and promote the artifact.
78-
10. Update `gradle.properties` to the next SNAPSHOT version.
79-
11. Run `git commit -am "Prepare next development version."`
80-
12. Make a PR with your changes.
81-
13. Merge the next version PR after approval.
82-
83-
If step 8 or 9 fails, drop the Sonatype repo, fix the problem, commit, and start again at step 8.
77+
8. Verify [Sonatype] has the artifact published
78+
8. Update `gradle.properties` to the next SNAPSHOT version.
79+
9. Run `git commit -am "Prepare next development version."`
80+
10. Make a PR with your changes.
81+
11. Merge the next version PR after approval.
8482

8583
[Procmon]: https://learn.microsoft.com/en-us/sysinternals/downloads/procmon
86-
[Sonatype Nexus]: https://oss.sonatype.org/
84+
[Sonatype]: https://central.sonatype.com/

file-attribute-caching/build.gradle.kts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ publishing {
7474
}
7575
repositories {
7676
maven {
77+
name = "MavenCentral"
7778
url = uri(if (version.toString().isReleaseBuild) releaseRepositoryUrl else snapshotRepositoryUrl)
7879
credentials {
7980
username = repositoryUsername
@@ -84,8 +85,15 @@ publishing {
8485
}
8586

8687
signing {
87-
// Signing credentials are stored locally in the user's global gradle.properties file.
88+
// Signing credentials are stored as secrets in GitHub.
8889
// See https://docs.gradle.org/current/userguide/signing_plugin.html#sec:signatory_credentials for more information.
90+
91+
useInMemoryPgpKeys(
92+
signingKeyId, // ID of the GPG key
93+
signingKey, // GPG public key
94+
signingPassword, // Password for the GPG public key
95+
)
96+
8997
sign(publishing.publications["mavenJava"])
9098
}
9199

@@ -95,13 +103,13 @@ val String.isReleaseBuild
95103
val Project.releaseRepositoryUrl: String
96104
get() = properties.getOrDefault(
97105
"RELEASE_REPOSITORY_URL",
98-
"https://oss.sonatype.org/service/local/staging/deploy/maven2",
106+
"https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2",
99107
).toString()
100108

101109
val Project.snapshotRepositoryUrl: String
102110
get() = properties.getOrDefault(
103111
"SNAPSHOT_REPOSITORY_URL",
104-
"https://oss.sonatype.org/content/repositories/snapshots",
112+
"https://central.sonatype.com/repository/maven-snapshots/",
105113
).toString()
106114

107115
val Project.repositoryUsername: String
@@ -110,6 +118,15 @@ val Project.repositoryUsername: String
110118
val Project.repositoryPassword: String
111119
get() = properties.getOrDefault("NEXUS_PASSWORD", "").toString()
112120

121+
val Project.signingKeyId: String
122+
get() = properties.getOrDefault("SIGNING_KEY_ID", "").toString()
123+
124+
val Project.signingKey: String
125+
get() = properties.getOrDefault("SIGNING_KEY", "").toString()
126+
127+
val Project.signingPassword: String
128+
get() = properties.getOrDefault("SIGNING_PASSWORD", "").toString()
129+
113130
val Project.pomPackaging: String
114131
get() = properties.getOrDefault("POM_PACKAGING", "jar").toString()
115132

0 commit comments

Comments
 (0)