forked from ilysenko/codex-desktop-linux
-
Notifications
You must be signed in to change notification settings - Fork 0
166 lines (151 loc) · 5.12 KB
/
Copy pathmanage-labels.yml
File metadata and controls
166 lines (151 loc) · 5.12 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
name: Manage repository labels
run-name: Labels ${{ inputs.operation }} by @${{ github.actor }}
on:
workflow_dispatch:
inputs:
operation:
description: Plan triage and catalog changes, converge labels, or retire obsolete labels
required: true
default: plan
type: choice
options:
- plan
- apply
- retire
confirmation:
description: Enter APPLY or RETIRE for the matching write operation
required: false
type: string
permissions: {}
concurrency:
group: repository-label-governance
cancel-in-progress: false
jobs:
plan:
if: inputs.operation == 'plan'
name: plan labels
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: read
issues: read
pull-requests: read
steps:
- name: Check out trusted governance code
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
ref: ${{ github.event.repository.default_branch }}
persist-credentials: false
- name: Validate read-only operation and policy
env:
CONFIRMATION: ${{ inputs.confirmation }}
run: |
set -euo pipefail
test -z "$CONFIRMATION" || {
echo "Plan requires an empty confirmation." >&2
exit 2
}
node scripts/ci/manage-labels.js --check
- name: Show the live plan
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
node scripts/ci/manage-labels.js --repo "$GITHUB_REPOSITORY"
- name: Record the result
env:
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
run: |
set -euo pipefail
{
echo "## Repository label governance"
echo
echo "- Operation: \`plan\`"
echo "- Trusted ref: \`$DEFAULT_BRANCH\`"
echo "- Result: read-only; no repository label was changed."
} >> "$GITHUB_STEP_SUMMARY"
mutate:
if: inputs.operation != 'plan'
name: ${{ inputs.operation }} labels
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: read
issues: write
pull-requests: write
steps:
# A write-capable dispatch must run only code already reviewed on the
# default branch, even when the dispatcher selects another ref in the UI.
- name: Check out trusted governance code
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
ref: ${{ github.event.repository.default_branch }}
persist-credentials: false
- name: Validate write operation and policy
env:
CONFIRMATION: ${{ inputs.confirmation }}
OPERATION: ${{ inputs.operation }}
run: |
set -euo pipefail
case "$OPERATION:$CONFIRMATION" in
apply:APPLY|retire:RETIRE) ;;
*)
echo "Use APPLY for apply or RETIRE for retire." >&2
exit 2
;;
esac
node scripts/ci/manage-labels.js --check
- name: Show the live plan
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
node scripts/ci/manage-labels.js --repo "$GITHUB_REPOSITORY"
- name: Capture the pre-change audit snapshot
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
node scripts/ci/manage-labels.js \
--repo "$GITHUB_REPOSITORY" \
--snapshot "$RUNNER_TEMP/repository-labels-before.json"
- name: Preserve the pre-change audit snapshot
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: repository-labels-before-${{ github.run_id }}
path: ${{ runner.temp }}/repository-labels-before.json
if-no-files-found: error
retention-days: 90
- name: Converge desired labels and migrate associations
if: inputs.operation == 'apply'
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
node scripts/ci/manage-labels.js \
--repo "$GITHUB_REPOSITORY" \
--apply \
--confirm APPLY
- name: Retire obsolete labels
if: inputs.operation == 'retire'
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
node scripts/ci/manage-labels.js \
--repo "$GITHUB_REPOSITORY" \
--retire "$RUNNER_TEMP/repository-labels-before.json" \
--confirm RETIRE
- name: Record the result
env:
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
OPERATION: ${{ inputs.operation }}
run: |
set -euo pipefail
{
echo "## Repository label governance"
echo
echo "- Operation: \`$OPERATION\`"
echo "- Trusted ref: \`$DEFAULT_BRANCH\`"
echo "- Result: completed with a pre-change audit snapshot."
} >> "$GITHUB_STEP_SUMMARY"