Maven Publish Release #7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Maven Publish Release | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| javaVersion: | |
| description: "Java version to use" | |
| default: "21" | |
| type: string | |
| mavenProperties: | |
| description: "Maven properties to use" | |
| default: "-DskipGithub=true" | |
| type: string | |
| mavenTasks: | |
| description: "Maven tasks to use" | |
| default: "clean install deploy" | |
| type: string | |
| branch: | |
| description: "Branch to publish to" | |
| default: "master" | |
| type: string | |
| permissions: | |
| contents: write | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| if: github.actor == 'agaffney' || github.actor == 'verbotenj' || github.actor == 'wolf31o2' | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Set up JDK ${{ inputs.javaVersion }} | |
| uses: actions/setup-java@v5 | |
| with: | |
| java-version: "${{ inputs.javaVersion }}" | |
| distribution: "temurin" | |
| - name: Set up Maven | |
| uses: hb0730/maven-action@v1.0.2 | |
| with: | |
| maven-version: 3.8.2 | |
| - name: Create Maven settings.xml | |
| run: | | |
| cat << 'EOF' > $HOME/.m2/settings.xml | |
| <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" | |
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
| xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 | |
| https://maven.apache.org/xsd/settings-1.0.0.xsd"> | |
| <servers> | |
| <server> | |
| <id>s3.applause-public-repo</id> | |
| <username>${{ secrets.REPO_PUBLISH_AWS_ACCESS_KEY_ID }}</username> | |
| <password>${{ secrets.REPO_PUBLISH_AWS_SECRET_ACCESS_KEY }}</password> | |
| </server> | |
| <server> | |
| <id>s3.applause-public-snapshots</id> | |
| <username>${{ secrets.REPO_PUBLISH_AWS_ACCESS_KEY_ID }}</username> | |
| <password>${{ secrets.REPO_PUBLISH_AWS_SECRET_ACCESS_KEY }}</password> | |
| </server> | |
| </servers> | |
| </settings> | |
| EOF | |
| - name: Publish | |
| run: | | |
| # Parse our version using build-helper and versions to strip SNAPSHOT | |
| mvn build-helper:parse-version versions:set -DgenerateBackupPoms=false -DnewVersion="\${parsedVersion.majorVersion}.\${parsedVersion.minorVersion}.\${parsedVersion.incrementalVersion}" | |
| # Write the current version | |
| mvn help:evaluate -q -Dexpression=project.version -DforceStdout=true | tail -n 1 | tee VERSION | |
| mvn ${{ inputs.mavenProperties }} ${{ inputs.mavenTasks }} | |
| VERSION="$(cat VERSION)" | |
| # Remove the org from the repo name | |
| GITHUB_REPO_NAME="${GITHUB_REPOSITORY#*/}" | |
| git config --global user.name "github-actions[bot]" | |
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
| git config --global --add safe.directory "$(pwd -P)" | |
| git commit -am "GHA: release version ${VERSION}" | |
| git tag v${VERSION} -am "GHA: publish public-$GITHUB_REPO_NAME v${VERSION}" | |
| git log -1 | |
| git push origin v${VERSION} | |
| git push origin HEAD:${{ inputs.branch }} | |
| # Increment incremental version and set SNAPSHOT | |
| mvn build-helper:parse-version versions:set -DgenerateBackupPoms=false -DnewVersion="\${parsedVersion.majorVersion}.\${parsedVersion.minorVersion}.\${parsedVersion.nextIncrementalVersion}-SNAPSHOT" | |
| # Write the SNAPSHOT version to VERSION | |
| mvn help:evaluate -q -Dexpression=project.version -DforceStdout=true | tail -n 1 | tee VERSION | |
| # Looks good! Now, for the git-fu for our SNAPSHOT version | |
| VERSION="$(cat VERSION)" | |
| git commit -am "GHA: SNAPSHOT version ${VERSION}" | |
| git diff HEAD^ HEAD | |
| git push origin HEAD:${{ inputs.branch }} |