-
Notifications
You must be signed in to change notification settings - Fork 99
235 lines (201 loc) · 9.29 KB
/
autobuild.yaml
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
# Original script from totoa553/OpenTaiko and DragonRatTiger/OpenTaiko
name: Build OpenTaiko
on:
push:
branches:
- main
jobs:
build:
runs-on: windows-latest
permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the
# added or changed files to the repository.
contents: write
env:
messagePathPrefix: COMMIT_MSG_
versionsPath: COMMIT_VERSIONS
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Observe the Directory
shell: cmd
run: |
dir
- name: Get each commit message for version checking
id: get-latest-commits
run: |
$messages = ConvertFrom-Json $env:messagesJson
$nMessages = $messages.Count
echo "nMessages=$nMessages" >> $env:GITHUB_ENV
for ($c = 0; $c -lt $nMessages; ++$c) {
New-Item -Path ($env:messagePathPrefix + $c) -Type file
$message = $messages | Select-Object -Index $c
echo $message > ($env:messagePathPrefix + $c)
}
env:
messagesJson: ${{ toJSON(github.event.commits.*.message) }}
- name: Get project version
uses: kzrnm/get-net-sdk-project-versions-action@v2
id: get-version
with:
proj-path: OpenTaiko/OpenTaiko.csproj
- name: Store projectVersion in environment
run: |
echo "projectVersion=${{ steps.get-version.outputs.version }}" >> $env:GITHUB_ENV
- name: Extract latest version info from each commit message
id: extract-versions
run: |
$hasVersion = $false
$version = $env:projectVersion
New-Item -Path $env:versionsPath -Type file
for ($c = 0; $c -lt $env:nMessages; ++$c) {
$commitSubject = Get-Content -Path ($env:messagePathPrefix + $c) | Select-Object -First 1
if ($commitSubject -match '^(?<version>[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\s-\s') {
$hasVersion = $true
$version = $matches['version']
}
if ($c -eq 0) {
echo "versionFirst=$version" >> $env:GITHUB_ENV
}
echo $version >> $env:versionsPath
}
# check the latest version
if ($hasVersion) {
Write-Host "Extracted latest version is: $version"
echo "version=$version" >> $env:GITHUB_ENV
} else {
Write-Host "No valid version found in the latest commit messages. Skipping bump."
echo "version=" >> $env:GITHUB_ENV
}
echo "versionLast=$version" >> $env:GITHUB_ENV
- name: Bump OpenTaiko version if necessary
if: env.version != ''
run: |
$newVersion = $env:version
Write-Host "Updating version in OpenTaiko.csproj to $newVersion"
(Get-Content OpenTaiko/OpenTaiko.csproj) -replace '<Version>.*<\/Version>', "<Version>$newVersion</Version>" | Set-Content OpenTaiko/OpenTaiko.csproj
- name: Get current date
id: get-date
run: |
$date = Get-Date -Format "yyyy-MM-dd"
echo "date=$date" >> $env:GITHUB_ENV
- name: Update CHANGELOG.md
run: |
$versions = Get-Content -Path $env:versionsPath
$date = $env:date
$changelogPath = "CHANGELOG.md"
:commit for ($c = 0; $c -lt $env:nMessages; ++$c) {
# (Re-)read CHANGELOG.md content as (re-)split lines
$changelog = Get-Content -Path $changelogPath
# Ensure list type for []-indexing
if ($changelog.Count -eq 1) {
$changelog = , $changelog
}
# Read the message as individual items
$commitBody = Get-Content -Path ($env:messagePathPrefix + $c) | Select-Object -Skip 1
# Remove empty lines from the message
$message = ($commitBody | Where-Object { $_ -ne "" }) -join "`n"
# Check if the version already exists
$version = $versions | Select-Object -Index $c
for ($i = 0; $i -lt $changelog.Count; ++$i) {
if (-not ($changelog[$i] -match "## \[$version\]")) {
continue
}
# Capture the existing content under the version heading
if ($message) {
# Append after the empty line (if exist) or the heading
$di = ($changelog[$i + 1] -eq "")
$changelog[$i + $di] += "`n$message"
}
# Write updated content back to CHANGELOG.md
Set-Content -Path $changelogPath -Value $changelog
continue commit
}
# Insert new version under '# Changelog'
for ($i = 0; $i -lt $changelog.Count; ++$i) {
if (-not ($changelog[$i] -match "# Changelog")) {
continue
}
# Append after the title, create empty line space
$changelog[$i] += "`n`n## [$version] - $date (Beta)`n`n"
if ($message) {
$changelog[$i] += "$message`n"
}
# Remove original empty line space
while (++$i -lt $changelog.Count) {
if ($changelog[$i] -ne "") {
break
}
$changelog[$i] = $null
}
# Write updated content back to CHANGELOG.md
Set-Content -Path $changelogPath -Value $changelog
continue commit
}
# No '# Changelog', do nothing
break commit
}
- name: Commit CHANGELOG.md and OpenTaiko.csproj changes
run: |
git config --global user.name "github-actions"
git config --global user.email "actions@github.com"
git add OpenTaiko/OpenTaiko.csproj
git add CHANGELOG.md
if ($env:versionLast -eq $env:versionFirst) {
git commit -m "Update changelog for version $env:versionLast"
} else {
git commit -m "Update changelog for versions $env:versionFirst to $env:versionLast"
}
git push https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} HEAD:${{ github.ref }}
- name: Build for Windows x64
shell: cmd
run: |
build-win-x64.bat
- name: Create Archive (Win x64)
shell: cmd
run: |
cd OpenTaiko\bin\Release\net8.0\win-x64\
7z a ../../../../../OpenTaiko.Win.x64.zip publish/ -xr!publish/Songs/ -xr!publish/FFmpeg/ -xr!publish/System/ -xr!publish/Libs/
7z u ../../../../../OpenTaiko.Win.x64.zip "publish/Libs/win-x64/*" "publish/FFmpeg/win-x64/*" "publish/Songs/L2 Custom Charts/*" "publish/Songs/L3 Downloaded Songs/*" "publish/Songs/S1 Dan-i Dojo/box.def" "publish/Songs/S2 Taiko Towers/box.def" "publish/Songs/X1 Favorite/*" "publish/Songs/X2 Recent/*" "publish/Songs/X3 Search By Difficulty/*" "publish/Songs/X4 Search By Text/*"
cd ..\..\..\..\..\
- name: Build for Linux x64
shell: cmd
run: |
build-linux-x64.bat
- name: Create Archive (Linux x64)
shell: cmd
run: |
cd OpenTaiko\bin\Release\net8.0\linux-x64\
7z a ../../../../../OpenTaiko.Linux.x64.zip publish/ -xr!publish/Songs/ -xr!publish/FFmpeg/ -xr!publish/System/ -xr!publish/Libs/
7z u ../../../../../OpenTaiko.Linux.x64.zip "publish/Libs/linux-x64/*" "publish/FFmpeg/linux-x64/*" "publish/Songs/L2 Custom Charts/*" "publish/Songs/L3 Downloaded Songs/*" "publish/Songs/S1 Dan-i Dojo/box.def" "publish/Songs/S2 Taiko Towers/box.def" "publish/Songs/X1 Favorite/*" "publish/Songs/X2 Recent/*" "publish/Songs/X3 Search By Difficulty/*" "publish/Songs/X4 Search By Text/*"
cd ..\..\..\..\..\
- name: Check if tag exists
uses: mukunku/tag-exists-action@v1.6.0
id: check-tag
with:
tag: ${{ env.version }}
- name: Create Release
if: steps.check-tag.outputs.exists == 'false' && env.version != ''
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.version }}
release_name: OpenTaiko v${{ env.version }}
body: |
Note: The releases do not contain skins nor songs.
Please download/update through the OpenTaiko Hub: https://github.com/OpenTaiko/OpenTaiko-Hub/releases
draft: false
prerelease: false
- name: Upload All Builds for the Latest Release
uses: xresloader/upload-to-github-release@v1.6.0
with:
file: "OpenTaiko.Win.x64.zip;OpenTaiko.Linux.x64.zip"
overwrite: true
tag_name: ${{ env.versionLast }}
draft: false
token: ${{ secrets.GITHUB_TOKEN }}