Skip to content

Commit b15252b

Browse files
committed
Update release workflows
1 parent 9b96625 commit b15252b

File tree

1 file changed

+54
-7
lines changed

1 file changed

+54
-7
lines changed

.github/workflows/preview-and-release.yml

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ on:
1414
workflow_dispatch:
1515

1616
env:
17-
PREVIEW_TASK: publishSnapshotPublicationToSonatypeSnapshotRepository
18-
PUBLISH_TASK: publishMavenCentralReleasePublicationToSonatypeRepository
17+
PREVIEW_TASK: publishToSonatype
18+
PUBLISH_TASK: publishToSonatype closeAndReleaseSonatypeStagingRepository
19+
JAVA_VERSION: 21
20+
JAVA_DISTRIBUTION: 'temurin'
1921

2022
permissions:
2123
contents: write
@@ -26,13 +28,14 @@ jobs:
2628
environment:
2729
name: maven_central_snapshot
2830
runs-on: ubuntu-latest
31+
needs: validate-package-contents
2932
steps:
3033
- uses: actions/checkout@v4
3134
- name: Set up JDK
3235
uses: actions/setup-java@v4
3336
with:
34-
java-version: 21
35-
distribution: 'temurin'
37+
java-version: ${{ env.JAVA_VERSION }}
38+
distribution: ${{ env.JAVA_DISTRIBUTION}}
3639
cache: gradle
3740
- name: Easy detect-secrets
3841
uses: RobertFischer/detect-secrets-action@v2.0.0
@@ -58,13 +61,14 @@ jobs:
5861
environment:
5962
name: maven_central_release
6063
runs-on: ubuntu-latest
64+
needs: validate-package-contents
6165
steps:
6266
- uses: actions/checkout@v4
6367
- name: Set up JDK
6468
uses: actions/setup-java@v4
6569
with:
66-
java-version: 21
67-
distribution: 'temurin'
70+
java-version: ${{ env.JAVA_VERSION }}
71+
distribution: ${{ env.JAVA_DISTRIBUTION}}
6872
cache: gradle
6973
- name: Easy detect-secrets
7074
uses: RobertFischer/detect-secrets-action@v2.0.0
@@ -83,7 +87,7 @@ jobs:
8387
- name: Grant execute permission for gradlew
8488
run: chmod +x gradlew
8589
- name: Publish
86-
run: ./gradlew $PUBLISH_TASK
90+
run: ./gradlew $PUBLISH_TASK -PmavenCentralSnapshotArtifactSuffix=""
8791
- name: Upload Build Artifact
8892
uses: actions/upload-artifact@v4
8993
with:
@@ -106,3 +110,46 @@ jobs:
106110
fail_on_unmatched_files: true
107111
files: |
108112
build/**/*.jar
113+
114+
validate-package-contents:
115+
runs-on: ubuntu-latest
116+
environment: ${{ contains(github.ref, 'refs/tags/v') && 'maven_central_release' || 'maven_central_snapshot' }}
117+
defaults:
118+
run:
119+
working-directory: ./
120+
steps:
121+
- uses: actions/checkout@v4
122+
- name: Setup JDK
123+
uses: actions/setup-java@v4
124+
with:
125+
java-version: ${{ env.JAVA_VERSION }}
126+
distribution: ${{ env.JAVA_DISTRIBUTION}}
127+
cache: gradle
128+
- name: Download file
129+
run: .\scripts\decodeAndWrite.ps1 -encodedValue $env:ENCODED_VALUE -outputPath $env:OUTPUT_PATH
130+
shell: pwsh
131+
env:
132+
ENCODED_VALUE: ${{ secrets.LOCAL_PROPERTIES }}
133+
OUTPUT_PATH: 'local.properties'
134+
- name: Download file
135+
run: .\scripts\decodeAndWrite.ps1 -encodedValue $env:ENCODED_VALUE -outputPath $env:OUTPUT_PATH
136+
shell: pwsh
137+
env:
138+
ENCODED_VALUE: ${{ secrets.SECRING_GPG }}
139+
OUTPUT_PATH: '.\secring.gpg'
140+
- name: Publish to local Maven cache for validation
141+
run: ./gradlew --no-daemon publishToMavenLocal
142+
- name: Get current SNAPSHOT version
143+
shell: pwsh
144+
run: |
145+
$contents = Get-Content gradle.properties -Raw
146+
$major = $contents | Select-String -Pattern 'mavenMajorVersion\s+= ([0-9]+)' | ForEach-Object { $_.Matches.Groups[1].Value }
147+
$minor = $contents | Select-String -Pattern 'mavenMinorVersion\s+= ([0-9]+)' | ForEach-Object { $_.Matches.Groups[1].Value }
148+
$patch = $contents | Select-String -Pattern 'mavenPatchVersion\s+= ([0-9]+)' | ForEach-Object { $_.Matches.Groups[1].Value }
149+
$version = "$major.$minor.$patch-SNAPSHOT"
150+
echo "Current version is $version"
151+
echo "PACKAGE_VERSION=$version" >> $Env:GITHUB_ENV
152+
- name: Inspect contents of local Maven cache
153+
shell: pwsh
154+
run: |
155+
.\scripts\validatePackageContents.ps1 -ArtifactId msgraph-sdk-java -Version $env:PACKAGE_VERSION

0 commit comments

Comments
 (0)