|
| 1 | +name: Release |
| 2 | +run-name: Release ${{ inputs.release_version }} |
| 3 | + |
| 4 | +#Only one job at a time |
| 5 | +concurrency: release |
| 6 | + |
| 7 | +on: |
| 8 | + workflow_dispatch: |
| 9 | + inputs: |
| 10 | + release_version: |
| 11 | + description: 'Release version' |
| 12 | + required: true |
| 13 | + type: string |
| 14 | + |
| 15 | +jobs: |
| 16 | + release: |
| 17 | + name: Publish |
| 18 | + runs-on: ubuntu-latest |
| 19 | + permissions: |
| 20 | + contents: write |
| 21 | + pull-requests: write |
| 22 | + steps: |
| 23 | + # Check out current repository |
| 24 | + - name: Fetch Sources |
| 25 | + uses: actions/checkout@v4 |
| 26 | + |
| 27 | + # Set up Java environment for the next steps |
| 28 | + - name: Setup Java |
| 29 | + uses: actions/setup-java@v4 |
| 30 | + with: |
| 31 | + distribution: 'temurin' |
| 32 | + java-version: 17 |
| 33 | + cache: 'gradle' |
| 34 | + |
| 35 | + # Setup Gradle |
| 36 | + - name: Setup Gradle |
| 37 | + uses: gradle/actions/setup-gradle@v4 |
| 38 | + |
| 39 | + - name: Tag Release |
| 40 | + env: |
| 41 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 42 | + run: | |
| 43 | + git config user.email "[email protected]" |
| 44 | + git config user.name "GitHub Action" |
| 45 | + if git diff --quiet; then |
| 46 | + echo "No changes to commit." |
| 47 | + else |
| 48 | + git commit -sam "chore(skip-release): set version to ${{ inputs.release_version }}" |
| 49 | + fi |
| 50 | + git tag ${{ inputs.release_version }} |
| 51 | + git push origin ${{ inputs.release_version }} |
| 52 | +
|
| 53 | + - name: Set Release Version |
| 54 | + shell: bash |
| 55 | + run: | |
| 56 | + CURRENT_VERSION=$(grep "projectVersion=" gradle.properties | cut -d'=' -f2) |
| 57 | + NEW_VERSION=${{ inputs.release_version }} |
| 58 | + awk -v current="$CURRENT_VERSION" -v new="$NEW_VERSION" 'BEGIN {FS=OFS="="} $1 == "projectVersion" { $2 = new }1' gradle.properties > tmpfile && mv tmpfile gradle.properties |
| 59 | + echo "Release version: $NEW_VERSION" |
| 60 | + echo "PLUGIN_VERSION=${NEW_VERSION}" >> $GITHUB_ENV |
| 61 | +
|
| 62 | + # Publish the plugin to local release repo |
| 63 | + - name: Publish Library |
| 64 | + run: | |
| 65 | + ./gradlew publish |
| 66 | + echo "Published $PLUGIN_VERSION." |
| 67 | +
|
| 68 | + # Set next SNAPSHOT version |
| 69 | + - name: Increment Plugin Version |
| 70 | + env: |
| 71 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 72 | + run: | |
| 73 | + CURRENT_VERSION=$(grep "projectVersion=" gradle.properties | cut -d'=' -f2) |
| 74 | + IFS="-" read -ra VERSION_PARTS <<< "$CURRENT_VERSION" |
| 75 | + IFS="." read -ra VERSION_NUM <<< "${VERSION_PARTS[0]}" |
| 76 | + ((VERSION_NUM[2]+=1)) |
| 77 | + NEW_VERSION="${VERSION_NUM[0]}.${VERSION_NUM[1]}.${VERSION_NUM[2]}-SNAPSHOT" |
| 78 | + awk -v new_version="$NEW_VERSION" '/projectVersion=/{sub(/=.*/, "=" new_version)}1' gradle.properties > tmpfile && mv tmpfile gradle.properties |
| 79 | + echo "Set $NEW_VERSION in gradle.properties" |
| 80 | + git checkout -b $NEW_VERSION |
| 81 | + git commit -sam "chore(skip-release): set version to $NEW_VERSION" |
| 82 | + git push -u origin $NEW_VERSION |
| 83 | +
|
| 84 | + - name: Simple conventional changelog |
| 85 | + uses: redhat-developer/simple-conventional-changelog@0a6db1ac3910c2cf66f2e1a530951dba1ece8540 #0.0.12 |
| 86 | + id: changelog |
| 87 | + with: |
| 88 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 89 | + current-tag: ${{ inputs.release_version }} |
| 90 | + types-mapping: 'feat:Features,fix:Bug Fixes,docs:Documentation,refactor:Refactoring,build:Build,chore:Other' |
| 91 | + |
| 92 | + # Create a new GitHub release |
| 93 | + - name: Create GitHub Release |
| 94 | + env: |
| 95 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 96 | + run: | |
| 97 | + gh release create ${{ inputs.release_version }} \ |
| 98 | + --title "${{ inputs.release_version }}" \ |
| 99 | + --notes "$(cat << 'EOM' |
| 100 | + ${{ steps.changelog.outputs.changelog }} |
| 101 | + EOM |
| 102 | + )" |
| 103 | +
|
| 104 | + - name: Upload Release Asset |
| 105 | + env: |
| 106 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 107 | + run: gh release upload ${{ inputs.release_version }} ./build/libs/*.jar |
0 commit comments