From fb13cf3765a1e63a61fea90b7e5b381cc0cecd05 Mon Sep 17 00:00:00 2001 From: Oliver Bertuch Date: Fri, 18 Oct 2024 16:03:02 +0200 Subject: [PATCH] ci: modernize the release process - Add manual workflow trigger for releases - Switch to Temurin - Determine Java version from POM instead of hardcoding --- .github/workflows/maven-release-manual.yml | 53 ++++++++++++++ .github/workflows/maven-release.yml | 85 ++++++++++++---------- 2 files changed, 99 insertions(+), 39 deletions(-) create mode 100644 .github/workflows/maven-release-manual.yml diff --git a/.github/workflows/maven-release-manual.yml b/.github/workflows/maven-release-manual.yml new file mode 100644 index 00000000..a4200685 --- /dev/null +++ b/.github/workflows/maven-release-manual.yml @@ -0,0 +1,53 @@ +name: Trigger release to Maven Central Repository +on: + workflow_dispatch: + inputs: + version: + description: "The version to set for this release" + required: true + type: string + +jobs: + trigger: + runs-on: ubuntu-latest + permissions: + # We need write permission so we can push the next snapshot version + contents: write + steps: + - uses: actions/checkout@v4 + - run: | + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + # Alternative command if we just inherit the jdk.version from the parent (grep is faster): + # $(mvn help:evaluate -Dexpression=jdk.version -q -DforceStdout) + - name: Determine Java version from POM + run: | + echo "JAVA_VERSION=$(grep '' pom.xml | cut -f2 -d'>' | cut -f1 -d'<')" >> ${GITHUB_ENV} + + - name: Set up JDK ${{ env.JAVA_VERSION }} + uses: actions/setup-java@v4 + with: + java-version: ${{ env.JAVA_VERSION }} + distribution: 'temurin' + cache: 'maven' + + - name: Update version in pom.xml and tag + run: | + mvn -B versions:set -DnewVersion="${{ inputs.version }}" -DgenerateBackupPoms=false + git add pom.xml + git commit -m "[github-action] Release version ${{ inputs.version }}" + git tag "${{ inputs.version }}" + - name: Increment to next version, commit and push + run: | + mvn -B versions:set -DnextSnapshot -DnextSnapshotIndexToIncrement=2 -DgenerateBackupPoms=false + git add pom.xml + git commit -m "[github-action] Increment version after release of ${{ inputs.version }}" + git push --tags origin main + + release: + name: Run release workflow + uses: ./.github/workflows/maven-release.yml + needs: [trigger] + secrets: inherit + with: + version: "${{ inputs.version }}" diff --git a/.github/workflows/maven-release.yml b/.github/workflows/maven-release.yml index 8f93a786..108a8082 100644 --- a/.github/workflows/maven-release.yml +++ b/.github/workflows/maven-release.yml @@ -1,44 +1,51 @@ name: Release to Maven Central Repository on: - push: - tags: - - '*' + push: + tags: + - '*' + workflow_call: + inputs: + version: + type: string + required: true + jobs: - publish: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Set up Java - uses: actions/setup-java@v4 - with: - java-version: '17' - distribution: 'adopt' - - name: Cache Maven packages - uses: actions/cache@v4 - with: - path: ~/.m2 - key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} - restore-keys: ${{ runner.os }}-m2 + publish: + runs-on: ubuntu-latest + steps: + - if: ${{ github.event_name == 'push' }} + uses: actions/checkout@v4 + - if: ${{ inputs.version }} + uses: actions/checkout@v4 + with: + ref: "${{ inputs.version }}" + # Alternative command if we just inherit the jdk.version from the parent (grep is faster): + # $(mvn help:evaluate -Dexpression=jdk.version -q -DforceStdout) + - name: Determine Java version from POM + run: | + echo "JAVA_VERSION=$(grep '' pom.xml | cut -f2 -d'>' | cut -f1 -d'<')" >> ${GITHUB_ENV} - - name: Build, test, verify - run: mvn -B verify - - name: Check POM metadata for release - run: mvn pomchecker:check-maven-central + - name: Set up JDK ${{ env.JAVA_VERSION }} + uses: actions/setup-java@v4 + with: + java-version: ${{ env.JAVA_VERSION }} + distribution: 'temurin' + cache: 'maven' - # Running setup-java again overwrites the settings.xml - IT'S MANDATORY TO DO THIS SECOND SETUP!!! - - name: Set up Maven Central Repository - uses: actions/setup-java@v4 - with: - java-version: '17' - distribution: 'adopt' - server-id: ossrh - server-username: MAVEN_USERNAME - server-password: MAVEN_PASSWORD - gpg-private-key: ${{ secrets.DATAVERSEBOT_GPG_KEY }} - gpg-passphrase: MAVEN_GPG_PASSPHRASE - - name: Sign + Publish release - run: mvn -Prelease deploy -pl '!report,!xoai-data-provider-tck' -DskipAnalysis -DskipUT -DskipIT - env: - MAVEN_USERNAME: ${{ secrets.DATAVERSEBOT_SONATYPE_USERNAME }} - MAVEN_PASSWORD: ${{ secrets.DATAVERSEBOT_SONATYPE_TOKEN }} - MAVEN_GPG_PASSPHRASE: ${{ secrets.DATAVERSEBOT_GPG_PASSWORD }} + # Running setup-java again overwrites the settings.xml - IT'S MANDATORY TO DO THIS SECOND SETUP!!! + - name: Set up Maven Central Repository + uses: actions/setup-java@v4 + with: + java-version: ${{ env.JAVA_VERSION }} + distribution: 'temurin' + server-id: ossrh + server-username: MAVEN_USERNAME + server-password: MAVEN_PASSWORD + gpg-private-key: ${{ secrets.DATAVERSEBOT_GPG_KEY }} + gpg-passphrase: MAVEN_GPG_PASSPHRASE + - name: Sign + Publish release + run: mvn -Prelease deploy -pl '!report,!xoai-data-provider-tck' -DskipAnalysis -DskipUT -DskipIT + env: + MAVEN_USERNAME: ${{ secrets.DATAVERSEBOT_SONATYPE_USERNAME }} + MAVEN_PASSWORD: ${{ secrets.DATAVERSEBOT_SONATYPE_TOKEN }} + MAVEN_GPG_PASSPHRASE: ${{ secrets.DATAVERSEBOT_GPG_PASSWORD }}