Skip to content

Commit

Permalink
Add new workflow to fixup backports for release notes
Browse files Browse the repository at this point in the history
The Mergify-generated backports do not currently include the information
needed by the release notes generation automation. This new workflow
will copy such information over to backport PRs.
  • Loading branch information
jackkoenig committed May 5, 2023
1 parent 7b57e59 commit 9707e9b
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions .github/workflows/backport-fixup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Fixes up Mergify-created backport PRs to include necessary labels and other
# information for release notes generation

name: Backport Fixup

on:
# TODO delete this on push
pull_request:
# TODO only run on types opened
#types: [opened]
# TODO remove this branches check
branches:
- 'backport-fixup'
workflow_dispatch:
inputs:
pr:
description: 'Number of the Pull Request to Fixup'
require: true

permissions:
pull-requests: write
contents: write

jobs:
resolve_prs:
name: Resolve PRs
runs-on: ubuntu-latest
# If triggering PR actually is a backport, then original_pr will be set
outputs:
backport_pr: ${{ steps.backport_pr.outputs.pr }}
original_pr: ${{ steps.dowork.outputs.pr }}

steps:
- name: Figure out backport PR number
id: backport
run: |
#if [[ -z "${{ inputs.pr }}" ]]; then
# echo "pr=${{ github.event.number }}" >> "$GITHUB_OUTPUT"
#else
# echo "pr=${{ inputs.pr }}" >> "$GITHUB_OUTPUT"
#fi
# TODO uncomment above, this is for development
echo "pr=3218" >> "$GITHUB_OUTPUT"
- name: Figure out original PR number (if one exists)
id: original
run: |
BP_PR=${{ steps.backport.outputs.pr }}
TITLE=$(gh pr view --json title --jq '.title' $BP_PR)
if [[ "$TITLE" =~ \(backport\ \#([0-9]+)\) ]]; then
echo "pr=${BASH_REMATCH[1]}" >> "$GITHUB_OUTPUT"
fi
fixup_backport:
name: Fixup the backport PR
runs-on: ubuntu-latest
needs: [resolve_prs]
if: ${{ needs.resolve_prs.outputs.original_pr }}

steps:
- name: Copy over labels
run: |
BP_PR=${{ needs.resolve_prs.outputs.backport_pr }}
ORIG_PR=${{ needs.resolve_prs.outputs.original_pr }}
LABELS=$(gh pr view --json labels --jq '.labels | .[].name | select(. != "Backported")' $ORIG_PR)
for label in $LABELS; do
gh pr edit $BP_PR --add-label $label
done
- id: Copy over body
run: |
BP_PR=${{ needs.resolve_prs.outputs.backport_pr }}
ORIG_PR=${{ needs.resolve_prs.outputs.original_pr }}
gh pr view --json body --jq '.body' $ORIG_PR > orig_body.txt
gh pr view --json body --jq '.body' $BP_PR > bp_body.txt
if grep -q '# Original PR Body' bp_body.txt; then
# Copy BP PR body but remove original PR body from bottom
sed '/# Original PR Body/q' bp_body.txt > new_bp_body.txt
echo "" >> new_bp_body.txt
else
cp bp_body.txt new_bp_body.txt
echo -e "\n----\n\n# Original PR Body\n" >> new_bp_body.txt
fi
cat orig_body.txt >> new_bp_body.txt
gh pr edit $BP_PR --body-file new_bp_body.txt

0 comments on commit 9707e9b

Please sign in to comment.