-
Notifications
You must be signed in to change notification settings - Fork 0
264 lines (226 loc) · 10.3 KB
/
update_pyclesperanto.yml
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
name: Update pyclEsperanto
on:
repository_dispatch:
types: [clic_update]
workflow_dispatch: # allows manual triggering
inputs:
tag:
description: 'Update to latest tag'
required: true
default: 'master'
jobs:
handle-issue:
runs-on: ubuntu-latest
outputs:
issue_number: ${{ steps.check-issues.outputs.issue_number }}
steps:
- name: Checkout repository
uses: actions/[email protected]
- name: Get release tag and store it for easy access in all jobs
id: get_release_tag
run: |
echo "${{ github.event.client_payload.release_tag || github.event.inputs.tag }}"
- name: Check if issues already exists
id: check-issues
uses: actions/[email protected]
with:
github-token: ${{ secrets.RELEASE_PAT }}
script: |
(async () => {
const releaseTag = context.payload.client_payload?.release_tag || context.payload.inputs.tag;
console.log(`Checking if issue already exists for release tag: ${releaseTag} in pyclesperanto`);
const { data: issues } = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: 'bot_playground',
labels: 'auto-update',
state: 'all'
});
const issue = issues.find(issue => issue.title === `Auto-Update to version ${releaseTag}`);
if (issue) {
console.log("Issue already exists with number: " + issue.number);
core.setOutput('issue_number', issue.number);
} else {
console.log(`No existing issue found for release tag: ${releaseTag}`);
core.setOutput('issue_number', '');
}
})();
- name: Create issue if not exists
id: create-issue
if: steps.check-issues.outputs.issue_number == ''
uses: actions/[email protected]
with:
github-token: ${{ secrets.RELEASE_PAT }}
script: |
(async () => {
const releaseTag = context.payload.client_payload?.release_tag || context.payload.inputs.tag;
console.log(`Creating new issue for release tag: ${releaseTag}`);
const { data: issue } = await github.rest.issues.create({
owner: context.repo.owner,
repo: 'bot_playground',
title: `Auto-Update to version ${releaseTag}`,
body: `This is an automated issue created by the auto-update workflow following up a new Release of CLIc.
### Release Information
- **Release Tag:** ${releaseTag}
- **Changelog:** [View Changelog](https://github.com/clEsperanto/CLIc/releases/tag/${releaseTag})
Please review the changes and update the dependencies accordingly.`,
labels: ['auto-update']
});
console.log("Created issue with number: " + issue.number);
core.setOutput('issue_number', issue.number);
})();
- name: Else reopen the issue
id: reopen-issue
if: steps.check-issues.outputs.issue_number != ''
env:
issue_number: ${{ steps.check-issues.outputs.issue_number }}
uses: actions/[email protected]
with:
github-token: ${{ secrets.RELEASE_PAT }}
script: |
(async () => {
const issue_number = process.env.issue_number;
const releaseTag = context.payload.client_payload?.release_tag || context.payload.inputs.tag;
console.log(`Adding message to existing issue with number: ${issue_number}`);
const { data: issue } = await github.rest.issues.get({
owner: context.repo.owner,
repo: 'bot_playground',
issue_number: issue_number
});
if (issue.state === 'closed') {
console.log(`Reopening closed issue with number: ${issue_number}`);
await github.rest.issues.update({
owner: context.repo.owner,
repo: 'bot_playground',
issue_number: issue_number,
state: 'open'
});
console.log(`Adding comment to reopened issue with number: ${issue_number}`);
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: 'bot_playground',
issue_number: issue_number,
body: `This is an automated issue created by the auto-update workflow following up a new Release of CLIc.
### Release Information
- **Release Tag:** ${releaseTag}
- **Changelog:** [View Changelog](https://github.com/clEsperanto/CLIc/releases/tag/${releaseTag})
Please review the changes and update the dependencies accordingly.`
});
}
core.setOutput('issue_number', issue_number);
})();
update-code:
needs: handle-issue
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/[email protected]
- name: Set up Python
uses: actions/[email protected]
with:
python-version: '3.x'
- name: Configure git
run: |
echo "Configuring git user"
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Create branch if not exists
id: check-branch
uses: actions/[email protected]
with:
github-token: ${{ secrets.RELEASE_PAT }}
script: |
const releaseTag = context.payload.client_payload?.release_tag || context.payload.inputs.tag;
const branchName = `auto-update-version-${releaseTag}`;
const { data: branches } = await github.rest.repos.listBranches({
owner: context.repo.owner,
repo: 'bot_playground',
});
const branchExists = branches.some(branch => branch.name === branchName);
if (!branchExists) {
console.log(`Creating new branch: ${branchName}`);
await github.rest.git.createRef({
owner: context.repo.owner,
repo: 'bot_playground',
ref: `refs/heads/${branchName}`,
sha: `main`,
});
} else {
console.log(`Branch already exists: ${branchName}`);
}
const { data: branchesAfter } = await github.rest.repos.listBranches({
owner: context.repo.owner,
repo: 'bot_playground',
});
console.log(branchesAfter.map(branch => branch.name));
- name: Update and push pyclesranto code
id: update-code
env:
GH_TOKEN: ${{ secrets.RELEASE_PAT }}
RELEASE_TAG: ${{ github.event.client_payload.release_tag || github.event.inputs.tag }}
run: |
echo "Clone and checkout repository to update branch"
git clone https://[email protected]/clEsperanto/bot_playground.git repoToUpdate
cd repoToUpdate
git fetch origin
git checkout auto-update-version-$RELEASE_TAG
echo "Run update script:"
python ../pyclesperanto_auto_update.py ${{ github.workspace }}/repoToUpdate $RELEASE_TAG
echo "Commit and push changes"
if [ -n "$(git status --porcelain)" ]; then
git add .
git commit -m "Update tiers to $RELEASE_TAG"
git push origin auto-update-version-$RELEASE_TAG
else
echo "No changes detected, skipping commit"
fi
shell: /usr/bin/bash -e {0}
- name: Check if PR exists
id: check-pr
uses: actions/[email protected]
with:
github-token: ${{ secrets.RELEASE_PAT }}
script: |
const releaseTag = context.payload.client_payload?.release_tag || context.payload.inputs.tag;
console.log(`Checking if PR already exists for branch: auto-update-version-${releaseTag}`);
const { data: prs } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: 'bot_playground',
state: 'open',
head: `auto-update-version-${releaseTag}`
});
if (prs.length > 0) {
console.log(`PR already exists with number: ${prs[0].number}`);
core.setOutput('pr_number', prs[0].number);
} else {
console.log(`No existing PR found for branch: auto-update-version-${releaseTag}`);
core.setOutput('pr_number', '');
}
- name: Create a PR if not
id: create-pr
if: steps.check-pr.outputs.pr_number == ''
uses: actions/[email protected]
with:
github-token: ${{ secrets.RELEASE_PAT }}
script: |
const releaseTag = context.payload.client_payload?.release_tag || context.payload.inputs.tag;
console.log(`Creating new PR for branch: auto-update-version-${releaseTag}`);
const { data: pr } = await github.rest.pulls.create({
owner: context.repo.owner,
repo: 'bot_playground',
title: `Auto-Update to version ${releaseTag}`,
head: `auto-update-version-${releaseTag}`,
base: 'main',
body: `### Automated Dependency Update
This is an automated pull request created by the auto-update workflow following up a new Release of CLIc.
**Release Tag:** ${releaseTag}
**Changelog:** [View Changelog](https://github.com/clEsperanto/CLIc/releases/tag/${releaseTag})
Closes #${{ needs.handle-issue.outputs.issue_number }}`
});
await github.rest.pulls.createReviewRequest({
owner: context.repo.owner,
repo: 'bot_playground',
pull_number: pr.number,
reviewers: ['StRigaud']
});
console.log(`Created PR with number: ${pr.number}`);
core.setOutput('pr_number', pr.number);