From 8ddfc1b74cd4a935a374857beb1b039a3e53755d Mon Sep 17 00:00:00 2001 From: Jack Koenig Date: Fri, 5 May 2023 14:22:03 -0700 Subject: [PATCH 1/2] Add new workflow to fixup backports for release notes (#3252) 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. (cherry picked from commit 86ccd1b277642560e05f294307ef6cc2f45a0f28) --- .github/workflows/backport-fixup.yml | 90 ++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 .github/workflows/backport-fixup.yml diff --git a/.github/workflows/backport-fixup.yml b/.github/workflows/backport-fixup.yml new file mode 100644 index 00000000000..b06fb3c8ddd --- /dev/null +++ b/.github/workflows/backport-fixup.yml @@ -0,0 +1,90 @@ +# Fixes up Mergify-created backport PRs to include necessary labels and other +# information for release notes generation + +name: Backport Fixup + +on: + pull_request: + types: [opened] + 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.outputs.pr }} + original_pr: ${{ steps.original.outputs.pr }} + + steps: + - uses: actions/checkout@v3 + - 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 + - name: Figure out original PR number (if one exists) + id: original + env: + GH_TOKEN: ${{ github.token }} + 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" + else + echo "$BP_PR is not a backport PR!" >> $GITHUB_STEP_SUMMARY + fi + + fixup_backport: + name: Fixup the backport PR + runs-on: ubuntu-latest + needs: [resolve_prs] + if: ${{ needs.resolve_prs.outputs.original_pr }} + + steps: + - uses: actions/checkout@v3 + - name: Copy over labels + env: + GH_TOKEN: ${{ github.token }} + 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 + - name: Copy over body + env: + GH_TOKEN: ${{ github.token }} + 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 From 2be4353b4632bb9c3e60aa1500058ca50277f94c Mon Sep 17 00:00:00 2001 From: Jack Koenig Date: Fri, 5 May 2023 14:40:21 -0700 Subject: [PATCH 2/2] Fix backport-fixup for labels with spaces (#3255) (cherry picked from commit 8f7e7e68b35696c74357ec8e3e58c7f7c3272b57) --- .github/workflows/backport-fixup.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/backport-fixup.yml b/.github/workflows/backport-fixup.yml index b06fb3c8ddd..1f396a69e51 100644 --- a/.github/workflows/backport-fixup.yml +++ b/.github/workflows/backport-fixup.yml @@ -62,10 +62,10 @@ jobs: 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 + + # Long line but the paste joining must be done right away or we run into issues with spaces in labels + LABELS=$(gh pr view --json labels --jq '.labels | .[].name | select(. != "Backported")' $ORIG_PR | paste -sd "," -) + gh pr edit $BP_PR --add-label "$LABELS" - name: Copy over body env: GH_TOKEN: ${{ github.token }}