forked from Homebrew/homebrew-core
-
Notifications
You must be signed in to change notification settings - Fork 0
198 lines (176 loc) · 7.54 KB
/
Copy pathcreate-replacement-pr.yml
File metadata and controls
198 lines (176 loc) · 7.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
name: Create replacement pull request
run-name: "Replace PR #${{ inputs.pull_request }}"
concurrency:
group: ${{ github.workflow }}-${{ github.event.inputs.pull_request }}
cancel-in-progress: false
on:
workflow_dispatch:
inputs:
pull_request:
description: Pull request number
required: true
autosquash:
description: "Squash pull request commits according to Homebrew style? (default: true)"
type: boolean
required: false
default: true
upload:
description: >
Upload bottles built from original pull request? (default: false)
Warning: This destroys status check information!
type: boolean
required: false
default: false
warn_on_upload_failure:
description: "Pass `--warn-on-upload-failure` to `brew pr-pull`? (default: false)"
type: boolean
required: false
default: false
message:
description: "Message to include when autosquashing revision bumps, deletions, and rebuilds (requires autosquash)"
required: false
env:
PR: ${{ inputs.pull_request }}
GNUPGHOME: /tmp/gnupghome
HOMEBREW_DEVELOPER: 1
HOMEBREW_NO_AUTO_UPDATE: 1
HOMEBREW_NO_INSTALL_FROM_API: 1
GH_REPO: ${{ github.repository }}
GH_NO_UPDATE_NOTIFIER: 1
GH_PROMPT_DISABLED: 1
RUN_URL: ${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id }}
REPLACEMENT_BRANCH: PR-${{ inputs.pull_request }}-${{ github.run_id }}
jobs:
create:
runs-on: ubuntu-latest
container:
image: ghcr.io/homebrew/ubuntu22.04:master
permissions:
contents: read
pull-requests: write # for `post-comment`, `gh api`, `gh pr edit`
defaults:
run:
shell: bash
steps:
- name: Post comment once started
uses: Homebrew/actions/post-comment@master
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue: ${{ env.PR }}
body: ":shipit: @${{ github.actor }} has [requested creation of a replacement PR](${{ env.RUN_URL }})."
bot_body: ":robot: An automated task has [requested creation of a replacement PR](${{ env.RUN_URL }})."
bot: github-actions[bot]
- name: Set up Homebrew
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master
with:
test-bot: false
- name: Get reviewers
id: reviewers
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
review_data="$(
gh api \
--header 'Accept: application/vnd.github+json' \
--header 'X-GitHub-Api-Version: 2022-11-28' \
"repos/$GH_REPO/pulls/$PR/reviews"
)"
reviewers="$(jq --compact-output '[.[].user.login]' <<< "$review_data")"
approved="$(jq --raw-output 'any(.[].state; .== "APPROVED")' <<< "$review_data")"
echo "reviewers=$reviewers" >> "$GITHUB_OUTPUT"
echo "approved=$approved" >> "$GITHUB_OUTPUT"
- name: Dismiss approvals
if: fromJson(steps.reviewers.outputs.approved)
uses: Homebrew/actions/dismiss-approvals@master
with:
token: ${{ secrets.HOMEBREW_GITHUB_PUBLIC_REPO_TOKEN }}
pr: ${{ env.PR }}
message: Replacement PR dispatched
- 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: git checkout -b "$REPLACEMENT_BRANCH" origin/master
- name: Set up commit signing
uses: Homebrew/actions/setup-commit-signing@master
with:
signing_key: ${{ secrets.BREWTESTBOT_GPG_SIGNING_SUBKEY }}
- name: Pull PR${{ inputs.upload && ' and upload bottles to GitHub Packages' || '' }}
working-directory: ${{ steps.set-up-homebrew.outputs.repository-path }}
env:
BREWTESTBOT_NAME_EMAIL: "${{ steps.git-user-config.outputs.name }} <${{ steps.git-user-config.outputs.email }}>"
HOMEBREW_GPG_PASSPHRASE: ${{ secrets.BREWTESTBOT_GPG_SIGNING_SUBKEY_PASSPHRASE }}
HOMEBREW_GITHUB_API_TOKEN: ${{ secrets.HOMEBREW_CORE_PUBLIC_REPO_EMAIL_TOKEN }}
HOMEBREW_GITHUB_PACKAGES_USER: brewtestbot
HOMEBREW_GITHUB_PACKAGES_TOKEN: ${{ secrets.HOMEBREW_CORE_GITHUB_PACKAGES_TOKEN }}
MESSAGE: ${{ inputs.message }}
run: |
# Don't quote arguments that might be empty; this causes errors.
brew pr-pull \
--debug \
--branch-okay \
--workflows=tests.yml \
--committer="$BREWTESTBOT_NAME_EMAIL" \
--root-url="https://ghcr.io/v2/homebrew/core" \
"${{ inputs.autosquash && '--autosquash' || '--clean' }}" \
${{ inputs.upload && '' || '--no-upload' }} \
${{ inputs.warn_on_upload_failure && '--warn-on-upload-failure' || '' }} \
${{ inputs.message && '--message="$MESSAGE"' || '' }} \
"$PR"
- name: Push commits
uses: Homebrew/actions/git-try-push@master
with:
token: ${{ secrets.HOMEBREW_GITHUB_PUBLIC_REPO_TOKEN }}
directory: ${{ steps.set-up-homebrew.outputs.repository-path }}
branch: ${{ env.REPLACEMENT_BRANCH }}
env:
GIT_COMMITTER_NAME: ${{ steps.git-user-config.outputs.name }}
GIT_COMMITTER_EMAIL: ${{ steps.git-user-config.outputs.email }}
HOMEBREW_GPG_PASSPHRASE: ${{ secrets.BREWTESTBOT_GPG_SIGNING_SUBKEY_PASSPHRASE }}
- name: Open replacement pull request
id: create-pr
working-directory: ${{ steps.set-up-homebrew.outputs.repository-path }}
env:
GH_TOKEN: ${{ secrets.HOMEBREW_GITHUB_PUBLIC_REPO_TOKEN }}
REVIEWERS: ${{ join(fromJson(steps.reviewers.outputs.reviewers)) }}
LABELS: ${{ inputs.upload && 'CI-published-bottle-commits' || '' }}
run: |
cat <<MESSAGE > body.txt
Created by [\`create-replacement-pr.yml\`]($RUN_URL)
-----
Closes #$PR
MESSAGE
gh pr create \
--base "$GITHUB_REF" \
--title "Replacement for #$PR"\
--body-file body.txt \
--head "$BOTTLE_BRANCH" \
--reviewer "$REVIEWERS" \
--label "$LABELS"
pull_number="$(gh pr list --head "$BOTTLE_BRANCH" --limit 1 --json number --jq '.[].number')"
echo "pull_number=$pull_number" >> "$GITHUB_OUTPUT"
- name: Label PR
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh pr edit --add-label automerge-skip --add-label superseded "$PR"
- name: Post comment on success
uses: Homebrew/actions/post-comment@master
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue: ${{ env.PR }}
body: ":white_check_mark: @${{ github.actor }} replacement PR created at #${{ steps.create-pr.outputs.pull_number }}."
bot_body: ":white_check_mark: Replacement PR created at #${{ steps.create-pr.outputs.pull_number }}."
bot: github-actions[bot]
- name: Post comment on failure
if: ${{ !success() }}
uses: Homebrew/actions/post-comment@master
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue: ${{ env.PR }}
body: ":warning: @${{ github.actor }} replacement PR creation [failed](${{ env.RUN_URL }}). CC @carlocab"
bot_body: ":warning: Replacement PR creation [failed](${{ env.RUN_URL }}). CC @carlocab"
bot: github-actions[bot]