ci: Updated workflow for change log
This commit is contained in:
+101
-3
@@ -1,5 +1,7 @@
|
||||
name: Mod Build
|
||||
on: push
|
||||
on:
|
||||
- push
|
||||
- workflow_dispatch
|
||||
env:
|
||||
MOD_NAME: "RefinedRDApi"
|
||||
MOD_ID: "7q2RnptXynYzEX"
|
||||
@@ -24,7 +26,7 @@ jobs:
|
||||
echo "Engine Directory: ${{env.ENGINE_DIR}}"
|
||||
echo "Built Mods Directory: ${{env.BUILT_MODS_DIR}}"
|
||||
echo "Dev Build Directory: ${{env.DEV_BUILDS_DIR}}"
|
||||
echo "Change Log: ${{vars.CHANGELOG}}"
|
||||
echo "Change Log: auto-generated from commits since last release/* tag"
|
||||
|
||||
Build:
|
||||
runs-on: windows-ue
|
||||
@@ -33,6 +35,7 @@ jobs:
|
||||
shell: pwsh
|
||||
outputs:
|
||||
version: ${{steps.version.outputs.version}}
|
||||
changelog_b64: ${{steps.changelog.outputs.changelog_b64}}
|
||||
steps:
|
||||
- name: Compute Version
|
||||
id: version
|
||||
@@ -108,6 +111,79 @@ jobs:
|
||||
git reset --hard "origin/$ref"
|
||||
}
|
||||
echo "Pulled ${{env.MOD_NAME}} @ latest (${{gitea.ref_name}})"
|
||||
|
||||
- name: Generate Changelog
|
||||
id: changelog
|
||||
run: |
|
||||
$modPath = "${{env.SML_DIR}}/Mods/${{env.MOD_NAME}}"
|
||||
if ("${{env.IS_GAME_FEATURE_PLUGIN}}" -eq "true") {
|
||||
$modPath = "${{env.SML_DIR}}/Mods/GameFeatures/${{env.MOD_NAME}}"
|
||||
}
|
||||
|
||||
# Last commit that was actually released to SMR is marked by a release/* tag
|
||||
# pushed by the SMRDeploy job. No manual tagging, no manual changelog.
|
||||
$prevTag = (git -C $modPath describe --tags --abbrev=0 --match "release/*" HEAD 2>$null)
|
||||
if ($LASTEXITCODE -ne 0 -or [string]::IsNullOrWhiteSpace($prevTag)) {
|
||||
$prevTag = $null
|
||||
$range = "HEAD"
|
||||
echo "No previous release/* tag found - using full history"
|
||||
} else {
|
||||
$range = "$prevTag..HEAD"
|
||||
echo "Previous release tag: $prevTag"
|
||||
}
|
||||
|
||||
$subjects = @(git -C $modPath log --no-merges --pretty=format:%s $range) |
|
||||
Where-Object { -not [string]::IsNullOrWhiteSpace($_) }
|
||||
|
||||
$groups = [ordered]@{
|
||||
"Features" = @()
|
||||
"Fixes" = @()
|
||||
"Performance" = @()
|
||||
"Changes" = @()
|
||||
"Other" = @()
|
||||
}
|
||||
# Commit types that are noise for players - never shown
|
||||
$skip = @("chore", "ci", "docs", "test", "tests", "style", "build")
|
||||
|
||||
foreach ($subject in $subjects) {
|
||||
if ($subject -match '^(?<type>[a-zA-Z]+)(\([^)]*\))?!?:\s*(?<desc>.+)$') {
|
||||
$type = $matches.type.ToLower()
|
||||
$desc = $matches.desc.Trim()
|
||||
if ($skip -contains $type) { continue }
|
||||
switch ($type) {
|
||||
"feat" { $groups["Features"] += $desc }
|
||||
"fix" { $groups["Fixes"] += $desc }
|
||||
"perf" { $groups["Performance"] += $desc }
|
||||
"refactor" { $groups["Changes"] += $desc }
|
||||
default { $groups["Other"] += $desc }
|
||||
}
|
||||
} else {
|
||||
$groups["Other"] += $subject.Trim()
|
||||
}
|
||||
}
|
||||
|
||||
$lines = @()
|
||||
foreach ($name in $groups.Keys) {
|
||||
$items = $groups[$name] | Select-Object -Unique
|
||||
if ($items.Count -eq 0) { continue }
|
||||
$lines += "### $name"
|
||||
foreach ($item in $items) { $lines += "- $item" }
|
||||
$lines += ""
|
||||
}
|
||||
|
||||
if ($lines.Count -eq 0) {
|
||||
$lines = @("### Changes", "- Maintenance release")
|
||||
}
|
||||
|
||||
$header = @("# Change Log - v${{steps.version.outputs.version}}", "")
|
||||
$changelog = (($header + $lines) -join "`n").Trim()
|
||||
echo "----- Changelog -----"
|
||||
echo $changelog
|
||||
echo "---------------------"
|
||||
|
||||
# base64 so the multiline markdown survives job outputs intact
|
||||
$b64 = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($changelog))
|
||||
Write-Output "changelog_b64=$b64" >> $Env:GITHUB_OUTPUT
|
||||
|
||||
- name: Update UPlugin Versions
|
||||
run: |
|
||||
@@ -213,9 +289,13 @@ jobs:
|
||||
path: ${{env.BUILT_MODS_DIR}}
|
||||
|
||||
- name: Deploy to SMR
|
||||
id: deploy
|
||||
run: |
|
||||
echo "Deploying to SMR"
|
||||
$Version = "${{needs.Build.outputs.version}}"
|
||||
$Changelog = [Text.Encoding]::UTF8.GetString([Convert]::FromBase64String("${{needs.Build.outputs.changelog_b64}}"))
|
||||
echo "Changelog:"
|
||||
echo $Changelog
|
||||
$query = '{ "query": "query { getModByReference(modReference:\"${{env.MOD_NAME}}\"){ versions(filter:{limit: 1}){ version } }}"}'
|
||||
$SMRVersion = (Invoke-RestMethod `
|
||||
-Method POST `
|
||||
@@ -232,5 +312,23 @@ jobs:
|
||||
& "S:/ficsit_windows_amd64.exe" smr upload `
|
||||
--api-base "$APIURL" `
|
||||
--api-key "${{secrets.FICSIT_TOKEN}}" `
|
||||
"${{env.MOD_ID}}" "$File" "${{vars.CHANGELOG}}"
|
||||
"${{env.MOD_ID}}" "$File" "$Changelog"
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Error "SMR upload failed"
|
||||
exit 1
|
||||
}
|
||||
Write-Output "uploaded=true" >> $Env:GITHUB_OUTPUT
|
||||
echo "Done"
|
||||
|
||||
- name: Tag Released Commit
|
||||
if: ${{ steps.deploy.outputs.uploaded == 'true' }}
|
||||
run: |
|
||||
$Version = "${{needs.Build.outputs.version}}"
|
||||
$modPath = "${{env.SML_DIR}}/Mods/${{env.MOD_NAME}}"
|
||||
if ("${{env.IS_GAME_FEATURE_PLUGIN}}" -eq "true") {
|
||||
$modPath = "${{env.SML_DIR}}/Mods/GameFeatures/${{env.MOD_NAME}}"
|
||||
}
|
||||
# This tag is the marker the next build's changelog starts from
|
||||
git -C $modPath tag -f "release/$Version"
|
||||
git -C $modPath push -f origin "release/$Version"
|
||||
echo "Tagged release/$Version @ $(git -C $modPath rev-parse HEAD)"
|
||||
Reference in New Issue
Block a user