-
Notifications
You must be signed in to change notification settings - Fork 0
141 lines (117 loc) · 4.05 KB
/
create-github-release.yaml
File metadata and controls
141 lines (117 loc) · 4.05 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
name: Create Github release
on:
push:
tags:
- "v*.*.*" # triggers on tags like vX.Y.Z
jobs:
run-only-on-main-branch:
name: Verify main branch
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Check if tag is on main
run: |
git fetch origin main
if git merge-base --is-ancestor $GITHUB_SHA origin/main; then
echo "Tag is on main"
else
echo "Tag is NOT on main, skipping"
#exit 1
fi
build-native:
name: Build on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
needs: run-only-on-main-branch
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up GraalVM
uses: graalvm/setup-graalvm@eec48106e0bf45f2976c2ff0c3e22395cced8243
with:
java-version: "21"
distribution: "graalvm"
- name: Build native image
run: mvn -B clean package -Pnative
- name: Locate built executable
id: find_exe
shell: bash
run: |
mkdir dist
OS_NAME=${{ matrix.os }}
if [[ "$OS_NAME" == "windows-latest" ]]; then
BIN_PATH=$(find jfiletreeprettyprinter-cli/target -type f -name "jfiletreeprettyprinter.exe")
else
BIN_PATH=$(find jfiletreeprettyprinter-cli/target -type f -name "jfiletreeprettyprinter")
fi
echo "Found binary: $BIN_PATH"
cp "$BIN_PATH" dist/
echo "bin_path=$BIN_PATH" >> $GITHUB_OUTPUT
- name: Zip executable
id: zip_exe
shell: bash
run: |
VERSION=${GITHUB_REF_NAME}
OS_NAME=${{ matrix.os }}
case "$OS_NAME" in
ubuntu-latest) SAFE_OS_NAME="linux" ;;
windows-latest) SAFE_OS_NAME="windows" ;;
macos-latest) SAFE_OS_NAME="macos" ;;
*) SAFE_OS_NAME="$OS_NAME" ;;
esac
ZIP_NAME="jfiletreeprettyprinter-${VERSION}-${SAFE_OS_NAME}.zip"
echo "Zip to create: $ZIP_NAME"
cd dist
if [[ "$SAFE_OS_NAME" == "windows" ]]; then
powershell Compress-Archive -Path * -DestinationPath "$ZIP_NAME"
else
tar -a -c -f "$ZIP_NAME" *
fi
echo "zip_path=dist/$ZIP_NAME" >> $GITHUB_OUTPUT
cd ..
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: release-zips-${{ matrix.os }}
path: ${{ steps.zip_exe.outputs.zip_path }}
release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: build-native
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
path: release_zips
- name: Extract changelog for current version
id: changelog
shell: bash
run: |
TAG="${GITHUB_REF_NAME#v}" # Remove leading "v" (e.g. vX.Y.Z → X.Y.Z)
echo "Extracting changelog for version $TAG"
# Extract section for this version up to the next version header
awk "/## \\[$TAG\\]/,/^---/" CHANGELOG.md > release_notes.tmp
# Clean up formatting (remove trailing ---)
sed -i '/^---/d' release_notes.tmp
# Verify
echo "==== Extracted release notes ===="
cat release_notes.tmp
echo "================================"
echo "body_path=release_notes.tmp" >> $GITHUB_OUTPUT
- name: Create GitHub Release
uses: softprops/action-gh-release@6da8fa9354ddfdc4aeace5fc48d7f679b5214090
with:
name: "JFileTreePrettyPrinter ${{ github.ref_name }}"
body_path: ${{ steps.changelog.outputs.body_path }}
files: release_zips/**/*.zip
draft: true
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}