From 4b199172a83453d29a5207ed3864f554dcbfb0aa Mon Sep 17 00:00:00 2001 From: Kerem Date: Fri, 12 Apr 2024 08:32:10 +0000 Subject: [PATCH] Java release pipeline (#23) --- .github/workflows/java-release.yml | 70 +++++++++++++++++++++++++++++ visual-java/scripts/bump_version.sh | 45 +++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 .github/workflows/java-release.yml create mode 100755 visual-java/scripts/bump_version.sh diff --git a/.github/workflows/java-release.yml b/.github/workflows/java-release.yml new file mode 100644 index 00000000..ea3e0239 --- /dev/null +++ b/.github/workflows/java-release.yml @@ -0,0 +1,70 @@ +name: Java (Release) + +on: + workflow_dispatch: + inputs: + releaseType: + description: 'Release type - major, minor or patch' + required: true + default: 'minor' + options: + - 'major' + - 'minor' + - 'patch' + +defaults: + run: + working-directory: visual-java + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Maven Central Repository + uses: actions/setup-java@v4 + with: + java-version: '11' + distribution: 'temurin' + server-id: ossrh + server-username: MVN_CENTRAL_USERNAME + server-password: MVN_CENTRAL_PASSWORD + + - name: upgrade & push version + id: upgrade + run: | + current_version=$(mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec) + new_version=$(./scripts/bump_version.sh -c $current_version -r ${{ github.event.inputs.releaseType }}) + mvn versions:set -DgenerateBackupPoms=false -DnewVersion=$new_version + tag_name="java-$new_version" + git add ./pom.xml + git commit -m "[release] $tag_name" + git tag $tag_name + git push + git push origin $tag_name + + echo "version=$new_version" >> "$GITHUB_OUTPUT" + echo "tag_name=$tag_name" >> "$GITHUB_OUTPUT" + + - name: Import GPG signing key + uses: crazy-max/ghaction-import-gpg@v6 + with: + gpg_private_key: ${{ secrets.MVN_CENTRAL_GPG_PRIVATE_KEY }} + passphrase: ${{ secrets.MVN_CENTRAL_GPG_PASSPHRASE }} + + - name: Release to Maven repo + run: | + mvn -P release -Dgpg.passphrase=${{ secrets.MVN_CENTRAL_GPG_PASSPHRASE }} \ + -Drevision=${{ steps.upgrade.outputs.version }} deploy + env: + MVN_CENTRAL_USERNAME: ${{ secrets.MVN_CENTRAL_USERNAME }} + MVN_CENTRAL_PASSWORD: ${{ secrets.MVN_CENTRAL_PASSWORD }} + + - name: Github Release + uses: softprops/action-gh-release@v2 + with: + fail_on_unmatched_files: true + tag_name: ${{ steps.upgrade.outputs.tag_name }} + files: visual-java/target/java-client-${{ steps.upgrade.outputs.version }}.jar + generate_release_notes: true diff --git a/visual-java/scripts/bump_version.sh b/visual-java/scripts/bump_version.sh new file mode 100755 index 00000000..4d8111f9 --- /dev/null +++ b/visual-java/scripts/bump_version.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +# Function to bump version based on release type +bump_version() { + local version=$1 + local release_type=$2 + + # Split the version into parts + IFS='.' read -r -a version_parts <<< "$version" + + # Increment the appropriate part based on release type + case "$release_type" in + "major") ((version_parts[0]++)); version_parts[1]=0; version_parts[2]=0;; + "minor") ((version_parts[1]++)); version_parts[2]=0;; + "patch") ((version_parts[2]++));; + *) echo "Invalid release type"; exit 1;; + esac + + # Join the parts back into a single version string + new_version="${version_parts[0]}.${version_parts[1]}.${version_parts[2]}" + echo "$new_version" +} + +# Main script starts here + +# Parse command line options +while getopts ":c:r:" opt; do + case $opt in + c) current_version="$OPTARG";; + r) release_type="$OPTARG";; + \?) echo "Invalid option: -$OPTARG" >&2; exit 1;; + :) echo "Option -$OPTARG requires an argument." >&2; exit 1;; + esac +done + +# Check if current_version and release_type are provided +if [ -z "$current_version" ] || [ -z "$release_type" ]; then + echo "Usage: $0 -c -r " + exit 1 +fi + +# Bump the version +new_version=$(bump_version "$current_version" "$release_type") + +echo "$new_version"