forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 1
209 lines (183 loc) · 8.08 KB
/
detect-breaking-changes-report.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
name: Levitate / Report breaking changes
on:
workflow_run:
workflows: ["Levitate / Detect breaking changes"]
types: [completed]
permissions:
pull-requests: write
jobs:
notify:
name: Report
runs-on: ubuntu-latest
env:
ARTIFACT_NAME: 'levitate' # The name of the artifact that we would like to download
ARTIFACT_FOLDER: '${{ github.workspace }}/tmp' # The name of the folder where we will download the artifact to
permissions:
contents: read
issues: write
pull-requests: write
steps:
- uses: actions/checkout@v3
# Download artifact (as a .zip archive)
- name: 'Download artifact'
uses: actions/github-script@v6
env:
RUN_ID: ${{ github.event.workflow_run.id }}
with:
script: |
const fs = require('fs');
const { owner, repo } = context.repo;
const runId = process.env.RUN_ID;
const artifactName = process.env.ARTIFACT_NAME;
const artifactFolder = process.env.ARTIFACT_FOLDER;
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner,
repo,
run_id: runId,
});
const artifact = artifacts.data.artifacts.find(a => a.name === artifactName);
if (!artifact) {
throw new Error(`Could not find artifact ${ artifactName } in workflow (${ runId })`);
}
const download = await github.rest.actions.downloadArtifact({
owner,
repo,
artifact_id: artifact.id,
archive_format: 'zip',
});
fs.mkdirSync(artifactFolder, { recursive: true });
fs.writeFileSync(`${ artifactFolder }/${ artifactName }.zip`, Buffer.from(download.data));
# Unzip artifact
- name: Unzip artifact
run: unzip "${ARTIFACT_FOLDER}/${ARTIFACT_NAME}.zip" -d "${ARTIFACT_FOLDER}"
# Parse the artifact and register fields as step output variables
# (All fields in the JSON will be available as ${{ steps.levitate-run.outputs.<field-name> }}
- name: Parsing levitate result
uses: actions/github-script@v6
id: levitate-run
with:
script: |
const filePath = `${ process.env.ARTIFACT_FOLDER }/result.json`;
const script = require('./.github/workflows/scripts/json-file-to-job-output.js');
await script({ core, filePath });
# Skip - print a message if the "Detect" workflow was skipped
- name: Check if the workflow should be skipped
if: steps.levitate-run.outputs.shouldSkip == 'true'
run: echo "Skipping."
# Check if label exists
- name: Check if "levitate breaking change" label exists
id: does-label-exist
if: steps.levitate-run.outputs.shouldSkip != 'true'
uses: actions/github-script@v6
env:
PR_NUMBER: ${{ github.event.workflow_run.pull_requests[0].number }}
with:
script: |
const { data } = await github.rest.issues.listLabelsOnIssue({
issue_number: process.env.PR_NUMBER,
owner: context.repo.owner,
repo: context.repo.repo,
});
const labels = data.map(({ name }) => name);
const doesExist = labels.includes('levitate breaking change');
return doesExist ? 1 : 0;
# Comment on the PR
- name: Comment on PR
if: steps.levitate-run.outputs.exit_code == 1 && steps.levitate-run.outputs.shouldSkip != 'true'
uses: marocchino/sticky-pull-request-comment@v2
with:
number: ${{ steps.levitate-run.outputs.pr_number }}
message: |
⚠️ **Possible breaking changes**
_(Open the links below in a new tab to go to the correct steps)_
${{ steps.levitate-run.outputs.message }}
[Console output](${{ steps.levitate-run.outputs.job_link }})
[Read our guideline](https://github.com/grafana/grafana/blob/main/contribute/breaking-changes-guide.md)
# Remove comment from the PR (no more breaking changes)
- name: Remove comment from PR
if: steps.levitate-run.outputs.exit_code == 0 && steps.levitate-run.outputs.shouldSkip != 'true'
uses: marocchino/sticky-pull-request-comment@v2
with:
number: ${{ steps.levitate-run.outputs.pr_number }}
delete: true
# Posts a notification to Slack if a PR has a breaking change and it did not have a breaking change before
- name: Post to Slack
id: slack
if: steps.levitate-run.outputs.exit_code == 1 && steps.does-label-exist.outputs.result == 0 && steps.levitate-run.outputs.shouldSkip != 'true' && env.HAS_SECRETS
uses: slackapi/[email protected]
with:
payload: |
{
"pr_link": "https://github.com/grafana/grafana/pull/${{ steps.levitate-run.outputs.pr_number }}",
"pr_number": "${{ steps.levitate-run.outputs.pr_number }}",
"job_link": "${{ steps.levitate-run.outputs.job_link }}",
"reporting_job_link": "${{ github.event.workflow_run.html_url }}",
"message": "${{ steps.levitate-run.outputs.message }}"
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_LEVITATE_WEBHOOK_URL }}
HAS_SECRETS: ${{ (github.repository == 'grafana/grafana' || secrets.SLACK_LEVITATE_WEBHOOK_URL != '') || '' }}
# Add the label
- name: Add "levitate breaking change" label
if: steps.levitate-run.outputs.exit_code == 1 && steps.does-label-exist.outputs.result == 0 && steps.levitate-run.outputs.shouldSkip != 'true'
uses: actions/github-script@v6
env:
PR_NUMBER: ${{ steps.levitate-run.outputs.pr_number }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
await github.rest.issues.addLabels({
issue_number: process.env.PR_NUMBER,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['levitate breaking change']
})
# Remove label (no more breaking changes)
- name: Remove "levitate breaking change" label
if: steps.levitate-run.outputs.exit_code == 0 && steps.does-label-exist.outputs.result == 1 && steps.levitate-run.outputs.shouldSkip != 'true'
uses: actions/github-script@v6
env:
PR_NUMBER: ${{ steps.levitate-run.outputs.pr_number }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
await github.rest.issues.removeLabel({
issue_number: process.env.PR_NUMBER,
owner: context.repo.owner,
repo: context.repo.repo,
name: 'levitate breaking change'
})
# Add reviewers
# This is very weird, the actual request goes through (comes back with a 201), but does not assign the team.
# Related issue: https://github.com/renovatebot/renovate/issues/1908
- name: Add "grafana/plugins-platform-frontend" as a reviewer
if: steps.levitate-run.outputs.exit_code && steps.levitate-run.outputs.shouldSkip != 'true'
uses: actions/github-script@v6
env:
PR_NUMBER: ${{ steps.levitate-run.outputs.pr_number }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
await github.rest.pulls.requestReviewers({
pull_number: process.env.PR_NUMBER,
owner: context.repo.owner,
repo: context.repo.repo,
reviewers: [],
team_reviewers: ['grafana/plugins-platform-frontend']
});
# Remove reviewers (no more breaking changes)
- name: Remove "grafana/plugins-platform-frontend" from the list of reviewers
if: steps.levitate-run.outputs.exit_code == 0 && steps.levitate-run.outputs.shouldSkip != 'true'
uses: actions/github-script@v6
env:
PR_NUMBER: ${{ steps.levitate-run.outputs.pr_number }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
await github.rest.pulls.removeRequestedReviewers({
pull_number: process.env.PR_NUMBER,
owner: context.repo.owner,
repo: context.repo.repo,
reviewers: [],
team_reviewers: ['grafana/plugins-platform-frontend']
});