-
Notifications
You must be signed in to change notification settings - Fork 0
259 lines (224 loc) · 8.32 KB
/
release.yml
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
name: Build and Release
on:
workflow_dispatch:
inputs:
version:
description: 'Release version (e.g. 1.0.0)'
required: true
type: string
env:
JAVA_VERSION: '17'
GRADLE_OPTS: "-Dorg.gradle.daemon=false"
jobs:
verify-version:
runs-on: ubuntu-22.04
permissions:
contents: write
outputs:
version: ${{ github.event.inputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: master
fetch-depth: 0
- name: Setup Git
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
- name: Validate version format
run: |
if [[ ! ${{ github.event.inputs.version }} =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Invalid version format. Must be in format x.y.z"
exit 1
fi
- name: Extract current version
id: current_version
run: |
echo "version=$(grep -E "^[[:space:]]*version[[:space:]]*=[[:space:]]*[^[:space:]]" version.properties | head -n 1 | cut -d'=' -f2 | tr -d '[:space:]' | sed 's/-snapshot$//')" >> $GITHUB_OUTPUT
- name: Compare versions
run: |
CURRENT_VERSION="${{ steps.current_version.outputs.version }}"
NEW_VERSION="${{ github.event.inputs.version }}"
if ! dpkg --compare-versions "$NEW_VERSION" ge "$CURRENT_VERSION"; then
echo "[error] New version ($NEW_VERSION) must be greater than or equal to current version ($CURRENT_VERSION)"
exit 1
fi
- name: Set version
id: set_version
run: echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
- name: Update version.properties version
run: |
VERSION="${{ github.event.inputs.version }}"
if ! sed -i "s/^version=.*/version=$VERSION/" version.properties; then
echo "[error] Failed to update version.properties"
exit 1
fi
if git diff --quiet version.properties; then
echo "[info] No changes to version.properties"
else
git add version.properties
git commit -m "chore: update version to $VERSION"
git push || {
echo "[error] Failed to push version update"
exit 1
}
fi
- name: Create and push tag
run: |
TAG_NAME="v${{ steps.set_version.outputs.version }}"
if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then
echo "[warning] Tag $TAG_NAME already exists, skipping tag creation"
else
echo "Creating new tag $TAG_NAME"
git tag -a "$TAG_NAME" -m "Release $TAG_NAME"
git push origin "$TAG_NAME" || {
echo "[error] Failed to push tag $TAG_NAME"
exit 1
}
fi
- name: Verify version match
run: |
PKG_VERSION=$(grep -E "^[[:space:]]*version[[:space:]]*=[[:space:]]*[^[:space:]]" version.properties | head -n 1 | cut -d'=' -f2 | tr -d '[:space:]')
if [ "${{ github.event.inputs.version }}" != "$PKG_VERSION" ]; then
echo "Version mismatch: Input version (${{ github.event.inputs.version }}) does not match version.properties version ($PKG_VERSION)"
exit 1
fi
build-jar:
needs: verify-version
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: master
fetch-depth: 0
- name: Set up JDK
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: ${{ env.JAVA_VERSION }}
cache: 'gradle'
- name: Make gradlew executable
run: chmod +x ./gradlew
- name: Build Processor JAR
run: |
./gradlew clean bootJar -Pversion=${{ needs.verify-version.outputs.version }} --stacktrace || {
echo "[error] Build failed. See below for detailed logs:"
find . -name "*.log" -type f -exec sh -c 'echo "=== $1 ==="; cat "$1"' _ {} \;
exit 1
}
- name: Prepare distribution
run: |
cp "build/libs/thymelab-processor-${{ needs.verify-version.outputs.version }}.jar" ./
- name: Upload JAR artifact
uses: actions/upload-artifact@v4
with:
name: jar
path: thymelab-processor-${{ needs.verify-version.outputs.version }}.jar
retention-days: 5
package-examples:
needs: verify-version
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: master
- name: Create examples archive
run: |
if [ ! -d "examples" ] || [ -z "$(ls -A examples)" ]; then
echo "[error] Examples directory not found or empty"
exit 1
fi
zip -r "thymelab-examples-${{ needs.verify-version.outputs.version }}.zip" examples/
- name: Upload examples artifact
uses: actions/upload-artifact@v4
with:
name: examples
path: thymelab-examples-*.zip
retention-days: 5
create-release:
needs: [verify-version, build-jar, package-examples]
runs-on: ubuntu-22.04
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: master
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Git
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git checkout master
- name: Get Changes
id: get_changes
run: |
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [ -z "$PREV_TAG" ]; then
CHANGES=$(git log --pretty=format:"- %s")
else
CHANGES=$(git log --pretty=format:"- %s" ${PREV_TAG}..HEAD)
fi
echo "changes<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Download JAR artifact
uses: actions/download-artifact@v4
with:
name: jar
path: release-files
- name: Download examples artifact
uses: actions/download-artifact@v4
with:
name: examples
path: release-files
- name: Create Release
uses: softprops/action-gh-release@v1
with:
name: ThymeLab v${{ needs.verify-version.outputs.version }}
body: |
## ThymeLab v${{ needs.verify-version.outputs.version }}
### 📥 Downloads
- **📦 thymelab-processor-${{ needs.verify-version.outputs.version }}.jar**: Standalone processor JAR
- **📚 thymelab-examples-${{ needs.verify-version.outputs.version }}.zip**: Template examples and resources
### 🚀 Quick Start
```bash
java -jar thymelab-processor-${{ needs.verify-version.outputs.version }}.jar \
-Dserver.port=8080 \
-Dlogging.level.com.github.thkwag.thymelab=INFO \
-Dwatch.directory.templates=/path/to/templates \
-Dwatch.directory.thymeleaf-data=/path/to/thymelab/data \
-Dwatch.directory.static=/path/to/static
```
### 📌 Note
The examples package contains template examples that can be used with ThymeLab Processor.
### 📝 What's Changed
${{ steps.get_changes.outputs.changes }}
files: |
release-files/thymelab-processor-${{ needs.verify-version.outputs.version }}.jar
release-files/thymelab-examples-${{ needs.verify-version.outputs.version }}.zip
draft: false
prerelease: false
generate_release_notes: true
tag_name: v${{ needs.verify-version.outputs.version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Update to next snapshot version
run: |
CURRENT_VERSION="${{ needs.verify-version.outputs.version }}"
NEW_VERSION=$(echo $CURRENT_VERSION | awk -F. '{$NF = $NF + 1;} 1' OFS=.)-snapshot
if ! sed -i "s/^version=.*/version=$NEW_VERSION/" version.properties; then
echo "[error] Failed to update version.properties"
exit 1
fi
git add version.properties
git commit -m "chore: update version to $NEW_VERSION"
git push || {
echo "[error] Failed to push changes"
exit 1
}