From 2274b55ca07b5d4bfe26b8cb7bc82b0d4559ed19 Mon Sep 17 00:00:00 2001 From: Tim McCormack Date: Fri, 12 May 2023 09:38:10 -0400 Subject: [PATCH] feat: Add change-description field to upgrade-one-dep workflow (#32214) This will allow people to optionally describe the dependency upgrade without having to rewrite the auto-generated commit or edit the PR body. (The PR body isn't even guaranteed to make it into the eventual merged commit.) --- .../upgrade-one-python-dependency.yml | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/.github/workflows/upgrade-one-python-dependency.yml b/.github/workflows/upgrade-one-python-dependency.yml index b8e6a7e14c..1802fa75ac 100644 --- a/.github/workflows/upgrade-one-python-dependency.yml +++ b/.github/workflows/upgrade-one-python-dependency.yml @@ -12,6 +12,11 @@ on: description: 'Name of package to upgrade' required: true type: string + change_desc: + description: | + Description of change, for commit message and PR. (What does the new version add or fix?) + default: '' + type: string defaults: run: @@ -39,13 +44,29 @@ jobs: make upgrade-package package="$PACKAGE" - name: PR preflight + env: + CHANGE_DESC: "${{ inputs.change_desc }}" run: | if git diff --exit-code; then # Fail early (and avoid quiet failure of create-pull-request action) echo "Error: No changes, so not creating PR." | tee -a "$GITHUB_STEP_SUMMARY" exit 1 else - : # do nothing; exit code 1 means there are changes (good!) + # There are changes to commit, so prep some info for the PR. + + # This is honestly a lot to go through just to say "add two newlines + # on the end if the variable isn't empty" but I guess this is what we + # have to do to get a conditional delimiter. + if [[ -z "$CHANGE_DESC" ]]; then + echo "body_prefix=" >> "$GITHUB_ENV" + else + EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) + echo "body_prefix<<$EOF" >> "$GITHUB_ENV" + echo "$CHANGE_DESC" >> "$GITHUB_ENV" + echo "" >> "$GITHUB_ENV" + echo "" >> "$GITHUB_ENV" + echo "$EOF" >> "$GITHUB_ENV" + fi fi - name: Make a PR @@ -58,9 +79,10 @@ jobs: commit-message: | feat: Upgrade Python dependency ${{ inputs.package }} - Commit generated by workflow `${{ github.workflow_ref }}` + ${{ env.body_prefix }}Commit generated by workflow `${{ github.workflow_ref }}` title: "feat: Upgrade Python dependency ${{ inputs.package }}" - body: "PR generated by workflow `${{ github.workflow_ref }}` on behalf of @${{ github.triggering_actor }}." + body: | + ${{ env.body_prefix }}PR generated by workflow `${{ github.workflow_ref }}` on behalf of @${{ github.triggering_actor }}. assignees: "${{ github.triggering_actor }}" - name: Job summary