-
Notifications
You must be signed in to change notification settings - Fork 0
195 lines (161 loc) · 5.97 KB
/
Copy pathrelease.yml
File metadata and controls
195 lines (161 loc) · 5.97 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
name: Release
on:
push:
tags:
- 'v*'
permissions:
contents: write
jobs:
package:
name: Package mod
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Validate release version
shell: bash
run: |
set -euo pipefail
VERSION="$(jq -r '.version' mod.txt)"
if [[ "${GITHUB_REF_TYPE}" == "tag" && "${GITHUB_REF_NAME}" != "v${VERSION}" ]]; then
echo "::error::tag (${GITHUB_REF_NAME}) does not match mod version (v${VERSION})"
exit 1
fi
echo "version=$VERSION" >> "$GITHUB_ENV"
- name: Generate update metadata
shell: bash
run: |
set -euo pipefail
ident="$(jq -r '.updates[0].identifier // empty' mod.txt)"
version="$(jq -r '.version' mod.txt)"
repo="$GITHUB_REPOSITORY"
if [[ -z "$ident" ]]; then
echo "has_update_metadata=false" >> "$GITHUB_ENV"
echo "No mod.txt updates[0].identifier configured; skipping update metadata."
exit 0
fi
mkdir -p generated
jq -n \
--arg ident "$ident" \
--arg version "$version" \
--arg download_url "https://github.com/$repo/releases/download/v$version/ModOptionsSearchFilter.zip" \
--arg patchnotes_url "https://github.com/$repo/releases/tag/v$version" \
'[{
ident: $ident,
version: $version,
download_url: $download_url,
patchnotes_url: $patchnotes_url
}]' > generated/update_meta.json
echo "has_update_metadata=true" >> "$GITHUB_ENV"
- name: Build SuperBLT zip
shell: bash
run: |
set -euo pipefail
rm -rf package ModOptionsSearchFilter.zip
mkdir -p package/ModOptionsSearchFilter
cp -R hooks mod.txt modoptionssearchfilter.lua modules package/ModOptionsSearchFilter/
if [[ "${has_update_metadata}" == "true" ]]; then
cp generated/update_meta.json package/ModOptionsSearchFilter/update_meta.json
fi
cd package
zip -r ../ModOptionsSearchFilter.zip ModOptionsSearchFilter
- name: Get previous tag
id: previous-tag
shell: bash
run: |
set -euo pipefail
git fetch --tags --force
previous_tag="$(git --no-pager tag --sort=creatordate --merged "${GITHUB_REF_NAME}" | grep -v "^${GITHUB_REF_NAME}$" | tail -1 || true)"
echo "previous_tag=$previous_tag" >> "$GITHUB_OUTPUT"
- name: Generate changelog
id: changelog
if: ${{ steps.previous-tag.outputs.previous_tag != '' }}
uses: requarks/changelog-action@v1
with:
token: ${{ github.token }}
fromTag: ${{ github.ref_name }}
toTag: ${{ steps.previous-tag.outputs.previous_tag }}
writeToFile: false
restrictToTypes: feat,fix,perf
useGitmojis: false
includeInvalidCommits: false
- name: Write release notes
env:
CHANGELOG: ${{ steps.changelog.outputs.changes }}
PREVIOUS_TAG: ${{ steps.previous-tag.outputs.previous_tag }}
shell: bash
run: |
set -euo pipefail
printf 'Mod Options Search Filter %s\n' "$version" > release-notes.md
if [[ -n "$CHANGELOG" ]]; then
printf '\n%s\n' "$CHANGELOG" >> release-notes.md
elif [[ -z "$PREVIOUS_TAG" ]]; then
printf '\nInitial release.\n' >> release-notes.md
else
printf '\nMaintenance release.\n' >> release-notes.md
fi
- name: Upload release asset
env:
GITHUB_TOKEN: ${{ github.token }}
TAG: ${{ github.ref_name }}
shell: bash
run: |
set -euo pipefail
assets=(ModOptionsSearchFilter.zip)
if [[ "${has_update_metadata}" == "true" ]]; then
assets+=(generated/update_meta.json)
fi
if gh release view "$TAG" >/dev/null 2>&1; then
gh release edit "$TAG" --notes-file release-notes.md
gh release upload "$TAG" "${assets[@]}" --clobber
else
gh release create "$TAG" "${assets[@]}" \
--title "$TAG" \
--notes-file release-notes.md
fi
- name: Publish update metadata
if: ${{ env.has_update_metadata == 'true' }}
env:
TAG: ${{ github.ref_name }}
shell: bash
run: |
set -euo pipefail
cp generated/update_meta.json update_meta.json
if git diff --quiet -- update_meta.json; then
echo "update_meta.json already matches $TAG"
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add update_meta.json
git commit -m "chore: update release metadata for $TAG"
git push origin HEAD:main
nexus:
name: Upload to Nexus Mods
needs: package
permissions:
contents: read
environment: nexusmods
runs-on: ubuntu-latest
steps:
- name: Download GitHub release
env:
GH_REPO: ${{ github.repository }}
GH_TOKEN: ${{ github.token }}
TAG: ${{ github.ref_name }}
shell: bash
run: |
set -euo pipefail
gh release download "$TAG" --pattern ModOptionsSearchFilter.zip
echo "version=${TAG#v}" >> "$GITHUB_ENV"
- name: Upload to Nexus Mods
uses: Nexus-Mods/upload-action@c96019556046053aa26044b44396cd38929daf23 # v1.0.0-beta.10
with:
api_key: ${{ secrets.NEXUSMODS_API_KEY }}
file_id: ${{ secrets.NEXUSMODS_FILE_ID }}
filename: ModOptionsSearchFilter.zip
version: ${{ env.version }}
primary_mod_manager_download: true
update_mod_version: true