-
Notifications
You must be signed in to change notification settings - Fork 5
200 lines (182 loc) · 10 KB
/
Copy pathrelease.yml
File metadata and controls
200 lines (182 loc) · 10 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
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
name: Stable Release
# Fires when a vX.Y.Z tag is pushed, or can be triggered manually with a tag.
on:
push:
tags:
- 'v[0-9]*.[0-9]*.[0-9]*'
workflow_dispatch:
inputs:
tag:
description: 'Tag to release (e.g. v3.0.2)'
required: true
jobs:
release:
name: Stable Release
runs-on: ubuntu-latest
permissions:
contents: write # Required for creating the GitHub Release
steps:
# ──────────────────────────────────────────────────────────────────────
# 1. CHECKOUT
# ──────────────────────────────────────────────────────────────────────
- name: Checkout
uses: actions/checkout@v7
with:
# For push:tags: github.ref is the tag ref (e.g. refs/tags/v3.0.3).
# For workflow_dispatch: github.ref is the branch (e.g. refs/heads/main).
# We never use the tag input here because the tag may not exist yet —
# it is created in a later step.
ref: ${{ github.ref }}
fetch-depth: 0
# ──────────────────────────────────────────────────────────────────────
# 2. RESOLVE VERSION
# ──────────────────────────────────────────────────────────────────────
- name: Resolve version from tag
id: meta
run: |
REF="${{ github.event.inputs.tag || github.ref_name }}"
VERSION="${REF#v}"
echo "ref=${REF}" >> "$GITHUB_OUTPUT"
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "Releasing version: ${VERSION}"
# ──────────────────────────────────────────────────────────────────────
# 3. CREATE TAG (if it doesn't exist yet)
#
# When triggered via workflow_dispatch the tag may not exist yet.
# This step creates and pushes it so the GitHub Release can reference it.
# ──────────────────────────────────────────────────────────────────────
- name: Create and push tag if missing
run: |
REF="${{ steps.meta.outputs.ref }}"
if git rev-parse --verify --quiet "refs/tags/${REF}" > /dev/null; then
echo "Tag ${REF} already exists; skipping creation."
else
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag "${REF}"
git push origin "${REF}"
echo "Created and pushed tag ${REF}."
fi
# ──────────────────────────────────────────────────────────────────────
# 4. BUILD & VERSION
# ──────────────────────────────────────────────────────────────────────
- name: Set up JDK 25
uses: actions/setup-java@v5
with:
distribution: temurin
java-version: '25'
cache: maven
- name: Set release version in all POMs
run: |
mvn -B -ntp versions:set \
-DnewVersion="${{ steps.meta.outputs.version }}" \
-DprocessAllModules \
-DgenerateBackupPoms=false
- name: Build
run: mvn -B -ntp -DskipTests -Dspotless.check.skip=true package
# ──────────────────────────────────────────────────────────────────────
# 5. EXTRACT CHANGELOG
#
# Reads the section for this version from CHANGELOG.md.
# Falls back to a link to the file when the section is missing.
# ──────────────────────────────────────────────────────────────────────
- name: Extract changelog for this version
id: changelog
run: |
VERSION="${{ steps.meta.outputs.version }}"
HEADER="## [${VERSION}]"
# Fixed-string match via index() avoids regex issues with dots in versions.
NOTES=$(awk \
-v hdr="$HEADER" \
'/^## \[/ && p { exit }
index($0, hdr) == 1 { p=1; next }
p { print }' \
CHANGELOG.md)
if [[ -z "$NOTES" ]]; then
NOTES="No changelog entry found for ${VERSION}."
fi
printf '%s\n' "$NOTES" > release-notes.md
echo "=== Release notes preview ===" && cat release-notes.md
# ──────────────────────────────────────────────────────────────────────
# 6. GITHUB RELEASE
# ──────────────────────────────────────────────────────────────────────
- name: Create GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create "${{ steps.meta.outputs.ref }}" \
--title "EzRTP ${{ steps.meta.outputs.version }}" \
--notes-file release-notes.md \
"ezrtp-bukkit/target/EzRTP-${{ steps.meta.outputs.version }}.jar" \
"ezrtp-paper/target/ezrtp-paper-${{ steps.meta.outputs.version }}.jar" \
"ezrtp-spigot/target/ezrtp-spigot-${{ steps.meta.outputs.version }}.jar" \
"ezrtp-purpur/target/ezrtp-purpur-${{ steps.meta.outputs.version }}.jar"
# ──────────────────────────────────────────────────────────────────────
# 7. MODRINTH RELEASE
# ──────────────────────────────────────────────────────────────────────
- name: Release to Modrinth (stable)
uses: Kir-Antipov/mc-publish@v3.3
with:
modrinth-id: ezplugins-ezrtp
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}
modrinth-featured: true
name: "EzRTP ${{ steps.meta.outputs.version }}"
version: "${{ steps.meta.outputs.version }}"
version-type: release
files: |
ezrtp-bukkit/target/EzRTP-${{ steps.meta.outputs.version }}.jar
ezrtp-paper/target/ezrtp-paper-${{ steps.meta.outputs.version }}.jar
ezrtp-spigot/target/ezrtp-spigot-${{ steps.meta.outputs.version }}.jar
ezrtp-purpur/target/ezrtp-purpur-${{ steps.meta.outputs.version }}.jar
game-versions: ">=1.13"
game-versions-filter: release
loaders: |
bukkit
spigot
paper
purpur
folia
changelog-file: release-notes.md
dependencies: |
placeholderapi(optional)
chunky(optional)
worldguard(optional)
teams-api(optional)
ezcountdown(optional)
ezeconomy(optional)
pvpmanager(optional)
simple-combatlog(optional)
# ──────────────────────────────────────────────────────────────────────
# 8. DISCORD NOTIFICATION
# ──────────────────────────────────────────────────────────────────────
- name: Post Discord notification
env:
DISCORD_WEBHOOK: ${{ secrets.EZRTP_RELEASE_DISCORD_WEBHOOK }}
run: |
REPO="${{ github.repository }}"
VERSION="${{ steps.meta.outputs.version }}"
GH_URL="https://github.com/${REPO}/releases/tag/${{ steps.meta.outputs.ref }}"
MODRINTH_URL="https://modrinth.com/plugin/ezplugins-ezrtp/version/${VERSION}"
# Truncate changelog to fit Discord's 4096-char embed description limit.
CHANGELOG=$(head -c 3800 release-notes.md || true)
PAYLOAD=$(jq -n \
--arg version "$VERSION" \
--arg gh_url "$GH_URL" \
--arg modrinth_url "$MODRINTH_URL" \
--arg changelog "$CHANGELOG" \
'{
embeds: [{
title: ("🚀 EzRTP " + $version + " — Stable Release"),
url: $gh_url,
color: 3447003,
description: $changelog,
fields: [
{ name: "GitHub Release", value: ("[View on GitHub](" + $gh_url + ")"), inline: true },
{ name: "Modrinth", value: ("[Download on Modrinth](" + $modrinth_url + ")"), inline: true }
],
footer: { text: "Stable release" }
}]
}')
curl --fail -s -X POST "$DISCORD_WEBHOOK" \
-H "Content-Type: application/json" \
-d "$PAYLOAD"