|
| 1 | +# |
| 2 | +# Copyright 2026 Aiven Oy and project contributors |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, |
| 11 | +# software distributed under the License is distributed on an |
| 12 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 13 | +# KIND, either express or implied. See the License for the |
| 14 | +# specific language governing permissions and limitations |
| 15 | +# under the License. |
| 16 | +# |
| 17 | +# SPDX-License-Identifier: Apache-2.0 |
| 18 | + |
| 19 | + |
| 20 | +name: Create release |
| 21 | + |
| 22 | +on: |
| 23 | + workflow_dispatch: |
| 24 | + inputs: |
| 25 | + commit_hash: |
| 26 | + description: "Hash of 'Release version x.y.z' commit" |
| 27 | + required: true |
| 28 | + |
| 29 | +permissions: |
| 30 | + contents: write |
| 31 | + pull-requests: write |
| 32 | + issues: write |
| 33 | + |
| 34 | +jobs: |
| 35 | + build: |
| 36 | + name: Create Release |
| 37 | + runs-on: ubuntu-latest |
| 38 | + steps: |
| 39 | + - name: Checkout code |
| 40 | + uses: actions/checkout@v6 |
| 41 | + with: |
| 42 | + ref: ${{ github.event.inputs.commit_hash }} |
| 43 | + |
| 44 | + - name: Extract version info |
| 45 | + run: | |
| 46 | + export version=$(mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec); |
| 47 | + echo "version=${version}" >> $GITHUB_OUTPUT; |
| 48 | + echo "java_version=$(mvn -q -Dexec.executable=echo -Dexec.args='${jdk.version}' --non-recursive exec:exec)" >> $GITHUB_OUTPUT; |
| 49 | + export release_version=$(mvn -q -Dexec.executable=echo -Dexec.args='${latestRelease}' --non-recursive exec:exec); |
| 50 | + if [[ "${release_version}" == "${version}" ]] |
| 51 | + then |
| 52 | + echo "Creating draft release for ${release_version}" |
| 53 | + echo "release_version=${release_version}" >> $GITHUB_OUTPUT; |
| 54 | + else |
| 55 | + echo "Invalid 'latestRelease' in pom. ${release_version} != ${version}" |
| 56 | + exit 1 |
| 57 | + fi |
| 58 | + export commit_title=$(git log --pretty=format:%s -1) |
| 59 | + echo "Commit title: $commit_title" |
| 60 | + if [[ ${commit_title} == "Release version ${release_version}" ]]; then |
| 61 | + echo "release_hash=$(git rev-list -n 1 v${release_version})" >> $GITHUB_OUTPUT |
| 62 | + else |
| 63 | + echo "Invalid commit title: "${commit_title} |
| 64 | + exit 1 |
| 65 | + fi |
| 66 | +
|
| 67 | + if [[ `grep -c "^## " CHANGE_LOG.md` -gt 1 ]] |
| 68 | + then |
| 69 | + grep -B 999 -m2 "^## " CHANGE_LOG.md | head -n -1 > /tmp/release_body.txt |
| 70 | + else |
| 71 | + cp CHANGE_LOG.md /tmp/release_body.txt |
| 72 | + fi |
| 73 | + id: project |
| 74 | + |
| 75 | + - name: Create tag |
| 76 | + run: | |
| 77 | + git config --local user.name "GitHub Action" |
| 78 | + git config --local user.email "action@github.com" |
| 79 | + git tag -a "v${{ steps.project.outputs.version }}" -m "Release version ${{ steps.project.outputs.version }}" |
| 80 | + git push origin "v${{ steps.project.outputs.version }}" |
| 81 | +
|
| 82 | + - name: Set up JDK ${{ steps.project.outputs.java_version }} |
| 83 | + uses: actions/setup-java@v5 |
| 84 | + with: |
| 85 | + distribution: 'adopt' |
| 86 | + java-version: ${{ steps.project.outputs.java_version }} |
| 87 | + cache: 'maven' |
| 88 | + |
| 89 | + - name: Setup Maven settings.xml |
| 90 | + uses: s4u/maven-settings-action@v4.0.0 |
| 91 | + with: |
| 92 | + sonatypeSnapshots: false |
| 93 | + servers: | |
| 94 | + [{ |
| 95 | + "id": "central", |
| 96 | + "username": "${{ secrets.SONATYPE_ID }}", |
| 97 | + "password": "${{ secrets.SONATYPE_PASSWORD }}" |
| 98 | + }] |
| 99 | +
|
| 100 | + - name: Publish ${{ steps.project.outputs.release_version }} |
| 101 | + run: mvn -P sign -P publish -e -B -V -ntp -Dgpg.signer=bc deploy |
| 102 | + env: |
| 103 | + MAVEN_GPG_KEY: ${{ secrets.GPG_KEY }} |
| 104 | + MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSWORD }} |
| 105 | + |
| 106 | + - name: Create release draft |
| 107 | + id: create_release |
| 108 | + uses: softprops/action-gh-release@v2.6.0 |
| 109 | + env: |
| 110 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 111 | + with: |
| 112 | + tag_name: "v${{ steps.project.outputs.release_version }}" |
| 113 | + target_commitish: ${{ github.event.inputs.commit_hash }} |
| 114 | + draft: true |
| 115 | + prerelease: false |
| 116 | + files: target/*.jar |
| 117 | + body_path: /tmp/release_body.txt |
| 118 | + |
0 commit comments