Skip to content

Commit

Permalink
Merge pull request #1445 from microsoft/feat/automate-ossrh-release
Browse files Browse the repository at this point in the history
Automate releases from OSSRH to Maven Central
  • Loading branch information
Ndiritu authored Aug 7, 2024
2 parents 7b200da + 0fe8547 commit 79a6eda
Show file tree
Hide file tree
Showing 13 changed files with 150 additions and 266 deletions.
2 changes: 2 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ updates:
- "/components/serialization/multipart"
- "/components/authentication/azure"
- "/components/http/okHttp"
- "/components/bundle"
schedule:
interval: daily
time: "09:00" # 9am UTC
Expand All @@ -23,6 +24,7 @@ updates:
- "/components/serialization/multipart/android"
- "/components/authentication/azure/android"
- "/components/http/okHttp/android"
- "/components/bundle/android"
schedule:
interval: daily
time: "10:00" # 10am UTC. Checked after the core modules to prevent duplicate PRs updating dependencies.gradle files
Expand Down
93 changes: 63 additions & 30 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,22 @@ permissions:
contents: write

env:
PREVIEW_TASK: publishMavenPublicationToSonatypeSnapshotRepository
PUBLISH_TASK: publishMavenPublicationToSonatypeRepository
PREVIEW_TASK: publishToSonatype
PUBLISH_TASK: publishToSonatype closeSonatypeStagingRepository

jobs:
release-to-maven-central-snapshot:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
environment: maven_central_snapshot
defaults:
run:
working-directory: ./
steps:
- uses: actions/checkout@v4
- name: Setup JDK
uses: actions/setup-java@v4
with:
with:
java-version: 17
distribution: 'temurin'
cache: gradle
Expand All @@ -31,17 +34,15 @@ jobs:
- name: Download file
run: .\scripts\decodeAndWrite.ps1 -encodedValue $env:ENCODED_VALUE -outputPath $env:OUTPUT_PATH
shell: pwsh
env:
env:
ENCODED_VALUE: ${{ secrets.LOCAL_PROPERTIES }}
OUTPUT_PATH: 'local.properties'
working-directory: ./
- name: Download file
run: .\scripts\decodeAndWrite.ps1 -encodedValue $env:ENCODED_VALUE -outputPath $env:OUTPUT_PATH
shell: pwsh
env:
env:
ENCODED_VALUE: ${{ secrets.SECRING_GPG }}
OUTPUT_PATH: 'secring.gpg'
working-directory: ./
- name: Copy secring
run: |
Copy-Item secring.gpg components/abstractions/ -Verbose
Expand All @@ -53,22 +54,45 @@ jobs:
Copy-Item secring.gpg components/http/okHttp/ -Verbose
Copy-Item secring.gpg components/bundle/ -Verbose
shell: pwsh
working-directory: ./
- name: Build with Gradle
run: ./gradlew --no-daemon build
working-directory: ./
- name: Publish Preview
- name: Publish to local Maven cache
run: ./gradlew --no-daemon publishToMavenLocal
- name: Get current SNAPSHOT version
shell: pwsh
run: |
$contents = Get-Content gradle.properties -Raw
$major = $contents | Select-String -Pattern 'mavenMajorVersion = ([0-9]+)' | ForEach-Object { $_.Matches.Groups[1].Value }
$minor = $contents | Select-String -Pattern 'mavenMinorVersion = ([0-9]+)' | ForEach-Object { $_.Matches.Groups[1].Value }
$patch = $contents | Select-String -Pattern 'mavenPatchVersion = ([0-9]+)' | ForEach-Object { $_.Matches.Groups[1].Value }
$version = "$major.$minor.$patch-SNAPSHOT"
echo "Current version is $version"
echo "PACKAGE_VERSION=$version" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
- name: Inspect contents of local Maven cache
shell: pwsh
run: |
.\scripts\ValidatePackageContents.ps1 -ArtifactId microsoft-kiota-abstractions -Version $PACKAGE_VERSION
.\scripts\ValidatePackageContents.ps1 -ArtifactId microsoft-kiota-authentication-azure -Version $PACKAGE_VERSION
.\scripts\ValidatePackageContents.ps1 -ArtifactId microsoft-kiota-http-okHttp -Version $PACKAGE_VERSION
.\scripts\ValidatePackageContents.ps1 -ArtifactId microsoft-kiota-serialization-form -Version $PACKAGE_VERSION
.\scripts\ValidatePackageContents.ps1 -ArtifactId microsoft-kiota-serialization-json -Version $PACKAGE_VERSION
.\scripts\ValidatePackageContents.ps1 -ArtifactId microsoft-kiota-serialization-text -Version $PACKAGE_VERSION
.\scripts\ValidatePackageContents.ps1 -ArtifactId microsoft-kiota-serialization-multipart -Version $PACKAGE_VERSION
- name: Publish to Snapshot Repository
run: ./gradlew --no-daemon $PREVIEW_TASK
working-directory: ./


release-to-maven-central:
if: contains(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
environment: maven_central
defaults:
run:
working-directory: ./
steps:
- uses: actions/checkout@v4
- name: Setup JDK
uses: actions/setup-java@v4
with:
with:
java-version: 17
distribution: 'temurin'
cache: gradle
Expand All @@ -77,17 +101,15 @@ jobs:
- name: Download file
run: .\scripts\decodeAndWrite.ps1 -encodedValue $env:ENCODED_VALUE -outputPath $env:OUTPUT_PATH
shell: pwsh
env:
env:
ENCODED_VALUE: ${{ secrets.LOCAL_PROPERTIES }}
OUTPUT_PATH: 'local.properties'
working-directory: ./
OUTPUT_PATH: 'local.properties'
- name: Download file
run: .\scripts\decodeAndWrite.ps1 -encodedValue $env:ENCODED_VALUE -outputPath $env:OUTPUT_PATH
shell: pwsh
env:
env:
ENCODED_VALUE: ${{ secrets.SECRING_GPG }}
OUTPUT_PATH: 'secring.gpg'
working-directory: ./
- name: Copy secring
run: |
Copy-Item secring.gpg components/abstractions/ -Verbose
Expand All @@ -99,34 +121,45 @@ jobs:
Copy-Item secring.gpg components/http/okHttp/ -Verbose
Copy-Item secring.gpg components/bundle/ -Verbose
shell: pwsh
working-directory: ./
- name: Build with Gradle
run: ./gradlew --no-daemon build
working-directory: ./
- name: Publish to local Maven cache for validation
run: ./gradlew --no-daemon publishToMavenLocal
- name: Get current SNAPSHOT version
shell: pwsh
run: |
$contents = Get-Content gradle.properties -Raw
$major = $contents | Select-String -Pattern 'mavenMajorVersion = ([0-9]+)' | ForEach-Object { $_.Matches.Groups[1].Value }
$minor = $contents | Select-String -Pattern 'mavenMinorVersion = ([0-9]+)' | ForEach-Object { $_.Matches.Groups[1].Value }
$patch = $contents | Select-String -Pattern 'mavenPatchVersion = ([0-9]+)' | ForEach-Object { $_.Matches.Groups[1].Value }
$version = "$major.$minor.$patch-SNAPSHOT"
echo "Current version is $version"
echo "PACKAGE_VERSION=$version" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
- name: Inspect contents of local Maven cache
shell: pwsh
run: |
.\scripts\ValidatePackageContents.ps1 -ArtifactId microsoft-kiota-abstractions -Version $PACKAGE_VERSION
.\scripts\ValidatePackageContents.ps1 -ArtifactId microsoft-kiota-authentication-azure -Version $PACKAGE_VERSION
.\scripts\ValidatePackageContents.ps1 -ArtifactId microsoft-kiota-http-okHttp -Version $PACKAGE_VERSION
.\scripts\ValidatePackageContents.ps1 -ArtifactId microsoft-kiota-serialization-form -Version $PACKAGE_VERSION
.\scripts\ValidatePackageContents.ps1 -ArtifactId microsoft-kiota-serialization-json -Version $PACKAGE_VERSION
.\scripts\ValidatePackageContents.ps1 -ArtifactId microsoft-kiota-serialization-text -Version $PACKAGE_VERSION
.\scripts\ValidatePackageContents.ps1 -ArtifactId microsoft-kiota-serialization-multipart -Version $PACKAGE_VERSION
.\scripts\ValidatePackageContents.ps1 -ArtifactId microsoft-kiota-bundle -Version $PACKAGE_VERSION
- name: Publish Release abstractions #publishing all components at once often results in split staging repos which fails to release
run: ./gradlew --no-daemon :components:abstractions:$PUBLISH_TASK -PmavenCentralSnapshotArtifactSuffix=""
working-directory: ./
- name: Publish Release serialization form
run: ./gradlew --no-daemon :components:serialization:form:$PUBLISH_TASK -PmavenCentralSnapshotArtifactSuffix=""
working-directory: ./
- name: Publish Release serialization json
run: ./gradlew --no-daemon :components:serialization:json:$PUBLISH_TASK -PmavenCentralSnapshotArtifactSuffix=""
working-directory: ./
- name: Publish Release serialization text
run: ./gradlew --no-daemon :components:serialization:text:$PUBLISH_TASK -PmavenCentralSnapshotArtifactSuffix=""
working-directory: ./
- name: Publish Release serialization multipart
run: ./gradlew --no-daemon :components:serialization:multipart:$PUBLISH_TASK -PmavenCentralSnapshotArtifactSuffix=""
working-directory: ./
- name: Publish Release authentication azure
run: ./gradlew --no-daemon :components:authentication:azure:$PUBLISH_TASK -PmavenCentralSnapshotArtifactSuffix=""
working-directory: ./
- name: Publish Release okHttp
run: ./gradlew --no-daemon :components:http:okHttp:$PUBLISH_TASK -PmavenCentralSnapshotArtifactSuffix=""
working-directory: ./
- name: Publish Release bundle
run: ./gradlew --no-daemon :components:bundle:$PUBLISH_TASK -PmavenCentralSnapshotArtifactSuffix=""
working-directory: ./
- name: Release
uses: anton-yurchenko/[email protected]
env:
Expand Down
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -354,4 +354,8 @@ MigrationBackup/
.gradle

# build file
build/
build/

local.properties

*.gpg
23 changes: 20 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ plugins {
id "org.sonarqube" version "5.1.0.4882"
id 'com.github.spotbugs' version '6.0.19'
id "com.diffplug.spotless" version "6.25.0"
id 'io.github.gradle-nexus.publish-plugin' version '2.0.0'
}

sonar {
properties {
property "sonar.projectKey", "microsoft_kiota-java"
property "sonar.organization", "microsoft"
property "sonar.host.url", "https://sonarcloud.io"
property "sonar.coverage.jacoco.xmlReportPaths", "${project.projectDir}/components/**/reports/jacoco/test/jacocoTestReport.xml"
property "sonar.organization", "microsoft"
property "sonar.host.url", "https://sonarcloud.io"
property "sonar.coverage.jacoco.xmlReportPaths", "${project.projectDir}/components/**/reports/jacoco/test/jacocoTestReport.xml"
}
}

Expand All @@ -21,3 +22,19 @@ subprojects {
repositories {
mavenCentral()
}

nexusPublishing {
repositories {
sonatype {
if (project.rootProject.file('local.properties').exists()) {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
username = properties.getProperty('sonatypeUsername')
password = properties.getProperty('sonatypePassword')
}
}
}
}

group = project.property('mavenGroupId')
version = "${mavenMajorVersion}.${mavenMinorVersion}.${mavenPatchVersion}${mavenCentralSnapshotArtifactSuffix}"
29 changes: 0 additions & 29 deletions components/abstractions/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -102,35 +102,6 @@ publishing {
}
}
}
repositories {
maven {
url = 'https://oss.sonatype.org/content/repositories/snapshots'
name = 'sonatypeSnapshot'

credentials {
if (project.rootProject.file('local.properties').exists()) {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
username = properties.getProperty('sonatypeUsername')
password = properties.getProperty('sonatypePassword')
}
}
}

maven {
url = 'https://oss.sonatype.org/service/local/staging/deploy/maven2'
name = 'sonatype'

credentials {
if (project.rootProject.file('local.properties').exists()) {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
username = properties.getProperty('sonatypeUsername')
password = properties.getProperty('sonatypePassword')
}
}
}
}
}

signing {
Expand Down
29 changes: 0 additions & 29 deletions components/authentication/azure/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -102,35 +102,6 @@ publishing {
}
}
}
repositories {
maven {
url = 'https://oss.sonatype.org/content/repositories/snapshots'
name = 'sonatypeSnapshot'

credentials {
if (project.rootProject.file('local.properties').exists()) {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
username = properties.getProperty('sonatypeUsername')
password = properties.getProperty('sonatypePassword')
}
}
}

maven {
url = 'https://oss.sonatype.org/service/local/staging/deploy/maven2'
name = 'sonatype'

credentials {
if (project.rootProject.file('local.properties').exists()) {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
username = properties.getProperty('sonatypeUsername')
password = properties.getProperty('sonatypePassword')
}
}
}
}
}

signing {
Expand Down
29 changes: 0 additions & 29 deletions components/bundle/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -102,35 +102,6 @@ publishing {
}
}
}
repositories {
maven {
url = 'https://oss.sonatype.org/content/repositories/snapshots'
name = 'sonatypeSnapshot'

credentials {
if (project.rootProject.file('local.properties').exists()) {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
username = properties.getProperty('sonatypeUsername')
password = properties.getProperty('sonatypePassword')
}
}
}

maven {
url = 'https://oss.sonatype.org/service/local/staging/deploy/maven2'
name = 'sonatype'

credentials {
if (project.rootProject.file('local.properties').exists()) {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
username = properties.getProperty('sonatypeUsername')
password = properties.getProperty('sonatypePassword')
}
}
}
}
}

signing {
Expand Down
29 changes: 0 additions & 29 deletions components/http/okHttp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -102,35 +102,6 @@ publishing {
}
}
}
repositories {
maven {
url = 'https://oss.sonatype.org/content/repositories/snapshots'
name = 'sonatypeSnapshot'

credentials {
if (project.rootProject.file('local.properties').exists()) {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
username = properties.getProperty('sonatypeUsername')
password = properties.getProperty('sonatypePassword')
}
}
}

maven {
url = 'https://oss.sonatype.org/service/local/staging/deploy/maven2'
name = 'sonatype'

credentials {
if (project.rootProject.file('local.properties').exists()) {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
username = properties.getProperty('sonatypeUsername')
password = properties.getProperty('sonatypePassword')
}
}
}
}
}

signing {
Expand Down
Loading

0 comments on commit 79a6eda

Please sign in to comment.