This repository was archived by the owner on Apr 18, 2026. It is now read-only.
Create release.yml #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: Build and Publish Release | |
| on: | |
| push: | |
| branches: | |
| - main # Change this to 'master' or another branch name as desired. | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '21' | |
| distribution: 'temurin' | |
| cache: maven | |
| - name: Build with Maven | |
| run: mvn clean package | |
| - name: Get version & release name | |
| id: version | |
| run: | | |
| # Extract the project version from your Maven POM. | |
| echo "version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_OUTPUT | |
| # Here we extract the project name as the release name. | |
| echo "releaseName=$(mvn help:evaluate -Dexpression=project.name -q -DforceStdout)" >> $GITHUB_OUTPUT | |
| - name: Print version & release name | |
| run: | | |
| echo "Version: ${{ steps.version.outputs.version }}" | |
| echo "Release Name: ${{ steps.version.outputs.releaseName }}" | |
| - name: Create an empty CHANGELOG.md if missing | |
| run: | | |
| if [ ! -f CHANGELOG.md ]; then | |
| touch CHANGELOG.md | |
| fi | |
| - name: Remove all lines after the 2nd title in CHANGELOG.md | |
| shell: pwsh | |
| run: | | |
| $changelogPath = "CHANGELOG.md" | |
| $content = Get-Content -Path $changelogPath | |
| $indices = ($content | ForEach-Object { $_ } | Select-String -Pattern "^#" | ForEach-Object { $_.LineNumber - 1 }) | |
| if ($indices.Count -ge 2) { | |
| $startIndex = $indices[0] | |
| $endIndex = $indices[1] | |
| $changes = $content[$startIndex..($endIndex - 1)] | |
| $changes = $changes | Where-Object { -not [string]::IsNullOrWhiteSpace($_) } | |
| $changes -join "`n" | Set-Content -Path $changelogPath | |
| Write-Output "Changelog updated" | |
| } else { | |
| Write-Output "Not as many lines as expected" | |
| } | |
| - name: Create Release | |
| id: createRelease | |
| uses: ncipollo/release-action@v1.14.0 | |
| with: | |
| allowUpdates: true | |
| updateOnlyUnreleased: true | |
| # Adjust the artifact path; Maven outputs your JAR into the target directory. | |
| artifacts: target/*.jar | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| tag: ${{ steps.version.outputs.version }} | |
| name: ${{ steps.version.outputs.releaseName }} | |
| bodyFile: CHANGELOG.md | |
| skipIfReleaseExists: true |