From aafb608149288840189519f3b51bf4fce32b6eb5 Mon Sep 17 00:00:00 2001 From: Dimitrij Date: Tue, 9 Sep 2025 23:27:09 +0100 Subject: [PATCH] Update GitHub Actions workflow for Renovate PRs --- .github/workflows/add_PR_2_chlog.yml | 110 ++++++++++++++------------- 1 file changed, 57 insertions(+), 53 deletions(-) diff --git a/.github/workflows/add_PR_2_chlog.yml b/.github/workflows/add_PR_2_chlog.yml index 3d9a17f8..b0c30b18 100644 --- a/.github/workflows/add_PR_2_chlog.yml +++ b/.github/workflows/add_PR_2_chlog.yml @@ -3,7 +3,7 @@ name: Update Changelog After Renovate PR Merge on: push: branches: - - v1.78.2-dev # ← replace with your actual default branch + - v1.78.2-dev # ← replace with your default branch workflow_dispatch: inputs: @@ -20,99 +20,103 @@ jobs: - name: Checkout code uses: actions/checkout@v3 - - name: Parse last commit for Renovate info + - name: Check for Renovate dependency update + id: check-renovate + shell: bash + run: | + # Always true for manual runs + if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then + echo "isRenovate=true" >> $GITHUB_OUTPUT + exit 0 + fi + + # Inspect the last commit message + 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: Skip if not a Renovate PR + if: steps.check-renovate.outputs.isRenovate == 'false' + run: | + echo "â„šī¸ No Renovate dependency update found in the last commit. Skipping changelog update." + + - name: Parse Renovate PR info + if: steps.check-renovate.outputs.isRenovate == 'true' id: extract shell: pwsh run: | - # Determine dryRun setting + # Determine dryRun $dryRun = '${{ github.event.inputs.dryRun }}' if (-not $dryRun) { $dryRun = 'false' } Write-Host "🔍 dryRun = $dryRun" - # Get the full commit message (subject + body) - $fullMessage = git log -1 --pretty=%B - Write-Host "📝 Full commit message:" - Write-Host $fullMessage + # Grab full commit message + $fullMsg = git log -1 --pretty=%B - # Grab the line that contains the dependency update - $prLine = $fullMessage | - Select-String -Pattern 'chore\(deps\): update dependency' - if (-not $prLine) { - throw "❌ No 'chore(deps): update dependency' line found" - } - - # Clean it up - $line = $prLine.Line.Trim() - - # Extract PR number at the end (#1234) - if ($line -match '#(\d+)$') { - $pr = $matches[1] + # Extract PR number (#1234) + if ($fullMsg -match '#(\d+)\s*$') { + $prNumber = $matches[1] } else { - throw "❌ No PR number found in: $line" + throw "❌ No PR number found in commit message" } - # Extract dependency name and version - if ($line -match 'chore\(deps\): update dependency ([\w\.\-]+) to ([\d\.]+)') { - $dep = $matches[1] - $ver = $matches[2] + # 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 from: $line" + throw "❌ Could not parse dependency info" } - Write-Host "✅ Parsed PR#$pr → $dep v$ver" - - # Export for later steps - echo "pr=$pr" >> $env:GITHUB_OUTPUT - echo "depName=$dep" >> $env:GITHUB_OUTPUT - echo "depVersion=$ver">> $env:GITHUB_OUTPUT - echo "dryRun=$dryRun" >> $env:GITHUB_OUTPUT + 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: | - $changelog = "$env:GITHUB_WORKSPACE/CHANGELOG.md" - if (-not (Test-Path $changelog)) { - throw "❌ CHANGELOG.md not found" - } + $path = "$env:GITHUB_WORKSPACE/CHANGELOG.md" + if (-not (Test-Path $path)) { throw "❌ CHANGELOG.md not found" } - $lines = Get-Content $changelog + $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 the latest version header: ## [x.y.z] + # Locate latest version header: ## [x.y.z] $vIndex = $lines.FindIndex({ $_ -match '^## \[\d+\.\d+\.\d+\]' }) - if ($vIndex -lt 0) { - throw "❌ No '## [x.y.z]' header found" - } + if ($vIndex -lt 0) { throw "❌ No version header found" } - # Locate (or insert) the '### Dependency update' section + # Find or insert '### Dependency update' $depIndex = -1 for ($i = $vIndex+1; $i -lt $lines.Count; $i++) { if ($lines[$i] -match '^### Dependency update') { - $depIndex = $i - break + $depIndex = $i; break } if ($lines[$i] -match '^## ') { break } } - if ($depIndex -eq -1) { $lines.Insert($vIndex+1, '### Dependency update') - $depIndex = $vIndex + 1 + $depIndex = $vIndex+1 } - # Insert our entry + # Insert the new line $lines.Insert($depIndex+1, $entry) - Set-Content -Path $changelog -Value $lines + Set-Content -Path $path -Value $lines - Write-Host "✅ Inserted into CHANGELOG.md:" + Write-Host "✅ Changelog entry inserted:" Write-Host " $entry" - - name: Commit & push (if not dry-run) - if: steps.extract.outputs.dryRun != 'true' + - 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.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 }}"