Skip to content

Commit

Permalink
create-replacement-pr: improve behaviour without autosquash
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
carlocab committed Jun 9, 2023
1 parent 72cb0f2 commit 9c4e2ef
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 20 deletions.
52 changes: 33 additions & 19 deletions .github/workflows/create-replacement-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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"' || '' }} \
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-commit-bottles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 9c4e2ef

Please sign in to comment.