|
| 1 | +name: Auto Release on Version Change |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ master ] |
| 6 | + paths: |
| 7 | + - 'build.gradle' |
| 8 | + |
| 9 | +jobs: |
| 10 | + check-version: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + outputs: |
| 13 | + version: ${{ steps.get-version.outputs.version }} |
| 14 | + version-changed: ${{ steps.check-tag.outputs.changed }} |
| 15 | + steps: |
| 16 | + - uses: actions/checkout@v3 |
| 17 | + with: |
| 18 | + fetch-depth: 0 |
| 19 | + |
| 20 | + - name: Extract version from build.gradle |
| 21 | + id: get-version |
| 22 | + run: | |
| 23 | + VERSION=$(grep "^version " build.gradle | sed "s/version '\(.*\)'/\1/") |
| 24 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 25 | + echo "Detected version: $VERSION" |
| 26 | +
|
| 27 | + - name: Check if tag exists |
| 28 | + id: check-tag |
| 29 | + run: | |
| 30 | + VERSION=${{ steps.get-version.outputs.version }} |
| 31 | + if git rev-parse "refs/tags/$VERSION" >/dev/null 2>&1; then |
| 32 | + echo "Tag $VERSION already exists" |
| 33 | + echo "changed=false" >> $GITHUB_OUTPUT |
| 34 | + else |
| 35 | + echo "Tag $VERSION does not exist - new version detected" |
| 36 | + echo "changed=true" >> $GITHUB_OUTPUT |
| 37 | + fi |
| 38 | +
|
| 39 | + release: |
| 40 | + needs: check-version |
| 41 | + if: needs.check-version.outputs.version-changed == 'true' |
| 42 | + runs-on: ubuntu-latest |
| 43 | + permissions: |
| 44 | + contents: write |
| 45 | + |
| 46 | + steps: |
| 47 | + - uses: actions/checkout@v3 |
| 48 | + with: |
| 49 | + fetch-depth: 0 |
| 50 | + |
| 51 | + - name: Set up JDK 16 |
| 52 | + uses: actions/setup-java@v3 |
| 53 | + with: |
| 54 | + java-version: '16' |
| 55 | + distribution: 'temurin' |
| 56 | + |
| 57 | + - name: Grant execute permission for gradlew |
| 58 | + run: chmod +x gradlew |
| 59 | + |
| 60 | + - name: Build with Gradle |
| 61 | + run: ./gradlew build |
| 62 | + |
| 63 | + - name: Extract release notes |
| 64 | + id: release-notes |
| 65 | + run: | |
| 66 | + VERSION=${{ needs.check-version.outputs.version }} |
| 67 | + |
| 68 | + # Get the commit message of the latest commit |
| 69 | + COMMIT_MSG=$(git log -1 --pretty=%B) |
| 70 | + |
| 71 | + # Create release notes |
| 72 | + echo "release_notes<<EOF" >> $GITHUB_OUTPUT |
| 73 | + echo "$COMMIT_MSG" >> $GITHUB_OUTPUT |
| 74 | + echo "EOF" >> $GITHUB_OUTPUT |
| 75 | +
|
| 76 | + - name: Create Release |
| 77 | + uses: softprops/action-gh-release@v1 |
| 78 | + with: |
| 79 | + tag_name: ${{ needs.check-version.outputs.version }} |
| 80 | + name: ${{ needs.check-version.outputs.version }} |
| 81 | + body: ${{ steps.release-notes.outputs.release_notes }} |
| 82 | + draft: false |
| 83 | + prerelease: false |
| 84 | + files: | |
| 85 | + build/libs/java-spotify-api-${{ needs.check-version.outputs.version }}.jar |
| 86 | + build/libs/java-spotify-api-${{ needs.check-version.outputs.version }}-all.jar |
| 87 | + build/libs/java-spotify-api-${{ needs.check-version.outputs.version }}-javadoc.jar |
| 88 | + build/libs/java-spotify-api-${{ needs.check-version.outputs.version }}-sources.jar |
| 89 | + env: |
| 90 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 91 | + |
0 commit comments