forked from MaaAssistantArknights/MaaAssistantArknights
-
Notifications
You must be signed in to change notification settings - Fork 0
358 lines (303 loc) · 12.9 KB
/
release-nightly-ota.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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
name: release-nightly-ota
on:
schedule:
- cron: "0 22 * * *" # Runs daily at 22:00 UTC
workflow_dispatch:
inputs:
release_body:
description: "Release note"
type: string
required: false
ref:
description: "Commit to build (git checkout)"
type: string
required: false
limit_maa:
description: "Number of releases to fetch from MaaAssistantArknights"
required: true
default: "10"
type: number
limit_mr:
description: "Number of releases to fetch from MaaRelease"
required: true
default: "10"
type: number
jobs:
build-win-nightly:
if: github.repository_owner == 'MaaAssistantArknights'
runs-on: windows-latest
strategy:
matrix:
msbuild_target: [x64]
fail-fast: false
env:
MAABUILDER_TARGET_PLATFORM: ${{ matrix.msbuild_target }}
outputs:
tag: ${{ steps.set_tag.outputs.tag }}
pre_version: ${{ steps.set_tag.outputs.pre_version }}
main_tag_name: ${{ steps.push_main_tag.outputs.main_tag_name }}
changelog: ${{ steps.read_changelog.outputs.content }}
steps:
- uses: actions/checkout@v4
with:
# repository: 'MaaAssistantArknights/MaaAssistantArknights'
#ref: ${{ inputs.ref }}
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 250
fetch-tags: true
- name: Fetch submodules
run: |
git submodule update --init --depth 1 3rdparty/EmulatorExtras
- name: Checkout ref (if provided)
if: inputs.ref != ''
run: |
git checkout --progress --recurse-submodules ${{ inputs.ref }}
- name: Check for Changes and Set tag
id: set_tag
run: |
# Fetch the latest tag from the repository
$latest_tag = git describe --tags --abbrev=0
# Check for changes between the latest tag and HEAD
$recent_changes = git log "$latest_tag..HEAD" --oneline
if (-not $recent_changes) {
Write-Output "No commits. Cancelling workflow..."
Write-Output "cancel_run=true" >> $env:GITHUB_ENV
exit 0
} else {
Write-Output "Recent commits: $recent_changes"
Write-Output "Commits found. Continuing build..."
Write-Output "cancel_run=false" >> $env:GITHUB_ENV
}
Write-Output "Previous Tag: $latest_tag"
Write-Output "latest_tag=$latest_tag" >> $env:GITHUB_OUTPUT
# Get the full description of the current commit
$described = git describe --tags --long --match 'v*'
Write-Output "New Described: $described"
$ids = $described -split "-"
if ($ids.Length -eq 3) {
# Extract and parse the current version
$current_version = $ids[0].Substring(1)
$parts = $current_version -split '\.'
if ($parts.Length -ne 3) {
Write-Error "Invalid version format: $current_version. Expected 'major.minor.patch'."
exit 1
}
# Increment the patch version
$parts[2] = [int]$parts[2] + 1
$new_version = "$($parts[0]).$($parts[1]).$($parts[2])"
# Construct the new tag and pre_version
$ver = "v$new_version"
$pre_version = $ids[0]
$dist = "{0:D3}" -f [int]$ids[1]
Write-Output "pre_version=$pre_version" >> $env:GITHUB_OUTPUT
Write-Output "New Tag: $ver-alpha.1.d$dist.$($ids[2])"
Write-Output "tag=$ver-alpha.1.d$dist.$($ids[2])" >> $env:GITHUB_OUTPUT
exit 0
}
if ($ids.Length -eq 4) {
$dist = "{0:D3}" -f [int]$ids[2]
$pre_version = "$($ids[0])-$($ids[1])"
Write-Output "Pre Version: $pre_version"
Write-Output "pre_version=$pre_version" >> $env:GITHUB_OUTPUT
Write-Output "tag: $pre_version.d$dist.$($ids[3])"
Write-Output "tag=$pre_version.d$dist.$($ids[3])" >> $env:GITHUB_OUTPUT
exit 0
}
exit 1
- name: Stop if no changes
if: env.cancel_run == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
curl -s -L -X POST `
-H "Accept: application/vnd.github+json" `
-H "Authorization: Bearer ${{ secrets.MAA_ACTION_READ_WRITE }}" `
-H "X-GitHub-Api-Version: 2022-11-28" `
"https://api.github.com/repos/MaaAssistantArknights/MaaAssistantArknights/actions/runs/${{ github.run_id }}/cancel" > $null
gh run watch ${{ github.run_id }}
- name: Generate Changelog
id: generate_changelog
run: |
python3 tools/ChangelogGenerator/changelog_generator.py --latest "${{ steps.set_tag.outputs.latest_tag }}" --tag "${{ steps.set_tag.outputs.tag }}"
Get-Content .\changelog.md | Select-Object -Skip 2 | Out-File -FilePath changelog_notag.md -Encoding utf8
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PYTHONIOENCODING: "utf-8"
- name: Stop if no changes
if: steps.generate_changelog.outputs.cancel_run == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
curl -s -L -X POST `
-H "Accept: application/vnd.github+json" `
-H "Authorization: Bearer ${{ secrets.MAA_ACTION_READ_WRITE }}" `
-H "X-GitHub-Api-Version: 2022-11-28" `
"https://api.github.com/repos/MaaAssistantArknights/MaaAssistantArknights/actions/runs/${{ github.run_id }}/cancel" > $null
gh run watch ${{ github.run_id }}
- name: Read Changelog to variable
id: read_changelog
uses: juliangruber/read-file-action@v1
with:
path: ./changelog_notag.md
- name: Cache .nuke/temp, ~/.nuget/packages
id: cache-nuget
uses: actions/cache@v4
with:
path: |
.nuke/temp
~/.nuget/packages
key: ${{ runner.os }}-${{ matrix.msbuild_target }}-${{ hashFiles('**/global.json', '**/*.csproj') }}
- name: Restore dependencies
if: steps.cache-nuget.outputs.cache-hit != 'true'
run: dotnet restore
- name: Cache MaaDeps
id: cache-maadeps
uses: actions/cache@v4
with:
path: |
./MaaDeps
key: ${{ runner.os }}-${{ matrix.msbuild_target }}-maadeps-${{ hashFiles('./maadeps-download.py') }}
- name: Bootstrap MaaDeps
if: steps.cache-maadeps.outputs.cache-hit != 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
python3 maadeps-download.py ${{ matrix.msbuild_target }}-windows
- name: Taggify Version
run: |
$csprojPath = "src/MaaWpfGui/MaaWpfGui.csproj"
$csprojPath = Resolve-Path -Path $csprojPath
$tag = '${{ steps.set_tag.outputs.tag }}' -replace '.*?/', ''
if ($tag -match '\d+(\.\d+){1,3}') {
$match = $Matches[0]
} else {
$match = "0.0.1"
}
echo "Tag value: $tag"
echo "Version value: $match"
[xml]$csproj = Get-Content -Path $csprojPath
$node = $csproj.Project.PropertyGroup | where {$_.ApplicationVersion -ne $null}
$node.InformationalVersion = $tag
$node.Version = $match
$node.FileVersion = $match
$node.AssemblyVersion = $match
$csproj.Save($csprojPath)
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Run './build.cmd DevBuild'
run: |
$env:GITHUB_WORKFLOW = 'dev-build-win' # pretend this is a dev-build-win workflow
$env:MAA_BUILDER_MAA_VERSION = "${{ steps.set_tag.outputs.tag }}"
echo "tag: " $env:MAA_BUILDER_MAA_VERSION
./build.cmd DevBuild
env:
Reason: "Build nightly version"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload MAA to Github
uses: actions/upload-artifact@v4
with:
name: MAA-win-${{ matrix.msbuild_target }}
path: artifacts
- name: Push tag to main repo
id: push_main_tag
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
$main_tag_name=$(echo "alpha/${{ steps.set_tag.outputs.tag }}")
git tag $main_tag_name -f
git push --tags origin HEAD:refs/tags/$main_tag_name -f
echo "main_tag_name=$main_tag_name" >> $env:GITHUB_OUTPUT
push-tag:
if: github.repository_owner == 'MaaAssistantArknights'
needs: build-win-nightly
runs-on: ubuntu-latest
steps:
- name: Fetch MaaRelease
uses: actions/checkout@v4
with:
repository: ${{ format('{0}/{1}', github.repository_owner, 'MaaRelease') }}
fetch-depth: 0
token: ${{ secrets.MAARELEASE_RELEASE }}
show-progress: false
- name: Commit and setup tag
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git checkout --orphan __temp
git rm -rf .
git commit --allow-empty --message ${{ needs.build-win-nightly.outputs.tag }}
git tag ${{ needs.build-win-nightly.outputs.tag }} || exit 0 # do nothing if the tag already exists
git push --tags origin HEAD:refs/tags/${{ needs.build-win-nightly.outputs.tag }}
make-ota:
if: github.repository_owner == 'MaaAssistantArknights'
needs: [build-win-nightly, push-tag]
strategy:
matrix:
target: [x64]
runs-on: ubuntu-latest
steps:
- name: Echo tag version
run: |
echo ${{ needs.build-win-nightly.outputs.tag }}
- name: Checkout code
uses: actions/checkout@v4
with:
path: MaaAssistantArknights
token: ${{ secrets.MAARELEASE_RELEASE }}
show-progress: false
- name: Download MAA from Github
uses: actions/download-artifact@v4
with:
name: MAA-win-${{ matrix.target }}
path: ${{ format('{0}/{1}', 'build-ota', needs.build-win-nightly.outputs.tag) }}
- name: Fetch release info
run: |
mkdir -pv build-ota && cd build-ota
# Convert inputs to integers
limit_maa=${{ inputs.limit_maa || 10 }}
limit_maa=${limit_maa%.*}
echo "Parsed limit_maa: $limit_maa"
limit_mr=${{ inputs.limit_mr || 10 }}
limit_mr=${limit_mr%.*}
echo "Parsed limit_mr: $limit_mr"
gh release list --repo 'MaaAssistantArknights/MaaAssistantArknights' --limit $limit_maa | tee ./release_maa.txt
gh release list --repo "${{ github.repository_owner }}/MaaRelease" --limit $limit_mr | tee ./release_mr.txt
echo ${{ needs.build-win-nightly.outputs.tag }} > ./config
cat ./release_maa.txt | awk '{ print $1 }' > ./tags_maa.txt
cat ./release_mr.txt | awk '{ print $1 }' > ./tags_mr.txt
comm <(sort ./tags_maa.txt) <(sort ./tags_mr.txt) | awk '{ print $1 }' >> ./config
echo "config:"
cat ./config
echo "release_tag=$(head -n 1 ./config)" >> $GITHUB_ENV
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build OTA
run: |
cd build-ota
pushd ${{ needs.build-win-nightly.outputs.tag }}
zip -d *.zip '*.lib' '*.pdb' '*.exp' '*.config' '*.xml'
mv *.zip MAA-${{ env.release_tag }}-win-${{ matrix.target }}.zip
popd
$GITHUB_WORKSPACE/MaaAssistantArknights/tools/OTAPacker/build.sh 'MaaAssistantArknights/MaaAssistantArknights' ./config ${{ matrix.target }} "${{ github.repository_owner }}/MaaRelease"
mv -v ${{ needs.build-win-nightly.outputs.tag }}/*.zip ./MAA-${{ env.release_tag }}-win-${{ matrix.target }}.zip
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload to MaaRelease
uses: svenstaro/upload-release-action@v2
with:
repo_name: ${{ format('{0}/{1}', github.repository_owner, 'MaaRelease') }}
repo_token: ${{ secrets.MAARELEASE_RELEASE }}
file_glob: true
file: build-ota/*.zip
tag: ${{ env.release_tag }}
prerelease: true
overwrite: true
body: |
${{ inputs.release_body || '' }}
${{ needs.build-win-nightly.outputs.changelog }}
**Full Changelog**: [${{ needs.build-win-nightly.outputs.pre_version }} -> ${{ needs.build-win-nightly.outputs.main_tag_name }}](https://github.com/${{ github.repository }}/compare/${{ needs.build-win-nightly.outputs.pre_version }}...${{ needs.build-win-nightly.outputs.main_tag_name }})
- name: Setup release mirror
run: |
gh workflow --repo MaaAssistantArknights/MaaRelease run release-mirrors.yml
env:
GH_TOKEN: ${{ secrets.MISTEOWORKFLOW }}