|
| 1 | +name: Semantic Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + |
| 8 | +jobs: |
| 9 | + release: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + permissions: |
| 12 | + contents: write |
| 13 | + pull-requests: read |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Checkout code |
| 17 | + uses: actions/checkout@v4 |
| 18 | + with: |
| 19 | + fetch-depth: 0 |
| 20 | + token: ${{ github.token }} |
| 21 | + |
| 22 | + - name: Set up JDK |
| 23 | + uses: actions/setup-java@v4 |
| 24 | + with: |
| 25 | + java-version: '8' |
| 26 | + distribution: 'temurin' |
| 27 | + |
| 28 | + - name: Extract version from pom.xml |
| 29 | + id: get_version |
| 30 | + run: | |
| 31 | + VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) |
| 32 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 33 | + echo "tag=v$VERSION" >> $GITHUB_OUTPUT |
| 34 | + echo "Extracted version: $VERSION" |
| 35 | +
|
| 36 | + - name: Check if tag exists |
| 37 | + id: check_tag |
| 38 | + run: | |
| 39 | + TAG="${{ steps.get_version.outputs.tag }}" |
| 40 | + if git rev-parse "$TAG" >/dev/null 2>&1; then |
| 41 | + echo "exists=true" >> $GITHUB_OUTPUT |
| 42 | + echo "Tag $TAG already exists, skipping release" |
| 43 | + else |
| 44 | + echo "exists=false" >> $GITHUB_OUTPUT |
| 45 | + echo "Tag $TAG does not exist, proceeding with release" |
| 46 | + fi |
| 47 | +
|
| 48 | + - name: Generate release notes |
| 49 | + id: release_notes |
| 50 | + if: steps.check_tag.outputs.exists == 'false' |
| 51 | + run: | |
| 52 | + TAG="${{ steps.get_version.outputs.tag }}" |
| 53 | + PREVIOUS_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") |
| 54 | + |
| 55 | + if [ -z "$PREVIOUS_TAG" ]; then |
| 56 | + # First release - get all commits |
| 57 | + RELEASE_NOTES=$(git log --pretty=format:"- %s (%h)" --no-merges) |
| 58 | + else |
| 59 | + # Get commits since last tag |
| 60 | + RELEASE_NOTES=$(git log ${PREVIOUS_TAG}..HEAD --pretty=format:"- %s (%h)" --no-merges) |
| 61 | + fi |
| 62 | + |
| 63 | + # Create release notes with header |
| 64 | + { |
| 65 | + echo "## Release ${{ steps.get_version.outputs.version }}" |
| 66 | + echo "" |
| 67 | + echo "### Changes" |
| 68 | + echo "" |
| 69 | + echo "$RELEASE_NOTES" |
| 70 | + } > release_notes.txt |
| 71 | + |
| 72 | + # Output for GitHub release |
| 73 | + { |
| 74 | + echo "notes<<EOF" |
| 75 | + cat release_notes.txt |
| 76 | + echo "EOF" |
| 77 | + } >> $GITHUB_OUTPUT |
| 78 | +
|
| 79 | + - name: Create Git tag |
| 80 | + if: steps.check_tag.outputs.exists == 'false' |
| 81 | + run: | |
| 82 | + TAG="${{ steps.get_version.outputs.tag }}" |
| 83 | + git config user.name "github-actions[bot]" |
| 84 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 85 | + git tag -a "$TAG" -m "Release ${{ steps.get_version.outputs.version }}" |
| 86 | + git push origin "$TAG" |
| 87 | +
|
| 88 | + - name: Create GitHub Release |
| 89 | + if: steps.check_tag.outputs.exists == 'false' |
| 90 | + uses: softprops/action-gh-release@v1 |
| 91 | + with: |
| 92 | + tag_name: ${{ steps.get_version.outputs.tag }} |
| 93 | + name: Release ${{ steps.get_version.outputs.version }} |
| 94 | + body: ${{ steps.release_notes.outputs.notes }} |
| 95 | + draft: false |
| 96 | + prerelease: false |
| 97 | + |
0 commit comments