From b15252b29e86639109ed853dd60d1ee6428c203b Mon Sep 17 00:00:00 2001 From: Philip Gichuhi Date: Tue, 13 Aug 2024 17:14:13 +0300 Subject: [PATCH] Update release workflows --- .github/workflows/preview-and-release.yml | 61 ++++++++++++++++++++--- 1 file changed, 54 insertions(+), 7 deletions(-) diff --git a/.github/workflows/preview-and-release.yml b/.github/workflows/preview-and-release.yml index ea569ac9505..ea041e211a9 100644 --- a/.github/workflows/preview-and-release.yml +++ b/.github/workflows/preview-and-release.yml @@ -14,8 +14,10 @@ on: workflow_dispatch: env: - PREVIEW_TASK: publishSnapshotPublicationToSonatypeSnapshotRepository - PUBLISH_TASK: publishMavenCentralReleasePublicationToSonatypeRepository + PREVIEW_TASK: publishToSonatype + PUBLISH_TASK: publishToSonatype closeAndReleaseSonatypeStagingRepository + JAVA_VERSION: 21 + JAVA_DISTRIBUTION: 'temurin' permissions: contents: write @@ -26,13 +28,14 @@ jobs: environment: name: maven_central_snapshot runs-on: ubuntu-latest + needs: validate-package-contents steps: - uses: actions/checkout@v4 - name: Set up JDK uses: actions/setup-java@v4 with: - java-version: 21 - distribution: 'temurin' + java-version: ${{ env.JAVA_VERSION }} + distribution: ${{ env.JAVA_DISTRIBUTION}} cache: gradle - name: Easy detect-secrets uses: RobertFischer/detect-secrets-action@v2.0.0 @@ -58,13 +61,14 @@ jobs: environment: name: maven_central_release runs-on: ubuntu-latest + needs: validate-package-contents steps: - uses: actions/checkout@v4 - name: Set up JDK uses: actions/setup-java@v4 with: - java-version: 21 - distribution: 'temurin' + java-version: ${{ env.JAVA_VERSION }} + distribution: ${{ env.JAVA_DISTRIBUTION}} cache: gradle - name: Easy detect-secrets uses: RobertFischer/detect-secrets-action@v2.0.0 @@ -83,7 +87,7 @@ jobs: - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Publish - run: ./gradlew $PUBLISH_TASK + run: ./gradlew $PUBLISH_TASK -PmavenCentralSnapshotArtifactSuffix="" - name: Upload Build Artifact uses: actions/upload-artifact@v4 with: @@ -106,3 +110,46 @@ jobs: fail_on_unmatched_files: true files: | build/**/*.jar + + validate-package-contents: + runs-on: ubuntu-latest + environment: ${{ contains(github.ref, 'refs/tags/v') && 'maven_central_release' || 'maven_central_snapshot' }} + defaults: + run: + working-directory: ./ + steps: + - uses: actions/checkout@v4 + - name: Setup JDK + uses: actions/setup-java@v4 + with: + java-version: ${{ env.JAVA_VERSION }} + distribution: ${{ env.JAVA_DISTRIBUTION}} + cache: gradle + - name: Download file + run: .\scripts\decodeAndWrite.ps1 -encodedValue $env:ENCODED_VALUE -outputPath $env:OUTPUT_PATH + shell: pwsh + env: + ENCODED_VALUE: ${{ secrets.LOCAL_PROPERTIES }} + OUTPUT_PATH: 'local.properties' + - name: Download file + run: .\scripts\decodeAndWrite.ps1 -encodedValue $env:ENCODED_VALUE -outputPath $env:OUTPUT_PATH + shell: pwsh + env: + ENCODED_VALUE: ${{ secrets.SECRING_GPG }} + OUTPUT_PATH: '.\secring.gpg' + - 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\s+= ([0-9]+)' | ForEach-Object { $_.Matches.Groups[1].Value } + $minor = $contents | Select-String -Pattern 'mavenMinorVersion\s+= ([0-9]+)' | ForEach-Object { $_.Matches.Groups[1].Value } + $patch = $contents | Select-String -Pattern 'mavenPatchVersion\s+= ([0-9]+)' | ForEach-Object { $_.Matches.Groups[1].Value } + $version = "$major.$minor.$patch-SNAPSHOT" + echo "Current version is $version" + echo "PACKAGE_VERSION=$version" >> $Env:GITHUB_ENV + - name: Inspect contents of local Maven cache + shell: pwsh + run: | + .\scripts\validatePackageContents.ps1 -ArtifactId msgraph-sdk-java -Version $env:PACKAGE_VERSION