workflow - iterate for each pushed commit; fix deprecation; prevent extra empty lines (#741)
This commit is contained in:
parent
0e4920491a
commit
db426c9647
192
.github/workflows/autobuild.yaml
vendored
192
.github/workflows/autobuild.yaml
vendored
@ -16,9 +16,13 @@ jobs:
|
|||||||
# added or changed files to the repository.
|
# added or changed files to the repository.
|
||||||
contents: write
|
contents: write
|
||||||
|
|
||||||
|
env:
|
||||||
|
messagePathPrefix: COMMIT_MSG_
|
||||||
|
versionsPath: COMMIT_VERSIONS
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Repository
|
- name: Checkout Repository
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Setup .NET
|
- name: Setup .NET
|
||||||
uses: actions/setup-dotnet@v4
|
uses: actions/setup-dotnet@v4
|
||||||
@ -30,80 +34,137 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
dir
|
dir
|
||||||
|
|
||||||
- name: Get commit subject for version checking
|
- name: Get each commit message for version checking
|
||||||
id: get-latest-commit
|
id: get-latest-commits
|
||||||
run: |
|
run: |
|
||||||
$latestCommitMessage = git log -1 --pretty=format:%s
|
$messages = ConvertFrom-Json $env:messagesJson
|
||||||
echo "::set-output name=latest_commit_message::$latestCommitMessage"
|
$nMessages = $messages.Count
|
||||||
|
echo "nMessages=$nMessages" >> $env:GITHUB_ENV
|
||||||
- name: Extract version from commit message
|
for ($c = 0; $c -lt $nMessages; ++$c) {
|
||||||
id: extract-version
|
New-Item -Path ($env:messagePathPrefix + $c) -Type file
|
||||||
run: |
|
$message = $messages | Select-Object -Index $c
|
||||||
if ('${{ steps.get-latest-commit.outputs.latest_commit_message }}' -match '^(?<version>[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\s-\s') {
|
echo $message > ($env:messagePathPrefix + $c)
|
||||||
$version = $matches['version']
|
|
||||||
Write-Host "Extracted version is: $version"
|
|
||||||
echo "::set-output name=version::$version"
|
|
||||||
} else {
|
|
||||||
Write-Host "No valid version found in the latest commit message. Skipping bump."
|
|
||||||
echo "::set-output name=version::"
|
|
||||||
}
|
}
|
||||||
|
env:
|
||||||
|
messagesJson: ${{ toJSON(github.event.commits.*.message) }}
|
||||||
|
|
||||||
- name: Bump OpenTaiko version if necessary
|
- name: Get project version
|
||||||
if: steps.extract-version.outputs.version != ''
|
|
||||||
run: |
|
|
||||||
$newVersion = "${{ steps.extract-version.outputs.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 version
|
|
||||||
uses: kzrnm/get-net-sdk-project-versions-action@v2
|
uses: kzrnm/get-net-sdk-project-versions-action@v2
|
||||||
id: get-version
|
id: get-version
|
||||||
with:
|
with:
|
||||||
proj-path: OpenTaiko/OpenTaiko.csproj
|
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
|
- name: Get current date
|
||||||
id: get-date
|
id: get-date
|
||||||
run: |
|
run: |
|
||||||
$date = Get-Date -Format "yyyy-MM-dd"
|
$date = Get-Date -Format "yyyy-MM-dd"
|
||||||
echo "::set-output name=date::$date"
|
echo "date=$date" >> $env:GITHUB_ENV
|
||||||
|
|
||||||
- name: Get changelogs from commit description
|
|
||||||
id: get-commit-message
|
|
||||||
run: |
|
|
||||||
$message = git log -1 --pretty=%b
|
|
||||||
$messagePath = 'COMMIT_MSG'
|
|
||||||
echo $message >> $messagePath
|
|
||||||
echo "messagePath=$messagePath" >> $env:GITHUB_ENV
|
|
||||||
|
|
||||||
- name: Update CHANGELOG.md
|
- name: Update CHANGELOG.md
|
||||||
run: |
|
run: |
|
||||||
$version = '${{steps.get-version.outputs.version}}'
|
$versions = Get-Content -Path $env:versionsPath
|
||||||
$date = '${{steps.get-date.outputs.date}}'
|
$date = $env:date
|
||||||
$messagePath = $env:messagePath
|
|
||||||
$changelogPath = "CHANGELOG.md"
|
$changelogPath = "CHANGELOG.md"
|
||||||
|
|
||||||
# Read commit description content
|
:commit for ($c = 0; $c -lt $env:nMessages; ++$c) {
|
||||||
$messageLines = Get-Content -Path $messagePath
|
# (Re-)read CHANGELOG.md content as (re-)split lines
|
||||||
|
$changelog = Get-Content -Path $changelogPath
|
||||||
# Read CHANGELOG.md content
|
# Ensure list type for []-indexing
|
||||||
$changelog = Get-Content -Path $changelogPath
|
if ($changelog.Count -eq 1) {
|
||||||
|
$changelog = , $changelog
|
||||||
# Remove empty lines from the message
|
|
||||||
$message = ($messageLines | Where-Object { $_ -ne "" }) -join "`n"
|
|
||||||
|
|
||||||
# Check if the version already exists
|
|
||||||
if ($changelog -match "## \[$version\]") {
|
|
||||||
if ($message) {
|
|
||||||
# Capture the existing content under the version heading
|
|
||||||
$changelog = $changelog -replace "(## \[($version)\] .* \(Beta\))", "`$1`n`n$message"
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
# Insert new version under '# Changelog'
|
|
||||||
$changelog = $changelog -replace "(# Changelog)", "`$1`n`n## [$version] - $date (Beta)`n`n$message"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Write updated content back to CHANGELOG.md
|
# Read the message as individual items
|
||||||
Set-Content -Path $changelogPath -Value $changelog
|
$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
|
- name: Commit CHANGELOG.md and OpenTaiko.csproj changes
|
||||||
run: |
|
run: |
|
||||||
@ -111,10 +172,13 @@ jobs:
|
|||||||
git config --global user.email "actions@github.com"
|
git config --global user.email "actions@github.com"
|
||||||
git add OpenTaiko/OpenTaiko.csproj
|
git add OpenTaiko/OpenTaiko.csproj
|
||||||
git add CHANGELOG.md
|
git add CHANGELOG.md
|
||||||
git commit -m "Update changelog for version ${{steps.get-version.outputs.version}}"
|
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 }}
|
git push https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} HEAD:${{ github.ref }}
|
||||||
|
|
||||||
|
|
||||||
- name: Build for Windows x64
|
- name: Build for Windows x64
|
||||||
shell: cmd
|
shell: cmd
|
||||||
run: |
|
run: |
|
||||||
@ -145,16 +209,16 @@ jobs:
|
|||||||
uses: mukunku/tag-exists-action@v1.6.0
|
uses: mukunku/tag-exists-action@v1.6.0
|
||||||
id: check-tag
|
id: check-tag
|
||||||
with:
|
with:
|
||||||
tag: "${{steps.get-version.outputs.version}}"
|
tag: ${{ env.projectVersion }}
|
||||||
|
|
||||||
- name: Create Release
|
- name: Create Release
|
||||||
if: steps.check-tag.outputs.exists == 'false'
|
if: steps.check-tag.outputs.exists == 'false' && env.version != ''
|
||||||
uses: actions/create-release@v1
|
uses: actions/create-release@v1
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
with:
|
with:
|
||||||
tag_name: "${{steps.get-version.outputs.version}}"
|
tag_name: ${{ env.projectVersion }}
|
||||||
release_name: OpenTaiko v${{steps.get-version.outputs.version}}
|
release_name: OpenTaiko v${{ env.projectVersion }}
|
||||||
body: |
|
body: |
|
||||||
Note: The releases do not contain skins nor songs.
|
Note: The releases do not contain skins nor songs.
|
||||||
Please download/update through the OpenTaiko Hub: https://github.com/OpenTaiko/OpenTaiko-Hub/releases
|
Please download/update through the OpenTaiko Hub: https://github.com/OpenTaiko/OpenTaiko-Hub/releases
|
||||||
@ -162,10 +226,10 @@ jobs:
|
|||||||
prerelease: false
|
prerelease: false
|
||||||
|
|
||||||
- name: Upload All Builds
|
- name: Upload All Builds
|
||||||
uses: xresloader/upload-to-github-release@v1.4.2
|
uses: xresloader/upload-to-github-release@v1.6.0
|
||||||
with:
|
with:
|
||||||
file: "OpenTaiko.Win.x64.zip;OpenTaiko.Linux.x64.zip"
|
file: "OpenTaiko.Win.x64.zip;OpenTaiko.Linux.x64.zip"
|
||||||
overwrite: true
|
overwrite: true
|
||||||
tag_name: "${{steps.get-version.outputs.version}}"
|
tag_name: ${{ env.projectVersion }}
|
||||||
draft: false
|
draft: false
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
token: ${{ secrets.GITHUB_TOKEN }}
|
Loading…
Reference in New Issue
Block a user