chore: create release gh action #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Semantic Release | |
| on: | |
| push: | |
| branches: | |
| - master | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| pull-requests: read | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ github.token }} | |
| - name: Set up JDK | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '8' | |
| distribution: 'temurin' | |
| - name: Extract version from pom.xml | |
| id: get_version | |
| run: | | |
| VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "tag=v$VERSION" >> $GITHUB_OUTPUT | |
| echo "Extracted version: $VERSION" | |
| - name: Check if tag exists | |
| id: check_tag | |
| run: | | |
| TAG="${{ steps.get_version.outputs.tag }}" | |
| if git rev-parse "$TAG" >/dev/null 2>&1; then | |
| echo "exists=true" >> $GITHUB_OUTPUT | |
| echo "Tag $TAG already exists, skipping release" | |
| else | |
| echo "exists=false" >> $GITHUB_OUTPUT | |
| echo "Tag $TAG does not exist, proceeding with release" | |
| fi | |
| - name: Generate release notes | |
| id: release_notes | |
| if: steps.check_tag.outputs.exists == 'false' | |
| run: | | |
| TAG="${{ steps.get_version.outputs.tag }}" | |
| PREVIOUS_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") | |
| if [ -z "$PREVIOUS_TAG" ]; then | |
| # First release - get all commits | |
| RELEASE_NOTES=$(git log --pretty=format:"- %s (%h)" --no-merges) | |
| else | |
| # Get commits since last tag | |
| RELEASE_NOTES=$(git log ${PREVIOUS_TAG}..HEAD --pretty=format:"- %s (%h)" --no-merges) | |
| fi | |
| # Create release notes with header | |
| { | |
| echo "## Release ${{ steps.get_version.outputs.version }}" | |
| echo "" | |
| echo "### Changes" | |
| echo "" | |
| echo "$RELEASE_NOTES" | |
| } > release_notes.txt | |
| # Output for GitHub release | |
| { | |
| echo "notes<<EOF" | |
| cat release_notes.txt | |
| echo "EOF" | |
| } >> $GITHUB_OUTPUT | |
| - name: Create Git tag | |
| if: steps.check_tag.outputs.exists == 'false' | |
| run: | | |
| TAG="${{ steps.get_version.outputs.tag }}" | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git tag -a "$TAG" -m "Release ${{ steps.get_version.outputs.version }}" | |
| git push origin "$TAG" | |
| - name: Create GitHub Release | |
| if: steps.check_tag.outputs.exists == 'false' | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: ${{ steps.get_version.outputs.tag }} | |
| name: Release ${{ steps.get_version.outputs.version }} | |
| body: ${{ steps.release_notes.outputs.notes }} | |
| draft: false | |
| prerelease: false | |