Skip to content
This repository was archived by the owner on Jan 3, 2026. It is now read-only.

Commit c09f377

Browse files
authored
Create release.yml
1 parent ec965ac commit c09f377

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

.github/workflows/release.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Build and Publish Release
2+
on:
3+
push:
4+
branches:
5+
- main # Change this to 'master' or another branch name as desired.
6+
7+
jobs:
8+
release:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: write
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Set up JDK 21
16+
uses: actions/setup-java@v4
17+
with:
18+
java-version: '21'
19+
distribution: 'temurin'
20+
cache: maven
21+
22+
- name: Build with Maven
23+
run: mvn clean package
24+
25+
- name: Get version & release name
26+
id: version
27+
run: |
28+
# Extract the project version from your Maven POM.
29+
echo "version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_OUTPUT
30+
# Here we extract the project name as the release name.
31+
echo "releaseName=$(mvn help:evaluate -Dexpression=project.name -q -DforceStdout)" >> $GITHUB_OUTPUT
32+
33+
- name: Print version & release name
34+
run: |
35+
echo "Version: ${{ steps.version.outputs.version }}"
36+
echo "Release Name: ${{ steps.version.outputs.releaseName }}"
37+
38+
- name: Create an empty CHANGELOG.md if missing
39+
run: |
40+
if [ ! -f CHANGELOG.md ]; then
41+
touch CHANGELOG.md
42+
fi
43+
44+
- name: Remove all lines after the 2nd title in CHANGELOG.md
45+
shell: pwsh
46+
run: |
47+
$changelogPath = "CHANGELOG.md"
48+
$content = Get-Content -Path $changelogPath
49+
$indices = ($content | ForEach-Object { $_ } | Select-String -Pattern "^#" | ForEach-Object { $_.LineNumber - 1 })
50+
51+
if ($indices.Count -ge 2) {
52+
$startIndex = $indices[0]
53+
$endIndex = $indices[1]
54+
55+
$changes = $content[$startIndex..($endIndex - 1)]
56+
$changes = $changes | Where-Object { -not [string]::IsNullOrWhiteSpace($_) }
57+
$changes -join "`n" | Set-Content -Path $changelogPath
58+
Write-Output "Changelog updated"
59+
} else {
60+
Write-Output "Not as many lines as expected"
61+
}
62+
63+
- name: Create Release
64+
id: createRelease
65+
uses: ncipollo/release-action@v1.14.0
66+
with:
67+
allowUpdates: true
68+
updateOnlyUnreleased: true
69+
# Adjust the artifact path; Maven outputs your JAR into the target directory.
70+
artifacts: target/*.jar
71+
token: ${{ secrets.GITHUB_TOKEN }}
72+
tag: ${{ steps.version.outputs.version }}
73+
name: ${{ steps.version.outputs.releaseName }}
74+
bodyFile: CHANGELOG.md
75+
skipIfReleaseExists: true

0 commit comments

Comments
 (0)