-
Notifications
You must be signed in to change notification settings - Fork 55
288 lines (262 loc) · 10.1 KB
/
update-plugins-repo-refs.yaml
File metadata and controls
288 lines (262 loc) · 10.1 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
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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
name: Update plugins repository references
on:
workflow_dispatch:
inputs:
regexps:
description: line-separated list of regular expressions of the plugin packages to discover. An expression surrounded by single quotes is taken as a litteral package name.
type: string
required: false
default: ""
workspace-path:
description: relative path of a workspace the discovery should be focused on
type: string
required: false
default: ""
allow-workspace-addition:
description: allow creating PRs that will add workspaces
type: boolean
required: false
release-branch-pattern:
description: A regular expression that defines active release branches. If not provided, the last 2 release branches (release-x.x) will be used.
type: string
required: false
default: ""
single-branch:
description: If provided, only the specified branch will receive updates, but the release branch pattern will still be used to find the minimum target backstage version.
type: string
required: false
default: ""
pr-to-update:
description: optional PR number of a PR to update
type: string
required: false
default: ""
verbose:
description: enable verbose logs
type: boolean
required: false
default: false
debug:
description: enable debug mode in bash scripts
type: boolean
required: false
default: false
workflow_call:
inputs:
regexps:
description: line-separated list of regular expressions of the plugin packages to discover. An expression surrounded by single quotes is taken as a litteral package name.
type: string
required: false
default: ""
workspace-path:
description: relative path of a workspace the discovery should be focused on
type: string
required: false
default: ""
pr-to-update:
type: string
required: false
default: ""
allow-workspace-addition:
description: allow creating PRs that will add workspaces
type: boolean
required: false
release-branch-pattern:
description: A regular expression that defines active release branches. If not provided, the last 2 release branches (release-x.x) will be used.
type: string
required: false
default: ""
single-branch:
description: If provided, only the specified branch will receive updates, but the release branch pattern will still be used to find the minimum target backstage version.
type: string
required: false
default: ""
verbose:
description: enable verbose logs
type: boolean
required: false
default: false
debug:
description: enable debug mode in bash scripts
type: boolean
required: false
default: false
schedule:
- cron: '0 12 * * *'
- cron: '0 19 * * *'
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ inputs.pr-to-update }}
cancel-in-progress: true
jobs:
prepare:
runs-on: ubuntu-latest
name: Prepare
outputs:
regexps: ${{ steps.read-regexps.outputs.REGEXPS }}
exclude-workspaces: ${{ steps.read-exclude-patterns.outputs.EXCLUDE_WORKSPACES }}
release-branch-pattern: ${{ steps.read-release-branch-pattern.outputs.RELEASE_BRANCH_PATTERN }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Read Regexps
id: read-regexps
env:
INPUT_REGEXPS: ${{ inputs.regexps }}
shell: bash
run: |
REGEXPS="${INPUT_REGEXPS}"
if [[ "${REGEXPS}" == "" ]]
then
REGEXPS="$(cat workspace-discovery-include)"
fi
echo "Regexps of plugins to export:"
echo "$REGEXPS"
echo "REGEXPS=$(echo $REGEXPS | tr '\n' ' ')" >> $GITHUB_OUTPUT
- name: Read Exclude Patterns
id: read-exclude-patterns
shell: bash
run: |
if [[ -f workspace-discovery-exclude ]]
then
EXCLUDE_WORKSPACES="$(grep -v '^#' workspace-discovery-exclude | grep -v '^$' | tr '\n' ' ')"
else
EXCLUDE_WORKSPACES=""
fi
echo "Workspace exclude patterns: ${EXCLUDE_WORKSPACES}"
echo "EXCLUDE_WORKSPACES=${EXCLUDE_WORKSPACES}" >> $GITHUB_OUTPUT
- name: Read Release Branch Pattern
id: read-release-branch-pattern
env:
INPUT_RELEASE_BRANCH_PATTERN: ${{ inputs.release-branch-pattern }}
GH_TOKEN: ${{ github.token }}
shell: bash
run: |
RELEASE_BRANCH_PATTERN="${INPUT_RELEASE_BRANCH_PATTERN}"
if [[ "${RELEASE_BRANCH_PATTERN}" == "" ]]
then
# Get the last 2 release branch names, sorted by version, and build a regex like ^release-(1\.7|1\.8)$
RELEASE_BRANCH_PATTERN="$(gh api repos/${GITHUB_REPOSITORY}/branches --paginate | \
jq -r '[.[].name | select(test("^release-")) | sub("^release-";"")]
| sort_by(split(".") | map(tonumber))
| reverse
| .[:2]
| map(gsub("\\."; "\\."))
| "^release-(" + join("|") + ")$"')"
fi
echo "Release branch pattern: ${RELEASE_BRANCH_PATTERN}"
echo "RELEASE_BRANCH_PATTERN=${RELEASE_BRANCH_PATTERN}" >> $GITHUB_OUTPUT
update-branches:
name: Update Branches
needs: prepare
if: github.event_name != 'schedule'
uses: redhat-developer/rhdh-plugin-export-utils/.github/workflows/update-plugins-repo-refs.yaml@main
with:
regexps: ${{ needs.prepare.outputs.regexps }}
exclude-workspaces: ${{ needs.prepare.outputs.exclude-workspaces }}
workspace-path: ${{ inputs.workspace-path }}
pr-to-update: ${{ inputs.pr-to-update }}
overlay-repo: ${{ github.repository }}
release-branch-pattern: ${{ needs.prepare.outputs.release-branch-pattern }}
single-branch: ${{ inputs.single-branch }}
verbose: ${{ inputs.verbose != '' && inputs.verbose }}
debug: ${{ inputs.debug != '' && inputs.debug }}
allow-workspace-addition: ${{ inputs.allow-workspace-addition != '' && inputs.allow-workspace-addition }}
permissions:
contents: write
pull-requests: write
update-main-branch:
name: Update Main Branch
needs: prepare
if: >-
(github.event_name == 'schedule')
uses: redhat-developer/rhdh-plugin-export-utils/.github/workflows/update-plugins-repo-refs.yaml@main
with:
regexps: ${{ needs.prepare.outputs.regexps }}
exclude-workspaces: ${{ needs.prepare.outputs.exclude-workspaces }}
overlay-repo: ${{ github.repository }}
release-branch-pattern: ${{ needs.prepare.outputs.release-branch-pattern }}
single-branch: "main" # we want to update only the main branch
verbose: false
debug: false
allow-workspace-addition: true
permissions:
contents: write
pull-requests: write
label-prs:
name: Label PRs
needs: [update-branches, update-main-branch]
if: |
always() &&
(needs.update-branches.result != 'skipped' ||
needs.update-main-branch.result != 'skipped')
uses: ./.github/workflows/label-mandatory-workspace-prs.yaml
permissions:
contents: read
pull-requests: write
issues: read
collect-auto-publish-prs:
name: Collect PRs for auto-publish
needs: [update-branches, update-main-branch]
if: |
!cancelled() &&
(needs.update-branches.result == 'success' ||
needs.update-main-branch.result == 'success')
runs-on: ubuntu-latest
outputs:
pr-numbers: ${{ steps.collect.outputs.pr-numbers }}
steps:
- uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
id: collect
with:
script: |
const run = await github.rest.actions.getWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.runId,
});
const runStart = new Date(run.data.run_started_at);
const prs = await github.paginate(github.rest.pulls.list, {
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
sort: 'updated',
direction: 'desc',
});
const recentPrs = prs.filter(pr =>
pr.head.ref.startsWith('workspaces/') &&
new Date(pr.updated_at) >= runStart
);
const numbers = recentPrs.map(pr => pr.number);
core.setOutput('pr-numbers', JSON.stringify(numbers));
core.info(`Found ${numbers.length} PRs for auto-publish: ${numbers}`);
auto-publish:
name: Auto-publish PRs
needs: collect-auto-publish-prs
if: |
!cancelled() &&
needs.collect-auto-publish-prs.result == 'success' &&
needs.collect-auto-publish-prs.outputs.pr-numbers != '[]'
runs-on: ubuntu-latest
permissions:
actions: write
steps:
- name: Trigger PR Actions publish for each updated PR
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
INPUT_PR_NUMBERS: ${{ needs.collect-auto-publish-prs.outputs.pr-numbers }}
with:
script: |
const prNumbers = JSON.parse(core.getInput('pr_numbers'));
for (const prNumber of prNumbers) {
core.info(`Triggering publish for PR #${prNumber}`);
await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'pr-actions.yaml',
ref: '${{ github.ref_name }}',
inputs: {
'pr-number': String(prNumber),
'command-name': 'publish',
},
});
await new Promise(r => setTimeout(r, 2000));
}