2024-10-26 09:56:14 +02:00
|
|
|
# Original script from totoa553/OpenTaiko and DragonRatTiger/OpenTaiko
|
|
|
|
|
|
|
|
name: Build OpenTaiko
|
|
|
|
|
2024-11-04 12:57:25 +01:00
|
|
|
on:
|
2024-10-26 09:56:14 +02:00
|
|
|
push:
|
|
|
|
branches:
|
|
|
|
- main
|
2024-11-04 12:57:25 +01:00
|
|
|
|
2024-10-26 09:56:14 +02:00
|
|
|
jobs:
|
|
|
|
build:
|
|
|
|
runs-on: windows-latest
|
2024-11-04 12:57:25 +01:00
|
|
|
|
2024-10-26 09:56:14 +02:00
|
|
|
permissions:
|
|
|
|
# Give the default GITHUB_TOKEN write permission to commit and push the
|
|
|
|
# added or changed files to the repository.
|
|
|
|
contents: write
|
2024-11-04 12:57:25 +01:00
|
|
|
|
|
|
|
env:
|
|
|
|
messagePathPrefix: COMMIT_MSG_
|
|
|
|
versionsPath: COMMIT_VERSIONS
|
|
|
|
|
2024-10-26 09:56:14 +02:00
|
|
|
steps:
|
|
|
|
- name: Checkout Repository
|
2024-11-04 12:57:25 +01:00
|
|
|
uses: actions/checkout@v4
|
|
|
|
|
2024-10-26 09:56:14 +02:00
|
|
|
- name: Setup .NET
|
|
|
|
uses: actions/setup-dotnet@v4
|
|
|
|
with:
|
|
|
|
dotnet-version: 8.0.x
|
|
|
|
|
|
|
|
- name: Observe the Directory
|
|
|
|
shell: cmd
|
|
|
|
run: |
|
|
|
|
dir
|
2024-11-04 12:57:25 +01:00
|
|
|
|
|
|
|
- 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
|
2024-10-26 09:56:14 +02:00
|
|
|
run: |
|
2024-11-04 12:57:25 +01:00
|
|
|
echo "projectVersion=${{ steps.get-version.outputs.version }}" >> $env:GITHUB_ENV
|
|
|
|
|
|
|
|
- name: Extract latest version info from each commit message
|
|
|
|
id: extract-versions
|
2024-10-26 09:56:14 +02:00
|
|
|
run: |
|
2024-11-04 12:57:25 +01:00
|
|
|
$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
|
2024-10-26 09:56:14 +02:00
|
|
|
} else {
|
2024-11-04 12:57:25 +01:00
|
|
|
Write-Host "No valid version found in the latest commit messages. Skipping bump."
|
|
|
|
echo "version=" >> $env:GITHUB_ENV
|
2024-10-26 09:56:14 +02:00
|
|
|
}
|
2024-11-04 12:57:25 +01:00
|
|
|
echo "versionLast=$version" >> $env:GITHUB_ENV
|
|
|
|
|
2024-10-26 09:56:14 +02:00
|
|
|
- name: Bump OpenTaiko version if necessary
|
2024-11-04 12:57:25 +01:00
|
|
|
if: env.version != ''
|
2024-10-26 09:56:14 +02:00
|
|
|
run: |
|
2024-11-04 12:57:25 +01:00
|
|
|
$newVersion = $env:version
|
2024-10-26 09:56:14 +02:00
|
|
|
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
|
2024-11-04 12:57:25 +01:00
|
|
|
|
2024-10-26 09:56:14 +02:00
|
|
|
- name: Get current date
|
|
|
|
id: get-date
|
|
|
|
run: |
|
|
|
|
$date = Get-Date -Format "yyyy-MM-dd"
|
2024-11-04 12:57:25 +01:00
|
|
|
echo "date=$date" >> $env:GITHUB_ENV
|
2024-10-26 09:56:14 +02:00
|
|
|
|
|
|
|
- name: Update CHANGELOG.md
|
|
|
|
run: |
|
2024-11-04 12:57:25 +01:00
|
|
|
$versions = Get-Content -Path $env:versionsPath
|
|
|
|
$date = $env:date
|
2024-10-26 09:56:14 +02:00
|
|
|
$changelogPath = "CHANGELOG.md"
|
|
|
|
|
2024-11-04 12:57:25 +01:00
|
|
|
: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
|
|
|
|
}
|
2024-11-02 05:37:16 +01:00
|
|
|
|
2024-11-04 12:57:25 +01:00
|
|
|
# Read the message as individual items
|
|
|
|
$commitBody = Get-Content -Path ($env:messagePathPrefix + $c) | Select-Object -Skip 1
|
2024-10-26 09:56:14 +02:00
|
|
|
|
2024-11-04 12:57:25 +01:00
|
|
|
# Remove empty lines from the message
|
|
|
|
$message = ($commitBody | Where-Object { $_ -ne "" }) -join "`n"
|
2024-10-26 09:56:14 +02:00
|
|
|
|
2024-11-04 12:57:25 +01:00
|
|
|
# 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
|
|
|
|
}
|
2024-10-26 09:56:14 +02:00
|
|
|
# Capture the existing content under the version heading
|
2024-11-04 12:57:25 +01:00
|
|
|
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
|
2024-10-26 09:56:14 +02:00
|
|
|
}
|
2024-11-04 12:57:25 +01:00
|
|
|
|
2024-10-26 09:56:14 +02:00
|
|
|
# Insert new version under '# Changelog'
|
2024-11-04 12:57:25 +01:00
|
|
|
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
|
|
|
|
}
|
2024-10-26 09:56:14 +02:00
|
|
|
|
2024-11-04 12:57:25 +01:00
|
|
|
# Write updated content back to CHANGELOG.md
|
|
|
|
Set-Content -Path $changelogPath -Value $changelog
|
|
|
|
|
|
|
|
continue commit
|
|
|
|
}
|
|
|
|
|
|
|
|
# No '# Changelog', do nothing
|
|
|
|
break commit
|
|
|
|
}
|
2024-11-04 12:33:23 +01:00
|
|
|
|
2024-10-26 09:56:14 +02:00
|
|
|
- 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
|
2024-11-04 12:57:25 +01:00
|
|
|
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"
|
|
|
|
}
|
2024-10-26 09:56:14 +02:00
|
|
|
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
|
2024-11-04 12:57:25 +01:00
|
|
|
|
2024-10-26 09:56:14 +02:00
|
|
|
- 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/*"
|
|
|
|
cd ..\..\..\..\..\
|
2024-11-04 12:57:25 +01:00
|
|
|
|
2024-10-26 09:56:14 +02:00
|
|
|
- name: Build for Linux x64
|
|
|
|
shell: cmd
|
|
|
|
run: |
|
|
|
|
build-linux-x64.bat
|
2024-11-04 12:57:25 +01:00
|
|
|
|
2024-10-26 09:56:14 +02:00
|
|
|
- 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/*"
|
|
|
|
cd ..\..\..\..\..\
|
|
|
|
|
|
|
|
- name: Check if tag exists
|
|
|
|
uses: mukunku/tag-exists-action@v1.6.0
|
|
|
|
id: check-tag
|
2024-11-04 12:57:25 +01:00
|
|
|
with:
|
|
|
|
tag: ${{ env.version }}
|
2024-10-26 09:56:14 +02:00
|
|
|
|
|
|
|
- name: Create Release
|
2024-11-04 12:57:25 +01:00
|
|
|
if: steps.check-tag.outputs.exists == 'false' && env.version != ''
|
2024-10-26 09:56:14 +02:00
|
|
|
uses: actions/create-release@v1
|
|
|
|
env:
|
2024-11-04 12:57:25 +01:00
|
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
2024-10-26 09:56:14 +02:00
|
|
|
with:
|
2024-11-04 12:57:25 +01:00
|
|
|
tag_name: ${{ env.version }}
|
|
|
|
release_name: OpenTaiko v${{ env.version }}
|
2024-10-26 09:56:14 +02:00
|
|
|
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
|
2024-11-04 12:57:25 +01:00
|
|
|
|
2024-10-26 09:56:14 +02:00
|
|
|
- name: Upload All Builds
|
2024-11-04 12:57:25 +01:00
|
|
|
if: steps.check-tag.outputs.exists == 'false' && env.version != ''
|
|
|
|
uses: xresloader/upload-to-github-release@v1.6.0
|
2024-10-26 09:56:14 +02:00
|
|
|
with:
|
|
|
|
file: "OpenTaiko.Win.x64.zip;OpenTaiko.Linux.x64.zip"
|
|
|
|
overwrite: true
|
2024-11-04 12:57:25 +01:00
|
|
|
tag_name: ${{ env.version }}
|
2024-10-26 09:56:14 +02:00
|
|
|
draft: false
|
2024-11-04 12:57:25 +01:00
|
|
|
token: ${{ secrets.GITHUB_TOKEN }}
|