Skip to content

Commit 126d7d3

Browse files
committed
Update release workflows
1 parent dca5d64 commit 126d7d3

4 files changed

Lines changed: 113 additions & 66 deletions

File tree

.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,6 +28,7 @@ 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: Detect secrets
@@ -35,8 +38,8 @@ jobs:
3538
- name: Set up JDK
3639
uses: actions/setup-java@v4
3740
with:
38-
java-version: 21
39-
distribution: 'temurin'
41+
java-version: ${{ env.JAVA_VERSION }}
42+
distribution: ${{ env.JAVA_DISTRIBUTION }}
4043
cache: gradle
4144
- name: Download File
4245
run: .\Scripts\decodeAndWrite.ps1 -encodedValue $env:ENCODED_VALUE -outputPath $env:OUTPUT_PATH
@@ -60,13 +63,14 @@ jobs:
6063
environment:
6164
name: maven_central_release
6265
runs-on: ubuntu-latest
66+
needs: validate-package-contents
6367
steps:
6468
- uses: actions/checkout@v4
6569
- name: Set up JDK
6670
uses: actions/setup-java@v4
6771
with:
68-
java-version: 21
69-
distribution: 'temurin'
72+
java-version: ${{ env.JAVA_VERSION }}
73+
distribution: ${{ env.JAVA_DISTRIBUTION }}
7074
cache: gradle
7175
- name: Detect secrets
7276
run: |
@@ -87,7 +91,7 @@ jobs:
8791
- name: Grant execute permission for gradlew
8892
run: chmod +x gradlew
8993
- name: Publish
90-
run: ./gradlew $PUBLISH_TASK
94+
run: ./gradlew $PUBLISH_TASK -PmavenCentralSnapshotArtifactSuffix=""
9195
- name: Upload Build Artifact
9296
uses: actions/upload-artifact@v4
9397
with:
@@ -110,3 +114,46 @@ jobs:
110114
fail_on_unmatched_files: true
111115
files: |
112116
build/**/*.jar
117+
118+
validate-package-contents:
119+
runs-on: ubuntu-latest
120+
environment: ${{ contains(github.ref, 'refs/tags/v') && 'maven_central_release' || 'maven_central_snapshot' }}
121+
defaults:
122+
run:
123+
working-directory: ./
124+
steps:
125+
- uses: actions/checkout@v4
126+
- name: Setup JDK
127+
uses: actions/setup-java@v4
128+
with:
129+
java-version: ${{ env.JAVA_VERSION }}
130+
distribution: ${{ env.JAVA_DISTRIBUTION}}
131+
cache: gradle
132+
- name: Download file
133+
run: .\scripts\decodeAndWrite.ps1 -encodedValue $env:ENCODED_VALUE -outputPath $env:OUTPUT_PATH
134+
shell: pwsh
135+
env:
136+
ENCODED_VALUE: ${{ secrets.LOCAL_PROPERTIES }}
137+
OUTPUT_PATH: 'local.properties'
138+
- name: Download file
139+
run: .\scripts\decodeAndWrite.ps1 -encodedValue $env:ENCODED_VALUE -outputPath $env:OUTPUT_PATH
140+
shell: pwsh
141+
env:
142+
ENCODED_VALUE: ${{ secrets.SECRING_GPG }}
143+
OUTPUT_PATH: '.\secring.gpg'
144+
- name: Publish to local Maven cache for validation
145+
run: ./gradlew --no-daemon publishToMavenLocal
146+
- name: Get current SNAPSHOT version
147+
shell: pwsh
148+
run: |
149+
$contents = Get-Content gradle.properties -Raw
150+
$major = $contents | Select-String -Pattern 'mavenMajorVersion\s+= ([0-9]+)' | ForEach-Object { $_.Matches.Groups[1].Value }
151+
$minor = $contents | Select-String -Pattern 'mavenMinorVersion\s+= ([0-9]+)' | ForEach-Object { $_.Matches.Groups[1].Value }
152+
$patch = $contents | Select-String -Pattern 'mavenPatchVersion\s+= ([0-9]+)' | ForEach-Object { $_.Matches.Groups[1].Value }
153+
$version = "$major.$minor.$patch-SNAPSHOT"
154+
echo "Current version is $version"
155+
echo "PACKAGE_VERSION=$version" >> $Env:GITHUB_ENV
156+
- name: Inspect contents of local Maven cache
157+
shell: pwsh
158+
run: |
159+
.\scripts\validatePackageContents.ps1 -ArtifactId msgraph-beta-sdk-java -Version $env:PACKAGE_VERSION

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ hs_err_pid*
3333
/target/
3434
local.properties
3535
.idea
36+
*.gpg
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Checks that expected files are present & have contents after the publish process to the local cache
2+
param(
3+
[Parameter(Mandatory=$true)][string] $ArtifactId,
4+
[Parameter(Mandatory=$true)][string] $Version,
5+
[Parameter()][string] $GroupId = "com.microsoft.graph",
6+
[Parameter()][string] $MavenLocalCachePath = "~" + [System.IO.Path]::DirectorySeparatorChar + ".m2" + [System.IO.Path]::DirectorySeparatorChar + "repository"
7+
)
8+
9+
$groupIdPath = $GroupId -replace "\.", [System.IO.Path]::DirectorySeparatorChar
10+
$packagePath = Join-Path -Path $groupIdPath -ChildPath $ArtifactId
11+
$packageFullPath = Join-Path -Path $MavenLocalCachePath -ChildPath $packagePath -AdditionalChildPath $Version
12+
13+
Write-Output "---------------------------------------------------"
14+
Write-Output "Validating package contents at $packageFullPath"
15+
16+
if(-not (Test-Path -Path $packageFullPath)) {
17+
Write-Output "Package not found in local cache."
18+
exit 1
19+
}
20+
21+
Write-Output "Package exists in local cache."
22+
23+
$expectedFiles = @(
24+
"-javadoc.jar",
25+
"-javadoc.jar.asc",
26+
"-sources.jar",
27+
"-sources.jar.asc",
28+
".module",
29+
".module.asc",
30+
".pom",
31+
".pom.asc",
32+
".jar",
33+
".jar.asc"
34+
)
35+
36+
foreach($file in $expectedFiles) {
37+
$file = $ArtifactId + "-" + $Version + $file
38+
$filePath = Join-Path -Path $packageFullPath -ChildPath $file
39+
if(-not (Test-Path -Path $filePath)) {
40+
Write-Output "Expected file $file not found in package."
41+
exit 1
42+
}
43+
$fileSize = (Get-Item -Path $filePath).length
44+
if($fileSize -eq 0) {
45+
Write-Output "File $file is empty."
46+
exit 1
47+
}
48+
}
49+
50+
$mavenMetadataFiles = Get-ChildItem -Path $packageFullPath -Filter "maven-metadata*.xml"
51+
if($mavenMetadataFiles.Count -eq 0) {
52+
Write-Output "No maven-metadata*.xml files found in package."
53+
exit 1
54+
}
55+
56+
Write-Output "Package $ArtifactId is valid."
57+
Write-Output "---------------------------------------------------"
58+
exit 0

gradle.properties

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -39,62 +39,3 @@ mavenArtifactSuffix =
3939
#enable mavenCentralPublishingEnabled to publish to maven central
4040
mavenCentralSnapshotArtifactSuffix = -SNAPSHOT
4141
mavenCentralPublishingEnabled=true
42-
43-
44-
45-
46-
47-
48-
49-
50-
51-
52-
53-
54-
55-
56-
57-
58-
59-
60-
61-
62-
63-
64-
65-
66-
67-
68-
69-
70-
71-
72-
73-
74-
75-
76-
77-
78-
79-
80-
81-
82-
83-
84-
85-
86-
87-
88-
89-
90-
91-
92-
93-
94-
95-
96-
97-
98-
99-
100-

0 commit comments

Comments
 (0)