-
-
Notifications
You must be signed in to change notification settings - Fork 525
188 lines (174 loc) · 6.15 KB
/
bump-dependency.yaml
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
name: Bump Deps
on:
repository_dispatch:
types: [ bump-dependency ]
jobs:
get-label:
name: Get Label
outputs:
label: ${{ steps.get-label.outputs.label }}
runs-on: ubuntu-22.04
steps:
- name: Get Label
id: get-label
env:
REPO: ${{ github.event.client_payload.dependency }}
run: |
if [ "$REPO" == "go-mysql-server" ]
then
echo "label=gms-bump" >> $GITHUB_OUTPUT
else
echo "$REPO is unsupported"
exit 1
fi
stale-bump-prs:
name: Retrieving Stale Bump PRs
needs: get-label
outputs:
stale-pulls: ${{ steps.get-stale-prs.outputs.open-pulls }}
runs-on: ubuntu-22.04
steps:
- name: Get Open Bump PRs
id: get-stale-prs
uses: actions/github-script@v6
env:
LABEL: ${{ needs.get-label.outputs.label }}
with:
debug: true
github-token: ${{ secrets.REPO_ACCESS_TOKEN }}
script: |
try {
const { LABEL } = process.env;
const { owner, repo } = context.repo;
const res = await github.rest.pulls.list({
owner,
repo,
state: 'open',
sort: 'created',
direction: 'desc',
});
const { data } = res;
const reduced = data.reduce((acc, p) => {
if (p.labels.length < 1) return acc;
let keepAlive = false;
let shouldPush = false;
for (const label of p.labels) {
if (label.name === LABEL) {
shouldPush = true;
}
if (label.name === "keep-alive") {
keepAlive = true;
}
}
if (shouldPush) {
acc.push({
number: p.number,
keepAlive,
headRef: p.head.ref,
});
}
return acc;
}, []);
console.log(reduced);
if (reduced.length > 0) core.setOutput("open-pulls", JSON.stringify(reduced));
process.exit(0);
} catch(err) {
console.log("Error:", err);
process.exit(1);
}
open-bump-pr:
needs: [get-label, stale-bump-prs]
name: Open Bump PR
runs-on: ubuntu-22.04
outputs:
latest-pr: ${{ steps.latest-pr.outputs.pr_url }}
steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.REPO_ACCESS_TOKEN || secrets.GITHUB_TOKEN }}
- name: Set up Go 1.x
uses: actions/setup-go@v3
with:
go-version: ^1.21
- name: Bump dependency
working-directory: go
run: |
go get github.com/dolthub/${{ github.event.client_payload.dependency }}@${{ github.event.client_payload.head_commit_sha }}
go mod tidy
- name: Get Assignee and Reviewer
id: get_reviewer
run: |
if [ "${{ github.event.client_payload.assignee }}" == "zachmu" ]
then
echo "reviewer=Hydrocharged" >> $GITHUB_OUTPUT
else
echo "reviewer=zachmu" >> $GITHUB_OUTPUT
fi
- name: Get short hash
id: short-sha
run: |
commit=${{ github.event.client_payload.head_commit_sha }}
short=${commit:0:8}
echo "short=$short" >> $GITHUB_OUTPUT
- name: Create and Push new branch
run: |
git config --global --add user.name "${{ github.event.client_payload.assignee }}"
git config --global --add user.email "${{ github.event.client_payload.assignee_email }}"
branchname=${{ format('{0}-{1}', github.event.client_payload.assignee, steps.short-sha.outputs.short) }}
git checkout -b "$branchname"
git add .
git commit -m "${{ format('[ga-bump-dep] Bump dependency in Dolt by {0}', github.event.client_payload.assignee) }}"
git push origin "$branchname"
- name: pull-request
uses: repo-sync/pull-request@v2
id: latest-pr
with:
source_branch: ${{ format('{0}-{1}', github.event.client_payload.assignee, steps.short-sha.outputs.short ) }}
destination_branch: "main"
github_token: ${{ secrets.REPO_ACCESS_TOKEN }}
pr_title: "[auto-bump] [no-release-notes] dependency by ${{ github.event.client_payload.assignee }}"
pr_template: ".github/markdown-templates/dep-bump.md"
pr_reviewer: ${{ steps.get_reviewer.outputs.reviewer }}
pr_assignee: ${{ github.event.client_payload.assignee }}
pr_label: ${{ needs.get-label.outputs.label }}
comment-on-stale-prs:
needs: [open-bump-pr, stale-bump-prs]
if: ${{ needs.stale-bump-prs.outputs.stale-pulls != '' }}
runs-on: ubuntu-22.04
strategy:
matrix:
pull: ${{ fromJson(needs.stale-bump-prs.outputs.stale-pulls) }}
steps:
- name: Comment/Close Stale PRs
id: get-stale-prs
uses: actions/github-script@v6
env:
PULL: ${{ toJson(matrix.pull) }}
SUPERSEDED_BY: ${{ needs.open-bump-pr.outputs.latest-pr }}
with:
debug: true
github-token: ${{ secrets.REPO_ACCESS_TOKEN }}
script: |
try {
const { owner, repo } = context.repo;
const { PULL, SUPERSEDED_BY } = process.env;
const pull = JSON.parse(PULL);
if (pull.keepAlive) process.exit(0);
console.log(`Closing open pr ${pull.number}`);
await github.rest.issues.createComment({
issue_number: pull.number,
owner,
repo,
body: `This PR has been superseded by ${SUPERSEDED_BY}`
});
await github.rest.pulls.update({
owner,
repo,
pull_number: pull.number,
state: 'closed',
});
process.exit(0);
} catch(err) {
console.log("Error:", err);
process.exit(1);
}