11name : Build and Publish
22
33on :
4+ workflow_dispatch :
45 push :
56 branches : [main]
67 paths-ignore :
1213 tags :
1314 - " v[0-9]+.[0-9]+.[0-9]+"
1415env :
15- PREVIEW_TASK : publishSnapshotPublicationToSonatypeSnapshotRepository
16- PUBLISH_TASK : publishMavenCentralReleasePublicationToSonatypeRepository
16+ PREVIEW_TASK : publishToSonatype
17+ PUBLISH_TASK : publishToSonatype closeAndReleaseSonatypeStagingRepository
18+ JAVA_VERSION : 21
19+ JAVA_DISTRIBUTION : ' temurin'
1720
1821permissions :
1922 contents : write
@@ -23,16 +26,19 @@ jobs:
2326 if : ${{ github.ref == 'refs/heads/main' }}
2427 environment :
2528 name : maven_central_snapshot
29+ needs : validate-package-contents
2630 runs-on : ubuntu-latest
2731 steps :
2832 - uses : actions/checkout@v4
29- - name : Easy detect-secrets
30- uses :
RobertFischer/[email protected] 33+ - name : Detect secrets
34+ run : |
35+ pip install detect-secrets
36+ git ls-files -z | xargs -0 detect-secrets-hook --baseline .secrets.baseline
3137 - name : Set up JDK
3238 uses : actions/setup-java@v4
3339 with :
34- java-version : 20
35- distribution : ' temurin '
40+ java-version : ${{ env.JAVA_VERSION }}
41+ distribution : ${{ env.JAVA_DISTRIBUTION }}
3642 cache : gradle
3743 - name : Download file
3844 run : .\scripts\decodeAndWrite.ps1 -encodedValue $env:ENCODED_VALUE -outputPath $env:OUTPUT_PATH
@@ -55,16 +61,19 @@ jobs:
5561 if : ${{ startsWith(github.ref, 'refs/tags/') && github.actor == 'release-please[bot]'}}
5662 environment :
5763 name : maven_central_release
64+ needs : validate-package-contents
5865 runs-on : ubuntu-latest
5966 steps :
6067 - uses : actions/checkout@v4
61- - name : Easy detect-secrets
62- uses :
RobertFischer/[email protected] 68+ - name : Detect secrets
69+ run : |
70+ pip install detect-secrets
71+ git ls-files -z | xargs -0 detect-secrets-hook --baseline .secrets.baseline
6372 - name : Set up JDK
6473 uses : actions/setup-java@v4
6574 with :
66- java-version : 20
67- distribution : ' temurin '
75+ java-version : ${{ env.JAVA_VERSION }}
76+ distribution : ${{ env.JAVA_DISTRIBUTION }}
6877 cache : gradle
6978 - name : Download file
7079 run : .\scripts\decodeAndWrite.ps1 -encodedValue $env:ENCODED_VALUE -outputPath $env:OUTPUT_PATH
8190 - name : Grant execute permission for gradlew
8291 run : chmod +x gradlew
8392 - name : Publish
84- run : ./gradlew $PUBLISH_TASK
93+ run : ./gradlew $PUBLISH_TASK -PmavenCentralSnapshotArtifactSuffix=""
8594 - name : Upload Build Artifact
8695 uses : actions/upload-artifact@v4
8796 with :
@@ -105,3 +114,45 @@ jobs:
105114 files : |
106115 build/**/*.jar
107116
117+ validate-package-contents :
118+ runs-on : ubuntu-latest
119+ environment : ${{ contains(github.ref, 'refs/tags/v') && 'maven_central_release' || 'maven_central_snapshot' }}
120+ defaults :
121+ run :
122+ working-directory : ./
123+ steps :
124+ - uses : actions/checkout@v4
125+ - name : Setup JDK
126+ uses : actions/setup-java@v4
127+ with :
128+ java-version : ${{ env.JAVA_VERSION }}
129+ distribution : ${{ env.JAVA_DISTRIBUTION}}
130+ cache : gradle
131+ - name : Download file
132+ run : .\scripts\decodeAndWrite.ps1 -encodedValue $env:ENCODED_VALUE -outputPath $env:OUTPUT_PATH
133+ shell : pwsh
134+ env :
135+ ENCODED_VALUE : ${{ secrets.LOCAL_PROPERTIES }}
136+ OUTPUT_PATH : ' local.properties'
137+ - name : Download file
138+ run : .\scripts\decodeAndWrite.ps1 -encodedValue $env:ENCODED_VALUE -outputPath $env:OUTPUT_PATH
139+ shell : pwsh
140+ env :
141+ ENCODED_VALUE : ${{ secrets.SECRING_GPG }}
142+ OUTPUT_PATH : ' .\secring.gpg'
143+ - name : Publish to local Maven cache for validation
144+ run : ./gradlew --no-daemon publishToMavenLocal
145+ - name : Get current SNAPSHOT version
146+ shell : pwsh
147+ run : |
148+ $contents = Get-Content gradle.properties -Raw
149+ $major = $contents | Select-String -Pattern 'mavenMajorVersion\s+= ([0-9]+)' | ForEach-Object { $_.Matches.Groups[1].Value }
150+ $minor = $contents | Select-String -Pattern 'mavenMinorVersion\s+= ([0-9]+)' | ForEach-Object { $_.Matches.Groups[1].Value }
151+ $patch = $contents | Select-String -Pattern 'mavenPatchVersion\s+= ([0-9]+)' | ForEach-Object { $_.Matches.Groups[1].Value }
152+ $version = "$major.$minor.$patch-SNAPSHOT"
153+ echo "Current version is $version"
154+ echo "PACKAGE_VERSION=$version" >> $Env:GITHUB_ENV
155+ - name : Inspect contents of local Maven cache
156+ shell : pwsh
157+ run : |
158+ .\scripts\validatePackageContents.ps1 -ArtifactId microsoft-graph-core -Version $env:PACKAGE_VERSION
0 commit comments