-
Notifications
You must be signed in to change notification settings - Fork 1
317 lines (288 loc) · 11.8 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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
name: Release
on:
push:
branches:
- main
jobs:
prerelease:
name: Prerelease
runs-on: windows-latest
environment: Release
outputs:
csharp_changesets: ${{ toJson(fromJson(steps.changesets.outputs.result).csharp) }}
web_changesets: ${{ toJson(fromJson(steps.changesets.outputs.result).web) }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install dotnet tools
run: dotnet tool install -g dotnet-script
- name: Build
run: nuget restore && dotnet build
- name: Prepare for nightly release
run: dotnet script ./scripts/CopyBuildsToBin.csx
- name: Create nightly release
uses: softprops/action-gh-release@v1
with:
prerelease: true
target_commitish: ${{ github.sha }}
name: "dev ${{ github.run_number }}"
tag_name: "dev_${{ github.run_number }}"
body: >
**DO NOT DOWNLOAD** unless either I told you to or you know what you're doing. Instead look these mods up on Thunderstore and download them from there.
These are testing builds used for development of the mods. They contain the most recent changes which are usually untested and broken. Use at your own risk.
files: ./bin/*.dll
- name: Load changesets
id: changesets
uses: actions/github-script@v6
with:
script: |
const path = require("path");
const fs = require("fs");
const changesets = fs
.readdirSync("changesets")
.map((filename) => path.parse(filename))
.filter(
(file) =>
file.ext.toLowerCase() === ".md" && file.name !== "README"
)
.map((file) => {
const parts = file.name.split("_");
return {
filename: file.base,
game: parts[0],
project: parts[1],
version_bump_type: parts[2],
changelog_description: fs.readFileSync(
path.join("changesets", file.base),
"utf-8"
),
};
});
return {
web: changesets.filter(changeset => changeset.game === "Web"),
csharp: changesets.filter(changeset => changeset.game !== "Web"),
};
release-csharp:
name: Release (C#)
runs-on: windows-latest
environment: Release
needs: prerelease
if: ${{ needs.prerelease.outputs.csharp_changesets != '[]' }}
strategy:
matrix:
changeset: ${{ fromJson(needs.prerelease.outputs.csharp_changesets) }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install dotnet tools
run: |
dotnet tool install -g dotnet-script
dotnet tool install -g tcli
- name: Bump version
id: bump_version
env:
GAME: ${{ matrix.changeset.game }}
PROJECT: ${{ matrix.changeset.project }}
VERSION_BUMP_TYPE: ${{ matrix.changeset.version_bump_type }}
CHANGELOG_DESCRIPTION: ${{ matrix.changeset.changelog_description }}
run: dotnet script ./scripts/Release.csx -- "$env:GAME" "$env:PROJECT" "$env:VERSION_BUMP_TYPE" "$env:CHANGELOG_DESCRIPTION"
- name: Build
run: nuget restore && dotnet build --configuration Release
- name: Release to Thunderstore
if: steps.bump_version.outputs.release_thunderstore == 'true'
env:
GAME: ${{ matrix.changeset.game }}
PROJECT: ${{ matrix.changeset.project }}
NEW_VERSION: ${{ steps.bump_version.outputs.new_version }}
TCLI_AUTH_TOKEN: ${{ secrets.THUNDERSTORE_API_TOKEN }}
run: node ./scripts/release-to-thunderstore.mjs "$env:GAME" "$env:PROJECT" "$env:NEW_VERSION"
- name: Release to Github
if: steps.bump_version.outputs.release_thunderstore != 'true' && steps.bump_version.outputs.release_livesplit != 'true'
shell: pwsh
env:
GAME: ${{ matrix.changeset.game }}
PROJECT: ${{ matrix.changeset.project }}
NEW_VERSION: ${{ steps.bump_version.outputs.new_version }}
run: |
node ./scripts/release-to-github.mjs "$env:GAME" "$env:PROJECT"
Compress-Archive -Path "./projects/$env:GAME/$env:PROJECT/dist/build/*" -DestinationPath "./projects/$env:GAME/$env:PROJECT/dist/$env:GAME-$env:PROJECT-$env:NEW_VERSION.zip" -Verbose
- name: Copy LiveSplit build for commit
if: steps.bump_version.outputs.release_livesplit == 'true'
env:
GAME: ${{ matrix.changeset.game }}
PROJECT: ${{ matrix.changeset.project }}
run: |
$DLL_NAME = "$env:PROJECT.dll"
cd "./projects/$env:GAME/$env:PROJECT"
mkdir -Force "./Components"
Copy-Item "./bin/Release/$DLL_NAME" "./Components/$DLL_NAME"
- name: Commit version bump
run: |
Remove-Item "./changesets/${{ matrix.changeset.filename }}"
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global core.autocrlf input
git add -A
git commit -m "Release" --no-verify
for ($i = 0; $i -lt 3; $i++) {
git fetch
try {
git rebase --autostash --no-verify
} catch {
git rebase --abort
Write-Output "Failed to rebase with main, probably due to git conflict. Manual fix required..."
exit 1
}
git push --no-verify
if ($LASTEXITCODE -eq 0) {
exit 0
}
}
Write-Output "Failed to push version bump after 3 retries. Manual fix required..."
exit 1
- name: Create release
uses: softprops/action-gh-release@v1
with:
target_commitish: ${{ github.sha }}
name: "${{ matrix.changeset.game }} ${{ matrix.changeset.project }} v${{ steps.bump_version.outputs.new_version }}"
tag_name: "${{ matrix.changeset.game }}${{ matrix.changeset.project }}_v${{ steps.bump_version.outputs.new_version }}"
body: ${{ steps.bump_version.outputs.changelog }}
files: |
./projects/${{ matrix.changeset.game }}/${{ matrix.changeset.project }}/dist/*.zip
./projects/${{ matrix.changeset.game }}/${{ matrix.changeset.project }}/thunderstore/build/*.zip
./projects/${{ matrix.changeset.game }}/${{ matrix.changeset.project }}/bin/Release/${{ matrix.changeset.project }}.dll
release-web:
name: Release (JS)
runs-on: ubuntu-latest
environment: Release
needs: prerelease
permissions:
pages: write
id-token: write
contents: write
if: ${{ needs.prerelease.outputs.web_changesets != '[]' }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
- uses: actions/setup-node@v3
with:
node-version: 18.x
registry-url: https://registry.npmjs.org
- name: Install dependencies
run: npm ci
- name: Bump versions
uses: actions/github-script@v6
env:
CHANGESETS: ${{ needs.prerelease.outputs.web_changesets }}
with:
script: |
const fs = require("fs");
const path = require("path");
const cp = require("child_process");
for (const changeset of JSON.parse(process.env.CHANGESETS)) {
const projectPath = path.join("projects", changeset.game, changeset.project);
const changelogPath = path.join(projectPath, "CHANGELOG.md");
const packageJson = JSON.parse(
fs.readFileSync(path.join(projectPath, "package.json"), "utf8")
);
const result = cp.spawnSync(
"npm",
[
"-w",
packageJson.name,
"version",
"--no-git-tag-version",
changeset.version_bump_type.toLowerCase(),
],
{ stdio: "inherit" }
);
if (result.status) throw new Error("Command failed");
const packageJson2 = JSON.parse(
fs.readFileSync(path.join(projectPath, "package.json"), "utf8")
);
const oldChangelog = fs.readFileSync(changelogPath, "utf8");
fs.writeFileSync(
changelogPath,
`## ${packageJson2.version}\n\n${changeset.changelog_description}\n\n${oldChangelog}`
);
fs.unlinkSync(path.join("changesets", changeset.filename));
}
- name: Build
run: npm -ws run build
- name: Publish to npm
uses: actions/github-script@v6
env:
CHANGESETS: ${{ needs.prerelease.outputs.web_changesets }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
with:
script: |
const fs = require("fs");
const path = require("path");
const cp = require("child_process");
for (const changeset of JSON.parse(process.env.CHANGESETS)) {
const projectPath = path.join("projects", changeset.game, changeset.project);
const packageJson = JSON.parse(
fs.readFileSync(path.join(projectPath, "package.json"), "utf8")
);
if (packageJson.private) continue;
const result = cp.spawnSync(
"npm",
["-w", packageJson.name, "publish", "--access=public"],
{ stdio: "inherit" }
);
if (result.status) throw new Error("Command failed");
}
- name: Commit version bumps
run: |
Remove-Item "./changesets/${{ matrix.changeset.filename }}"
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global core.autocrlf input
git add -A
git commit -m "Release" --no-verify
for ($i = 0; $i -lt 3; $i++) {
git fetch
try {
git rebase --autostash --no-verify
} catch {
git rebase --abort
Write-Output "Failed to rebase with main, probably due to git conflict. Manual fix required..."
exit 1
}
git push --no-verify
if ($LASTEXITCODE -eq 0) {
exit 0
}
}
Write-Output "Failed to push version bump after 3 retries. Manual fix required..."
exit 1
- name: Check if should deploy pages
id: deploy_pages
uses: actions/github-script@v6
env:
CHANGESETS: ${{ needs.prerelease.outputs.web_changesets }}
with:
script: |
var projects = new Set(JSON.parse(process.env.CHANGESETS).map(changeset => changeset.project));
console.log(projects);
return ["vr-input-viewer"].some(name => projects.has(name));
- name: Bundle pages
if: ${{ steps.deploy_pages.outputs.result == 'true' }}
run: ./pages/build.sh
- name: Upload vr.jf.id.au
uses: SamKirkland/[email protected]
with:
server: ftpupload.net
protocol: ftps
username: if0_34708249
password: ${{ secrets.IF_FTP_PASSWORD }}
local-dir: ./pages/dist/vr.jf.id.au/
server-dir: ./vr.jf.id.au/htdocs/
- name: Upload pages artifact
if: ${{ steps.deploy_pages.outputs.result == 'true' }}
uses: actions/upload-pages-artifact@v2
with:
path: ./pages/dist/github-pages
- name: Deploy pages
if: ${{ steps.deploy_pages.outputs.result == 'true' }}
uses: actions/deploy-pages@v2