mirror of
https://github.com/grafana/grafana.git
synced 2024-11-26 10:50:37 -06:00
5283a8b13d
* chore: temporarily rename the breaking-change label assigned by Levitate * chore: use 'levitate breaking change' as a label
185 lines
6.7 KiB
YAML
185 lines
6.7 KiB
YAML
name: Levitate / Report breaking changes
|
|
|
|
on:
|
|
workflow_run:
|
|
workflows: ["Levitate / Detect breaking changes"]
|
|
types: [completed]
|
|
|
|
jobs:
|
|
notify:
|
|
name: Report
|
|
runs-on: ubuntu-latest
|
|
env:
|
|
ARTIFACT_FOLDER: '${{ github.workspace }}/tmp'
|
|
ARTIFACT_NAME: 'levitate'
|
|
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
|
|
- 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));
|
|
|
|
- name: Unzip artifact
|
|
run: unzip "${ARTIFACT_FOLDER}/${ARTIFACT_NAME}.zip" -d "${ARTIFACT_FOLDER}"
|
|
|
|
- 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 });
|
|
|
|
- name: Check if "levitate breaking change" label exists
|
|
id: does-label-exist
|
|
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;
|
|
|
|
- name: Comment on PR
|
|
if: ${{ steps.levitate-run.outputs.exit_code == 1 }}
|
|
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)
|
|
|
|
- name: Remove comment on PR
|
|
if: ${{ steps.levitate-run.outputs.exit_code == 0 }}
|
|
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 }}
|
|
uses: slackapi/slack-github-action@v1.18.0
|
|
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 }}
|
|
|
|
- name: Add "levitate breaking change" label
|
|
if: ${{ steps.levitate-run.outputs.exit_code == 1 && steps.does-label-exist.outputs.result == 0 }}
|
|
uses: actions/github-script@v6
|
|
env:
|
|
PR_NUMBER: ${{ steps.levitate-run.outputs.pr_number }}
|
|
with:
|
|
github-token: ${{ secrets.GH_BOT_ACCESS_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']
|
|
})
|
|
|
|
- name: Remove "levitate breaking change" label
|
|
if: ${{ steps.levitate-run.outputs.exit_code == 0 && steps.does-label-exist.outputs.result == 1 }}
|
|
uses: actions/github-script@v6
|
|
env:
|
|
PR_NUMBER: ${{ steps.levitate-run.outputs.pr_number }}
|
|
with:
|
|
github-token: ${{ secrets.GH_BOT_ACCESS_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'
|
|
})
|
|
|
|
# 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 == 1 }}
|
|
uses: actions/github-script@v6
|
|
env:
|
|
PR_NUMBER: ${{ steps.levitate-run.outputs.pr_number }}
|
|
with:
|
|
github-token: ${{ secrets.GH_BOT_ACCESS_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']
|
|
});
|
|
|
|
- name: Remove "grafana/plugins-platform-frontend" from the list of reviewers
|
|
if: ${{ steps.levitate-run.outputs.exit_code == 0 }}
|
|
uses: actions/github-script@v6
|
|
env:
|
|
PR_NUMBER: ${{ steps.levitate-run.outputs.pr_number }}
|
|
with:
|
|
github-token: ${{ secrets.GH_BOT_ACCESS_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']
|
|
});
|
|
|
|
|