-
Notifications
You must be signed in to change notification settings - Fork 9
176 lines (160 loc) · 6.01 KB
/
owners-redhat.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
name: Red Hat OWNERS Files
# On OWNERS file submissions, this workflow will check the path and the
# contents of the file to make sure it matches expectations for Red Hat
# submissions.
on:
pull_request_target:
paths:
- charts/redhat/**/OWNERS
- charts/community/redhat/**/OWNERS
env:
SUCCESS_LABEL: redhat-owners-content-ok
jobs:
gather-metadata:
name: Gather Metadata From Path
outputs:
category: ${{ steps.gather-metadata.outputs.category }}
organization: ${{ steps.gather-metadata.outputs.organization }}
chartname: ${{ steps.gather-metadata.outputs.chart-name }}
runs-on: ubuntu-22.04
steps:
- name: Clean up stale label
uses: actions/github-script@v7
continue-on-error: true
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const successLabel = '${{ env.SUCCESS_LABEL }}';
try {
await github.issues.removeLabel({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: successLabel,
})
} catch (error) {
// a 404 indicates the label isn't here
if (error.status == 404) {
console.log('The issue did not have the label');
return 0;
}
throw error
}
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install Python CI tooling
working-directory: scripts
run: |
make venv.tools
- name: Gather Metadata
id: gather-metadata
env:
API_URL: ${{ github.event.pull_request._links.self.href }}
BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
run: |
./scripts/venv.tools/bin/extract-metadata-from-pr \
--emit-to-github-output \
${{ env.API_URL }}
ensure-prefix-in-path:
name: Ensure chart name prefix
runs-on: ubuntu-22.04
needs: [gather-metadata]
steps:
- name: Confirm Prefix
id: confirm-prefix
run: echo "${{ needs.gather-metadata.outputs.chartname }}" | grep "^redhat-"
ensure-owners-file-contents:
name: Ensure OWNERS file contents is valid
runs-on: ubuntu-22.04
needs: [gather-metadata]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install Python CI tooling
working-directory: scripts
run: |
make venv.tools
# Only used to assert content of the OWNERS file.
- name: Checkout Pull Request
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
token: ${{ secrets.BOT_TOKEN }}
fetch-depth: 0
path: "pr-branch"
- name: Assert Owners File Content
id: assert-content
working-directory: pr-branch
env:
CATEGORY: ${{ needs.gather-metadata.outputs.category }}
ORGANIZATION: ${{ needs.gather-metadata.outputs.organization }}
CHARTNAME: ${{ needs.gather-metadata.outputs.chartname }}
run: |
../scripts/venv.tools/bin/assert-redhat-owners-file-meta \
"${CATEGORY}" \
"${ORGANIZATION}" \
"${CHARTNAME}"
notify-on-failure:
name: Notify on failure
runs-on: ubuntu-22.04
needs: [ensure-prefix-in-path, ensure-owners-file-contents]
if: failure() && (needs.ensure-prefix-in-path.result == 'failure' || needs.ensure-owners-file-contents.result == 'failure')
steps:
- name: Send PR Comment
uses: actions/github-script@v7
env:
PREFIX_CHECK_RESULT: ${{ needs.ensure-prefix-in-path.result != '' && needs.ensure-prefix-in-path.result || 'unknown' }}
CONTENT_CHECK_RESULT: ${{ needs.ensure-owners-file-contents.result != '' && needs.ensure-owners-file-contents.result || 'unknown' }}
BUILD_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const prefixCheckResult = '${{ env.PREFIX_CHECK_RESULT }}';
const contentCheckResult = '${{ env.CONTENT_CHECK_RESULT }}';
const buildURL='${{ env.BUILD_URL }}';
var comment = '### :x: Red Hat OWNERS File Content and Path Check';
if (prefixCheckResult == 'failure') {
comment = comment.concat('\n\n', 'The chart name in your submission path looks incorrect!');
}
if (contentCheckResult == 'failure') {
comment = comment.concat('\n\n', 'The content of your OWNERS file looks incorrect!');
}
comment = comment.concat('\n\n', `Check your [workflow run](${buildURL}) for more information.`);
var issue_number = ${{ github.event.number }};
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: Number(issue_number),
body: comment
});
label-on-success:
name: Label On Success
continue-on-error: true
needs: [ensure-prefix-in-path, ensure-owners-file-contents]
runs-on: ubuntu-22.04
env:
PR: ${{ github.event.number }}
if: success()
steps:
- name: Label PR
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issue_number = ${{ env.PR }};
const successLabel = '${{ env.SUCCESS_LABEL }}';
github.rest.issues.addLabels({
issue_number: Number(issue_number),
owner: context.repo.owner,
repo: context.repo.repo,
labels: [successLabel],
});