Skip to content

Commit

Permalink
ci: modernize the release process
Browse files Browse the repository at this point in the history
- Add manual workflow trigger for releases
- Switch to Temurin
- Determine Java version from POM instead of hardcoding
  • Loading branch information
poikilotherm committed Oct 18, 2024
1 parent 0324546 commit 8dffbac
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 39 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/maven-release-manual.yml
Original file line number Diff line number Diff line change
@@ -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 '<jdk.version>' 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 **/pom.xml
git commit -m "[github-action] Release version ${{ inputs.version }}"
git tag "xoai-${{ inputs.version }}"
- name: Increment to next version, commit and push
run: |
mvn -B versions:set -DnextSnapshot -DnextSnapshotIndexToIncrement=2 -DgenerateBackupPoms=false
git add pom.xml **/pom.xml
git commit -m "[github-action] Increment version after release of ${{ inputs.version }}"
git push --tags origin branch-5.0
release:
name: Run release workflow
uses: ./.github/workflows/maven-release.yml
needs: [trigger]
secrets: inherit
with:
version: "xoai-${{ inputs.version }}"
85 changes: 46 additions & 39 deletions .github/workflows/maven-release.yml
Original file line number Diff line number Diff line change
@@ -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 '<jdk.version>' 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 }}

0 comments on commit 8dffbac

Please sign in to comment.