forked from EarthPol/NameMCAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
75 lines (65 loc) · 2.54 KB
/
release.yml
File metadata and controls
75 lines (65 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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