Skip to content

Commit 697f7a8

Browse files
Added github action to publish (#45)
1 parent b6451b1 commit 697f7a8

3 files changed

Lines changed: 69 additions & 14 deletions

File tree

.github/workflows/publish.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Publish to Maven Central
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
publish:
10+
if: contains(github.ref, 'release')
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v5
15+
16+
- name: Set up JDK
17+
uses: actions/setup-java@v4
18+
with:
19+
java-version: 11
20+
distribution: 'temurin'
21+
22+
- name: Publish to Maven Central
23+
run: ./gradlew publish
24+
env:
25+
ORG_GRADLE_PROJECT_NEXUS_USERNAME: ${{ secrets.NEXUS_USERNAME }}
26+
ORG_GRADLE_PROJECT_NEXUS_PASSWORD: ${{ secrets.NEXUS_PASSWORD }}
27+
ORG_GRADLE_PROJECT_SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
28+
ORG_GRADLE_PROJECT_SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
29+
ORG_GRADLE_PROJECT_SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
30+
31+
- name: Notify Central Publisher Portal
32+
if: !contains(github.ref, 'SNAPSHOT')
33+
run: |
34+
token=$(echo -n "${{ secrets.NEXUS_USERNAME }}:${{ secrets.NEXUS_PASSWORD }}" | base64)
35+
curl -X POST \
36+
-H "Authorization: Bearer $token" \
37+
-F "publishing_type=automatic" \
38+
https://central.sonatype.com/manual/upload/defaultRepository/com.pkware.filesystem

README.md

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

6666
## Releasing:
67+
Both a normal or snapshot release can be made. In order to have the publish pipeline run, the release must be made from
68+
a `release/*` branch. For a snapshot release, the release must be made fron a `release/*-SNAPSHOT` branch.
69+
6770
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.
71+
2. Change the version in gradle.properties to a non-SNAPSHOT version if needed.
72+
3. Update the CHANGELOG.md for the impending release for non-SNAPSHOT versions.
7073
4. Run `git commit -am "Release X.Y.Z."` (where X.Y.Z is the new version) in the terminal or
7174
command line.
7275
5. Make a PR with your changes.
7376
6. Merge the release PR after approval, tag the commit on the main branch with
7477
`git tag -a X.Y.Z -m "X.Y.Z"`(X.Y.Z is the new version).
7578
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.
79+
8. Verify [Sonatype] has the artifact published
80+
8. Update `gradle.properties` to the next SNAPSHOT version.
81+
9. Run `git commit -am "Prepare next development version."`
82+
10. Make a PR with your changes.
83+
11. Merge the next version PR after approval.
8484

8585
[Procmon]: https://learn.microsoft.com/en-us/sysinternals/downloads/procmon
86-
[Sonatype Nexus]: https://oss.sonatype.org/
86+
[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)