Repository navigation
258 lines (216 loc) · 9.17 KB
/
Copy pathrelease.yml
File metadata and controls
258 lines (216 loc) · 9.17 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
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
name: Release
# Triggered by pushing a tag in the format: {module}-v{semver}
# Example: tags-v0.1.0, omnibar-v1.2.3
on:
push:
tags:
- "*-v*.*.*"
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup pnpm
uses: pnpm/action-setup@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "22"
cache: "pnpm"
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build all packages
run: pnpm turbo build
# Parse tag
# Tag format: {module}-v{version} -> module=tags version=0.1.0
- name: Parse tag
id: tag
run: |
TAG="${GITHUB_REF_NAME}"
MODULE="${TAG%-v*}"
VERSION="${TAG##*-v}"
echo "module=$MODULE" >> "$GITHUB_OUTPUT"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
# Ask pnpm where the package lives instead of assuming a directory.
# Releasable packages live under modules/ (standalone modules) and
# bridges/ (system bridges), and both ship a Foundry manifest.
- name: Resolve package directory
id: pkg
run: |
MODULE="${{ steps.tag.outputs.module }}"
DIR=$(pnpm --filter "@rpg-made-simple/$MODULE" list --depth -1 --json \
| jq -r --arg root "$PWD/" '.[0].path // empty | sub("^" + $root; "")')
if [[ -z "$DIR" ]]; then
echo "Error: no workspace package named @rpg-made-simple/$MODULE (does the module id in the tag match the package name?)"
exit 1
fi
echo "dir=$DIR" >> "$GITHUB_OUTPUT"
- name: Generate changelog
id: changelog
run: |
DIR="${{ steps.pkg.outputs.dir }}"
MODULE="${{ steps.tag.outputs.module }}"
TAG="${{ steps.tag.outputs.tag }}"
# Find the most recent previous tag for this module
PREV_TAG=$(git tag --list "${MODULE}-v*" --sort=version:refname \
| grep -v "^${TAG}$" | tail -1)
if [[ -n "$PREV_TAG" ]]; then
RANGE="${PREV_TAG}..HEAD"
else
RANGE="HEAD"
fi
ENTRIES=$(git log "$RANGE" --pretty=format:"- %s" -- "$DIR/")
if [[ -z "$ENTRIES" ]]; then
ENTRIES="- No recorded changes"
fi
# Store multiline output using the GitHub Actions delimiter pattern
{
echo "entries<<CHANGELOG_EOF"
echo "$ENTRIES"
echo "CHANGELOG_EOF"
} >> "$GITHUB_OUTPUT"
echo "prev_tag=${PREV_TAG}" >> "$GITHUB_OUTPUT"
- name: Validate module dist
run: |
DIR="${{ steps.pkg.outputs.dir }}"
if [[ ! -f "$DIR/dist/module.json" ]]; then
echo "Error: $DIR/dist/module.json not found (is this package a Foundry module?)"
exit 1
fi
# Patch module.json with release-specific URLs
# The build generates module.json without manifest/download URLs.
# We inject them here so the published manifest is self-contained.
#
# manifest: always points to the latest release index (via GitHub's
# /releases/latest/download/ redirect), so Foundry always sees
# the most recent module.json even as versions change.
# download: points to the exact versioned zip for this release.
- name: Patch module.json with release URLs
id: manifest
run: |
MODULE="${{ steps.tag.outputs.module }}"
VERSION="${{ steps.tag.outputs.version }}"
TAG="${{ steps.tag.outputs.tag }}"
REPO="${{ github.repository }}"
MANIFEST_FILE="${{ steps.pkg.outputs.dir }}/dist/module.json"
TITLE=$(jq -r '.title' "$MANIFEST_FILE")
echo "title=$TITLE" >> "$GITHUB_OUTPUT"
MANIFEST_URL="https://github.com/$REPO/releases/latest/download/$MODULE.json"
DOWNLOAD_URL="https://github.com/$REPO/releases/download/$TAG/$MODULE.zip"
jq \
--arg version "$VERSION" \
--arg manifest "$MANIFEST_URL" \
--arg download "$DOWNLOAD_URL" \
'. + {version: $version, manifest: $manifest, download: $download}' \
"$MANIFEST_FILE" > /tmp/module_patched.json
cp /tmp/module_patched.json "$MANIFEST_FILE"
# Also save as {module}.json so the upload name is unambiguous
cp "$MANIFEST_FILE" "$MODULE.json"
- name: Create module ZIP
run: |
MODULE="${{ steps.tag.outputs.module }}"
DIR="${{ steps.pkg.outputs.dir }}"
(cd "$DIR/dist" && zip -r "$GITHUB_WORKSPACE/$MODULE.zip" .)
# Publish individual module release.
# Not marked as latest: "latest" is always the release index.
- name: Write module release notes
run: |
MODULE="${{ steps.tag.outputs.module }}"
REPO="${{ github.repository }}"
PREV_TAG="${{ steps.changelog.outputs.prev_tag }}"
{
echo "## ${{ steps.manifest.outputs.title }} v${{ steps.tag.outputs.version }}"
echo ""
echo "### Changelog"
if [[ -n "$PREV_TAG" ]]; then
echo "_Changes since \`$PREV_TAG\`_"
fi
echo ""
echo "${{ steps.changelog.outputs.entries }}"
echo ""
echo "### Install"
echo "Install in Foundry VTT using this manifest URL:"
echo '```'
echo "https://github.com/$REPO/releases/latest/download/$MODULE.json"
echo '```'
} > /tmp/module-notes.md
- name: Publish module release
uses: ncipollo/release-action@v1
with:
tag: ${{ steps.tag.outputs.tag }}
name: "${{ steps.manifest.outputs.title }} v${{ steps.tag.outputs.version }}"
artifacts: "${{ steps.tag.outputs.module }}.zip,${{ steps.tag.outputs.module }}.json"
makeLatest: false
allowUpdates: true
token: ${{ secrets.GITHUB_TOKEN }}
bodyFile: /tmp/module-notes.md
# Build and publish the release index.
# The index collects one {module}.json per published module and is always
# marked as the latest release. This lets module.json files reference
# /releases/latest/download/{module}.json as a stable manifest URL.
#
# Index versions are monotonically incremented integers (release-index-v1,
# release-index-v2, ...). The previous index is downloaded and merged so
# every module is always present in the index, even if only one changed.
- name: Build release index
id: index
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
MODULE="${{ steps.tag.outputs.module }}"
mkdir -p release-index
cp "$MODULE.json" "release-index/$MODULE.json"
# Find the highest-numbered existing index release
LATEST=$(gh release list --limit 200 --json tagName \
--jq '[.[] | .tagName | select(startswith("release-index-v"))] |
sort_by(ltrimstr("release-index-v") | tonumber) |
last // empty')
if [[ -n "$LATEST" ]]; then
echo "Merging previous index from $LATEST..."
mkdir -p /tmp/prev-index
gh release download "$LATEST" --dir /tmp/prev-index --pattern "*.json" 2>/dev/null || true
for f in /tmp/prev-index/*.json; do
[[ -f "$f" ]] || continue
NAME=$(basename "$f" .json)
# Skip the module we just released: we already have the updated version
[[ "$NAME" == "$MODULE" ]] && continue
cp "$f" "release-index/$NAME.json"
done
PREV_VER="${LATEST#release-index-v}"
NEW_VER=$((PREV_VER + 1))
else
echo "No previous index found, starting at v1."
NEW_VER=1
fi
echo "new_version=$NEW_VER" >> "$GITHUB_OUTPUT"
- name: Write index release notes
run: |
TAG="${{ steps.tag.outputs.tag }}"
cat > /tmp/index-notes.md <<'HEADER'
Auto-generated module index. Always use `/releases/latest/download/{module}.json` as the manifest URL in Foundry VTT.
HEADER
echo "Updated by release: **$TAG**" >> /tmp/index-notes.md
echo "" >> /tmp/index-notes.md
echo "### Published modules" >> /tmp/index-notes.md
for f in release-index/*.json; do
NAME=$(basename "$f" .json)
VER=$(jq -r '.version // "unknown"' "$f")
TITLE=$(jq -r '.title // $name' --arg name "$NAME" "$f")
echo "- $TITLE \`$NAME\` v$VER" >> /tmp/index-notes.md
done
- name: Publish release index
uses: ncipollo/release-action@v1
with:
tag: "release-index-v${{ steps.index.outputs.new_version }}"
name: "Release Index v${{ steps.index.outputs.new_version }}"
artifacts: "release-index/*.json"
makeLatest: true
allowUpdates: true
token: ${{ secrets.GITHUB_TOKEN }}
bodyFile: /tmp/index-notes.md