Files
mRemoteNG/.github/workflows/add_PR_2_chlog.yml

126 lines
4.2 KiB
YAML
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
name: Update Changelog After Renovate PR Merge
on:
push:
branches:
- v1.78.2-dev # ← replace with your repos default branch
workflow_dispatch:
inputs:
dryRun:
description: 'Run without committing changes'
required: false
default: 'true'
jobs:
update-changelog:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- 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 from merge subject
if ($fullMsg -match 'Merge pull request #(\d+)') {
$prNumber = $matches[1]
} else {
throw "❌ Could not locate PR number in merge commit"
}
# 4) Extract dependency update from body
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) Persist 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 $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 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