Release and Publish #3
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
| # Creates GitHub releases and publishes to GitHub Packages | |
| name: Release and Publish | |
| permissions: | |
| contents: write | |
| packages: write | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Version to release' | |
| required: true | |
| type: string | |
| jobs: | |
| build: | |
| name: Build Release | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '21' | |
| distribution: 'temurin' | |
| cache: gradle | |
| - name: Grant execute permission for gradlew | |
| run: chmod +x gradlew | |
| - name: Build with Gradle | |
| run: ./gradlew build | |
| - name: Determine version | |
| id: determine-version | |
| run: | | |
| if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then | |
| echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV | |
| else | |
| TAG=${GITHUB_REF#refs/tags/v} | |
| echo "VERSION=$TAG" >> $GITHUB_ENV | |
| fi | |
| echo "VERSION=${{ env.VERSION }}" | |
| - name: Generate Changelog | |
| id: changelog | |
| run: | | |
| PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "") | |
| if [ -z "$PREVIOUS_TAG" ]; then | |
| echo "## π Initial Release v${{ env.VERSION }}" > changelog.md | |
| echo "" >> changelog.md | |
| echo "This is the first official release." >> changelog.md | |
| else | |
| echo "## π Release v${{ env.VERSION }}" > changelog.md | |
| echo "" >> changelog.md | |
| echo "### Changes since $PREVIOUS_TAG:" >> changelog.md | |
| echo "" >> changelog.md | |
| git log --pretty=format:"* %s (%h)" $PREVIOUS_TAG..HEAD | grep -v "Merge" >> changelog.md | |
| fi | |
| cat changelog.md | |
| CHANGELOG=$(cat changelog.md) | |
| echo "changelog<<EOF" >> $GITHUB_OUTPUT | |
| echo "$CHANGELOG" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| - name: Create Release | |
| id: create_release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: v${{ env.VERSION }} | |
| name: Release v${{ env.VERSION }} | |
| body: ${{ steps.changelog.outputs.changelog }} | |
| draft: false | |
| prerelease: false | |
| files: | | |
| build/libs/*.jar | |
| LICENSE | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Publish to GitHub Packages | |
| uses: gradle/gradle-build-action@v2 | |
| with: | |
| arguments: publish | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| VERSION: ${{ env.VERSION }} |