mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
127 lines
4.4 KiB
YAML
127 lines
4.4 KiB
YAML
name: Update Changelog After Renovate PR Merge
|
||
|
||
on:
|
||
# 1) Auto on pushes to your repo’s default branch (merge commits included)
|
||
push:
|
||
branches:
|
||
- v1.78.2-dev
|
||
|
||
# 2) Manual trigger
|
||
workflow_dispatch:
|
||
inputs:
|
||
dryRun:
|
||
description: 'Run without committing changes'
|
||
required: false
|
||
default: 'true'
|
||
|
||
jobs:
|
||
update-changelog:
|
||
runs-on: ubuntu-latest
|
||
|
||
# Only proceed if…
|
||
# - manual dispatch
|
||
# - OR a push to default branch
|
||
if: |
|
||
github.event_name == 'workflow_dispatch' ||
|
||
github.event_name == 'push'
|
||
|
||
steps:
|
||
- name: Checkout code
|
||
uses: actions/checkout@v5
|
||
|
||
- name: Check for Renovate dependency update
|
||
id: check-renovate
|
||
shell: bash
|
||
run: |
|
||
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
|
||
echo "isRenovate=true" >> $GITHUB_OUTPUT
|
||
exit 0
|
||
fi
|
||
msg="$(git log -1 --pretty=%B)"
|
||
if echo "$msg" | grep -q 'chore(deps): update dependency'; then
|
||
echo "isRenovate=true" >> $GITHUB_OUTPUT
|
||
else
|
||
echo "isRenovate=false" >> $GITHUB_OUTPUT
|
||
fi
|
||
|
||
- name: Abort if not a Renovate PR
|
||
if: steps.check-renovate.outputs.isRenovate == 'false'
|
||
run: |
|
||
echo "ℹ️ Last commit is not a Renovate dependency update—skipping."
|
||
|
||
- name: Parse Renovate PR info
|
||
if: steps.check-renovate.outputs.isRenovate == 'true'
|
||
id: extract
|
||
shell: pwsh
|
||
run: |
|
||
# 1) Determine dryRun
|
||
$dryRun = '${{ github.event.inputs.dryRun }}'
|
||
if (-not $dryRun) { $dryRun = 'false' }
|
||
Write-Host "🔍 dryRun = $dryRun"
|
||
|
||
# 2) Read full commit message
|
||
$fullMsg = git log -1 --pretty=%B
|
||
Write-Host "📝 Commit message:"; Write-Host $fullMsg
|
||
|
||
# 3) Extract PR number
|
||
if ($fullMsg -match 'Merge pull request #(\d+)') {
|
||
$prNumber = $matches[1]
|
||
} else {
|
||
throw "❌ Could not locate PR number in merge commit"
|
||
}
|
||
|
||
# 4) Extract dependency name & version
|
||
if ($fullMsg -match 'chore\(deps\): update dependency ([\w\.\-]+) to ([\d\.]+)') {
|
||
$depName = $matches[1]
|
||
$depVersion = $matches[2]
|
||
} else {
|
||
throw "❌ Could not parse dependency name/version"
|
||
}
|
||
|
||
# 5) Export outputs
|
||
echo "pr=$prNumber" >> $env:GITHUB_OUTPUT
|
||
echo "depName=$depName" >> $env:GITHUB_OUTPUT
|
||
echo "depVersion=$depVersion" >> $env:GITHUB_OUTPUT
|
||
echo "dryRun=$dryRun" >> $env:GITHUB_OUTPUT
|
||
|
||
- name: Update CHANGELOG.md
|
||
if: steps.check-renovate.outputs.isRenovate == 'true'
|
||
shell: pwsh
|
||
run: |
|
||
$path = "$env:GITHUB_WORKSPACE/CHANGELOG.md"
|
||
if (-not (Test-Path $path)) { throw "❌ CHANGELOG.md not found" }
|
||
$lines = Get-Content $path
|
||
$pr = '${{ steps.extract.outputs.pr }}'
|
||
$dep = '${{ steps.extract.outputs.depName }}'
|
||
$ver = '${{ steps.extract.outputs.depVersion }}'
|
||
$entry = "- #$pr: update dependency $dep to $ver"
|
||
|
||
# Find latest version header: ## [x.y.z]
|
||
$vIndex = $lines.FindIndex({ $_ -match '^## \[\d+\.\d+\.\d+\]' })
|
||
if ($vIndex -lt 0) { throw "❌ No version header found" }
|
||
|
||
# Locate or create "### Dependency update"
|
||
$depIndex = -1
|
||
for ($i = $vIndex + 1; $i -lt $lines.Count; $i++) {
|
||
if ($lines[$i] -match '^### Dependency update') { $depIndex = $i; break }
|
||
if ($lines[$i] -match '^## ') { break }
|
||
}
|
||
if ($depIndex -eq -1) {
|
||
$lines.Insert($vIndex + 1, '### Dependency update')
|
||
$depIndex = $vIndex + 1
|
||
}
|
||
|
||
# Insert the changelog entry
|
||
$lines.Insert($depIndex + 1, $entry)
|
||
Set-Content -Path $path -Value $lines
|
||
Write-Host "✅ Inserted in CHANGELOG.md:"; Write-Host " $entry"
|
||
|
||
- name: Commit & push
|
||
if: steps.check-renovate.outputs.isRenovate == 'true' && steps.extract.outputs.dryRun != 'true'
|
||
run: |
|
||
git config user.name "github-actions"
|
||
git config user.email "github-actions@github.com"
|
||
git add CHANGELOG.md
|
||
git commit -m "docs: update changelog for #${{ steps.extract.outputs.pr }}"
|
||
git push
|