-
Notifications
You must be signed in to change notification settings - Fork 0
341 lines (327 loc) · 11.2 KB
/
Copy pathsetup-existing-repository.yml
File metadata and controls
341 lines (327 loc) · 11.2 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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
name: Setup Existing Repository
on:
workflow_dispatch:
inputs:
repo_owner:
description: "Target owner - GitHub user or organization"
required: true
type: string
repo_name:
description: "Existing repository name"
required: true
type: string
apply_repo_settings:
description: "Apply repository settings from repo-settings.json"
required: false
default: false
type: boolean
apply_labels:
description: "Apply labels from labels-default.json"
required: false
default: false
type: boolean
apply_security_settings:
description: "Apply security settings from security-default.json"
required: false
default: false
type: boolean
ruleset_profile:
description: "Ruleset profile to apply"
required: false
default: none
type: choice
options:
- none
- minimal
- default
- coderabbit
coderabbit_mode:
description: "CodeRabbit file apply mode"
required: false
default: none
type: choice
options:
- none
- plan
- pull-request
- direct
agent_provider:
description: "AI agent instructions to apply"
required: false
default: none
type: choice
options:
- none
- copilot
- claude
- cursor
- windsurf
- codex
- all
agent_mode:
description: "Agent instruction file apply mode"
required: false
default: pull-request
type: choice
options:
- plan
- pull-request
- direct
label_policy:
description: "Label apply policy"
required: false
default: create-and-update
type: choice
options:
- create-missing
- create-and-update
target_branch:
description: "Target branch for file changes"
required: false
default: main
type: string
github_host:
description: "GitHub hostname"
required: false
default: github.com
type: string
gh_token:
description: >-
PAT fallback. Prefer GH_PAT secret or GitHub App auth for shared usage.
required: false
type: string
app_id:
description: "GitHub App ID for App-based auth"
required: false
type: string
app_owner:
description: "Owner whose GitHub App installation token should be used"
required: false
type: string
allowed_repo_owners:
description: "Optional comma-separated allowlist of target owners"
required: false
type: string
workflow_call:
inputs:
repo_owner:
required: true
type: string
repo_name:
required: true
type: string
apply_repo_settings:
required: false
default: false
type: boolean
apply_labels:
required: false
default: false
type: boolean
apply_security_settings:
required: false
default: false
type: boolean
ruleset_profile:
required: false
default: none
type: string
coderabbit_mode:
required: false
default: none
type: string
agent_provider:
required: false
default: none
type: string
agent_mode:
required: false
default: pull-request
type: string
label_policy:
required: false
default: create-and-update
type: string
target_branch:
required: false
default: main
type: string
github_host:
required: false
default: github.com
type: string
gh_token:
required: false
type: string
app_id:
required: false
type: string
app_owner:
required: false
type: string
allowed_repo_owners:
required: false
type: string
secrets:
GH_PAT:
required: false
app_private_key:
required: false
BOOTSTRAP_APP_PRIVATE_KEY:
required: false
outputs:
labels_changed:
description: Whether labels were created or updated.
value: ${{ jobs.setup-existing-repository.outputs.labels_changed }}
labels_created_count:
description: Number of labels created.
value: ${{ jobs.setup-existing-repository.outputs.labels_created_count }}
labels_updated_count:
description: Number of labels updated.
value: ${{ jobs.setup-existing-repository.outputs.labels_updated_count }}
ruleset_action:
description: "Ruleset action taken: created, updated, skipped, or empty."
value: ${{ jobs.setup-existing-repository.outputs.ruleset_action }}
ruleset_id:
description: Ruleset ID when available.
value: ${{ jobs.setup-existing-repository.outputs.ruleset_id }}
coderabbit_pull_request_url:
description: CodeRabbit setup pull request URL when created or updated.
value: ${{ jobs.setup-existing-repository.outputs.coderabbit_pull_request_url }}
agent_pull_request_url:
description: Agent instruction setup pull request URL when created or updated.
value: ${{ jobs.setup-existing-repository.outputs.agent_pull_request_url }}
jobs:
setup-existing-repository:
name: Setup Existing Repository
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
labels_changed: ${{ steps.apply_labels.outputs.changed }}
labels_created_count: ${{ steps.apply_labels.outputs.created_count }}
labels_updated_count: ${{ steps.apply_labels.outputs.updated_count }}
ruleset_action: ${{ steps.apply_ruleset.outputs.ruleset_action }}
ruleset_id: ${{ steps.apply_ruleset.outputs.ruleset_id }}
coderabbit_pull_request_url: ${{ steps.apply_coderabbit.outputs.pull_request_url }}
agent_pull_request_url: ${{ steps.apply_agent_instructions.outputs.pull_request_url }}
env:
GH_HOST: ${{ inputs.github_host || 'github.com' }}
steps:
- name: Resolve bootstrap repository
id: bootstrap-repo
shell: bash
run: |
REPO=$(printf '%s' '${{ github.workflow_ref }}' | cut -d'/' -f1,2)
echo "repository=$REPO" >> "$GITHUB_OUTPUT"
- name: Checkout bootstrap repository
uses: actions/checkout@v7
with:
repository: ${{ steps.bootstrap-repo.outputs.repository }}
ref: ${{ github.workflow_sha }}
- name: Validate explicit options
shell: bash
env:
RULESET_PROFILE: ${{ inputs.ruleset_profile }}
CODERABBIT_MODE: ${{ inputs.coderabbit_mode }}
AGENT_PROVIDER: ${{ inputs.agent_provider }}
AGENT_MODE: ${{ inputs.agent_mode }}
LABEL_POLICY: ${{ inputs.label_policy }}
run: |
set -euo pipefail
validate_choice() {
value="$1"
allowed="$2"
name="$3"
if ! printf '%s' "$allowed" | tr ' ' '\n' | grep -Fxq "$value"; then
echo "::error::Invalid $name '$value'. Allowed: $allowed"
exit 1
fi
}
validate_choice "$RULESET_PROFILE" "none minimal default coderabbit" "ruleset_profile"
validate_choice "$CODERABBIT_MODE" "none plan pull-request direct" "coderabbit_mode"
validate_choice "$AGENT_PROVIDER" "none copilot claude cursor windsurf codex all" "agent_provider"
validate_choice "$AGENT_MODE" "plan pull-request direct" "agent_mode"
validate_choice "$LABEL_POLICY" "create-missing create-and-update" "label_policy"
- name: Validate target owner
uses: ./.github/actions/validate-bootstrap-owner
with:
owner: ${{ inputs.repo_owner }}
allowed_repo_owners: ${{ inputs.allowed_repo_owners }}
- name: Resolve GitHub token
id: resolve-token
uses: ./.github/actions/resolve-gh-token
with:
gh_token: ${{ inputs.gh_token }}
gh_pat_secret: ${{ secrets.GH_PAT }}
app_id: ${{ inputs.app_id }}
app_private_key: ${{ secrets.app_private_key || secrets.BOOTSTRAP_APP_PRIVATE_KEY }}
app_owner: ${{ inputs.app_owner || inputs.repo_owner }}
- name: Apply repository settings
id: apply_repo_settings
if: inputs.apply_repo_settings == true
uses: ./.github/actions/apply-repo-settings
with:
owner: ${{ inputs.repo_owner }}
repo_name: ${{ inputs.repo_name }}
enable_repo_settings: "true"
apply_repository_settings: "true"
repo_settings_file: .github/config/repo-settings.json
manage_environments: "false"
enable_dependabot: "false"
gh_token: ${{ steps.resolve-token.outputs.token }}
- name: Apply labels
id: apply_labels
if: inputs.apply_labels == true
uses: ./.github/actions/apply-labels
with:
owner: ${{ inputs.repo_owner }}
repo_name: ${{ inputs.repo_name }}
label_file: .github/config/labels-default.json
label_policy: ${{ inputs.label_policy }}
gh_token: ${{ steps.resolve-token.outputs.token }}
- name: Apply security settings
id: apply_security_settings
if: inputs.apply_security_settings == true
uses: ./.github/actions/apply-security-settings
with:
owner: ${{ inputs.repo_owner }}
repo_name: ${{ inputs.repo_name }}
security_file: .github/config/security-default.json
gh_token: ${{ steps.resolve-token.outputs.token }}
- name: Apply repository ruleset
id: apply_ruleset
if: inputs.ruleset_profile != 'none'
uses: ./.github/actions/apply-repository-ruleset
with:
owner: ${{ inputs.repo_owner }}
repo_name: ${{ inputs.repo_name }}
ruleset_profile: ${{ inputs.ruleset_profile }}
gh_token: ${{ steps.resolve-token.outputs.token }}
- name: Apply CodeRabbit
id: apply_coderabbit
if: inputs.coderabbit_mode != 'none'
uses: ./.github/actions/apply-coderabbit
with:
owner: ${{ inputs.repo_owner }}
repo_name: ${{ inputs.repo_name }}
mode: ${{ inputs.coderabbit_mode }}
target_branch: ${{ inputs.target_branch }}
github_host: ${{ inputs.github_host }}
gh_token: ${{ steps.resolve-token.outputs.token }}
- name: Apply agent instructions
id: apply_agent_instructions
if: inputs.agent_provider != 'none'
uses: ./.github/actions/apply-agent-instructions
with:
owner: ${{ inputs.repo_owner }}
repo_name: ${{ inputs.repo_name }}
agent_provider: ${{ inputs.agent_provider }}
mode: ${{ inputs.agent_mode }}
target_branch: ${{ inputs.target_branch }}
github_host: ${{ inputs.github_host }}
gh_token: ${{ steps.resolve-token.outputs.token }}
- name: Summary
shell: bash
run: |
echo "Existing repository setup finished for ${{ inputs.repo_owner }}/${{ inputs.repo_name }}" >> "$GITHUB_STEP_SUMMARY"