From 9c4e2efc129c3d8cc485aa19c801b2136346caf0 Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Fri, 9 Jun 2023 13:18:40 +0800 Subject: [PATCH] create-replacement-pr: improve behaviour without autosquash When we don't need to autosquash a PR, we can reuse the previously built bottles without destroying status check information, so let's do that to minimise the number of times we have to re-run CI. --- .github/workflows/create-replacement-pr.yml | 52 +++++++++++++------- .github/workflows/publish-commit-bottles.yml | 2 +- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/.github/workflows/create-replacement-pr.yml b/.github/workflows/create-replacement-pr.yml index 0e22f1c75e52e..b793df960bea3 100644 --- a/.github/workflows/create-replacement-pr.yml +++ b/.github/workflows/create-replacement-pr.yml @@ -19,7 +19,7 @@ on: upload: description: > Upload bottles built from original pull request? (default: false) - Warning: This destroys status check information! + Warning: This destroys status check information when used with autosquash! type: boolean required: false default: false @@ -72,23 +72,6 @@ jobs: with: test-bot: false - - name: Configure Git user - id: git-user-config - uses: Homebrew/actions/git-user-config@master - with: - username: BrewTestBot - - - name: Checkout replacement PR branch - working-directory: ${{ steps.set-up-homebrew.outputs.repository-path }} - run: | - if git ls-remote --exit-code --heads origin "$REPLACEMENT_BRANCH" - then - echo "::error ::Branch $REPLACEMENT_BRANCH already exists!" - exit 1 - fi - - git checkout -b "$REPLACEMENT_BRANCH" origin/master - - name: Get reviewers id: reviewers env: @@ -107,6 +90,37 @@ jobs: echo "reviewers=$reviewers" >> "$GITHUB_OUTPUT" echo "approved=$approved" >> "$GITHUB_OUTPUT" + - name: Check approval if needed + if: inputs.upload && !fromJson(steps.reviewers.outputs.approved) + run: | + echo "::error ::Refusing to upload bottles because PR #$PR is not approved!" + exit 1 + + - name: Configure Git user + id: git-user-config + uses: Homebrew/actions/git-user-config@master + with: + username: BrewTestBot + + - name: Checkout PR branch + if: ${{ !inputs.autosquash }} + working-directory: ${{steps.set-up-homebrew.outputs.repository-path}} + env: + GH_TOKEN: ${{secrets.GITHUB_TOKEN}} + run: gh pr checkout "$PR" + + - name: Checkout replacement PR branch + working-directory: ${{ steps.set-up-homebrew.outputs.repository-path }} + env: + START_POINT: ${{ inputs.autosquash && 'origin/master' || 'HEAD' }} + run: | + if git ls-remote --exit-code --heads origin "$REPLACEMENT_BRANCH" + then + echo "::error ::Branch $REPLACEMENT_BRANCH already exists!" + exit 1 + fi + git checkout -b "$REPLACEMENT_BRANCH" "$START_POINT" + - name: Dismiss approvals if: fromJson(steps.reviewers.outputs.approved) uses: Homebrew/actions/dismiss-approvals@master @@ -137,7 +151,7 @@ jobs: --workflows=tests.yml \ --committer="$BREWTESTBOT_NAME_EMAIL" \ --root-url="https://ghcr.io/v2/homebrew/core" \ - "${{ inputs.autosquash && '--autosquash' || '--clean' }}" \ + ${{ inputs.autosquash && '--autosquash' || '--clean --no-cherry-pick' }} \ ${{ inputs.upload && '' || '--no-upload' }} \ ${{ inputs.warn_on_upload_failure && '--warn-on-upload-failure' || '' }} \ ${{ inputs.message && '--message="$MESSAGE"' || '' }} \ diff --git a/.github/workflows/publish-commit-bottles.yml b/.github/workflows/publish-commit-bottles.yml index 7cc308ea29271..b555045760ff0 100644 --- a/.github/workflows/publish-commit-bottles.yml +++ b/.github/workflows/publish-commit-bottles.yml @@ -191,7 +191,7 @@ jobs: --ref "$GITHUB_REF_NAME" \ --field pull_request="$PR" \ --field autosquash="$AUTOSQUASH" \ - --field upload=false \ + --field upload='${{ !inputs.autosquash }}' \ --field warn_on_upload_failure=false \ --field message="$MESSAGE"