-
-
Notifications
You must be signed in to change notification settings - Fork 17
147 lines (129 loc) · 5.25 KB
/
Copy pathpublish.yml
File metadata and controls
147 lines (129 loc) · 5.25 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
---
name: brew pr-pull
permissions: {}
on:
pull_request_target:
types:
- labeled
jobs:
pr-pull:
if: |
github.event.label.name == 'pr-pull' &&
github.event.pull_request.state == 'open' &&
!contains(github.event.pull_request.labels.*.name, 'bottle-published')
runs-on: ubuntu-24.04
permissions:
actions: read
checks: read
contents: write
issues: read
packages: write
pull-requests: write
steps:
- name: Comment on PR
uses: mshick/add-pr-comment@ec328af66588ab8f77cdeb2c264f14aba45bbf59 # v3.12
with:
repo-token: ${{ secrets.GH_BOT_TOKEN }}
message: >
⚠️ **Important**: This PR is being processed to add bottles.
Please **do not push any changes** to this PR branch as it may cause conflicts or issues with the
bottle publishing process.
If you need to make changes:
1. Mark this PR as draft
2. Wait for the
[publish workflow](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
to complete
3. Make your changes after the bottles have been added
- name: Set up Homebrew
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@main
with:
stable: false
# Homebrew's Linux sandbox requires bwrap on PATH before brew pr-pull runs brew doctor.
# The sysctls enable the rootless user namespaces that bwrap needs to create the sandbox.
- name: Set up Homebrew Linux sandbox
if: runner.os == 'Linux'
run: |
brew install bubblewrap
sudo sysctl -w kernel.unprivileged_userns_clone=1
sudo sysctl -w user.max_user_namespaces=28633
sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0 || true
- name: Set up git
uses: Homebrew/actions/git-user-config@main
with:
username: ${{ vars.GH_BOT_NAME }}
- name: Get PR data
id: pr-data
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number
});
const data = pr.data;
const branch = data.head.ref;
const remoteBranch = branch;
const remote = data.head.repo.clone_url;
const headRepoOwner = data.head.repo.owner.login;
const isFork = data.head.repo.fork;
const finalBranch = isFork ? `${headRepoOwner}-${branch}` : branch;
core.setOutput('branch', finalBranch);
core.setOutput('remote_branch', remoteBranch);
core.setOutput('remote', remote);
- name: Checkout PR branch
working-directory: ${{ steps.set-up-homebrew.outputs.repository-path }}
env:
BRANCH: ${{ steps.pr-data.outputs.branch }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PULL_REQUEST: ${{ github.event.pull_request.number }}
run: gh pr checkout "${PULL_REQUEST}" --branch "${BRANCH}" --repo "${GITHUB_REPOSITORY}"
- name: Pull bottles
env:
HOMEBREW_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HOMEBREW_GITHUB_PACKAGES_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HOMEBREW_GITHUB_PACKAGES_USER: ${{ github.repository_owner }}
PULL_REQUEST: ${{ github.event.pull_request.number }}
run: |
for attempt in 1 2; do
brew pr-pull \
--branch-okay \
--committer="${{ vars.GH_BOT_NAME }} <${{ secrets.GH_BOT_EMAIL }}>" \
--debug \
--no-cherry-pick \
--tap="${GITHUB_REPOSITORY}" \
"${PULL_REQUEST}" && break
if [ "${attempt}" -lt 2 ]; then
echo "brew pr-pull failed, retrying in 30 seconds..."
sleep 30
fi
done
- name: Push commits
uses: Homebrew/actions/git-try-push@main
with:
token: ${{ secrets.GH_BOT_TOKEN }}
directory: ${{ steps.set-up-homebrew.outputs.repository-path }}
remote: ${{ steps.pr-data.outputs.remote }}
branch: ${{ steps.pr-data.outputs.branch }}
remote_branch: ${{ steps.pr-data.outputs.remote_branch }}
env:
GIT_COMMITTER_NAME: ${{ vars.GH_BOT_NAME }}
GIT_COMMITTER_EMAIL: ${{ secrets.GH_BOT_EMAIL }}
- name: Add bottle-published label
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
labels: ['bottle-published']
});
- name: Comment on PR
uses: mshick/add-pr-comment@ec328af66588ab8f77cdeb2c264f14aba45bbf59 # v3.12
with:
repo-token: ${{ secrets.GH_BOT_TOKEN }}
message: Bottles have been added to this PR.