mirror of https://github.com/grafana/grafana
Chore: change triggering of the detect-breaking-changes Github flow (#43188)
* chore: only run the breaking-changes flow on pull requests * chore: run the detect-breaking-changes flow on opening a PR * chore: use * Wip * Wip * Wip * Wip * Wip * Wip * Wip * Wip * Wip * Wip * Wip * Wip * Wip * Wip * Wip * Wip * Wip * trying to get workflow split running. * trying to trigger workflow. * trying to trigger. * Splits levitate job into two workflows. Co-authored-by: Marcus Andersson <marcus.andersson@grafana.com>pull/43470/head^2
parent
1695468de1
commit
8ed5b95f42
@ -0,0 +1,49 @@ |
||||
name: Levitate / Detect breaking changes |
||||
|
||||
on: pull_request |
||||
|
||||
jobs: |
||||
build: |
||||
name: Detect |
||||
runs-on: ubuntu-latest |
||||
|
||||
steps: |
||||
- uses: actions/checkout@v2 |
||||
|
||||
- name: Setup environment |
||||
uses: actions/setup-node@v2 |
||||
with: |
||||
node-version: '16' |
||||
|
||||
- name: Get link for the Github Action job |
||||
id: job |
||||
uses: actions/github-script@v5 |
||||
with: |
||||
script: | |
||||
const script = require('./.github/workflows/scripts/pr-get-job-link.js') |
||||
await script({github, context, core}) |
||||
|
||||
- name: Install dependencies |
||||
run: yarn install --immutable |
||||
|
||||
- name: Build packages |
||||
run: yarn packages:build |
||||
|
||||
- name: Detect breaking changes |
||||
id: breaking-changes |
||||
run: ./scripts/check-breaking-changes.sh |
||||
env: |
||||
FORCE_COLOR: 3 |
||||
GITHUB_JOB_LINK: ${{ steps.job.outputs.link }} |
||||
GITHUB_STEP_NUMBER: 7 |
||||
|
||||
- name: Persisting the check output |
||||
run: | |
||||
mkdir -p ./levitate |
||||
echo "{ \"exit_code\": ${{ steps.breaking-changes.outputs.is_breaking }}, \"message\": \"${{ steps.breaking-changes.outputs.mesage }}\", \"job_link\": \"${{ steps.job.outputs.link }}\" }" > ./levitate/result.json |
||||
|
||||
- name: Upload check output as artifact |
||||
uses: actions/upload-artifact@v2 |
||||
with: |
||||
name: levitate |
||||
path: levitate/ |
||||
@ -0,0 +1,45 @@ |
||||
module.exports = async ({ github, context, core, runId, artifactName }) => { |
||||
try { |
||||
const AdmZip = require('adm-zip'); |
||||
const fs = require('fs'); |
||||
|
||||
const { owner, repo } = context.repo; |
||||
const { data } = await github.rest.actions.listWorkflowRunArtifacts({ |
||||
owner,
|
||||
repo,
|
||||
run_id: runId, |
||||
}); |
||||
|
||||
const artifact = data.artifacts.find(a => a.name === artifactName); |
||||
|
||||
if (!artifact) { |
||||
throw new Error(`Could not find artifact ${artifactName} in workflow (${runId})`); |
||||
} |
||||
|
||||
const zip = await github.rest.actions.downloadArtifact({ |
||||
owner, |
||||
repo, |
||||
artifact_id: artifact.id, |
||||
archive_format: "zip", |
||||
}); |
||||
|
||||
const dir = `./tmp/${artifactName}`; |
||||
await mkdirRecursive(fs, dir); |
||||
|
||||
const admZip = new AdmZip(Buffer.from(zip.data)); |
||||
admZip.extractAllTo(dir, true); |
||||
|
||||
return dir; |
||||
} catch (error) { |
||||
core.restFailed(error.message); |
||||
} |
||||
} |
||||
|
||||
async function mkdirRecursive(fs, path) { |
||||
return new Promise((resolve, reject) => { |
||||
fs.mkdir(path, { recursive: true }, (error) => { |
||||
if (error) return reject(error); |
||||
return resolve(); |
||||
}); |
||||
}); |
||||
} |
||||
@ -0,0 +1,27 @@ |
||||
module.exports = async ({ core, filePath }) => { |
||||
try { |
||||
const fs = require('fs'); |
||||
const content = await readFile(fs, filePath); |
||||
const result = JSON.parse(content); |
||||
|
||||
core.startGroup('Parsing json file...'); |
||||
|
||||
for (const property in result) { |
||||
core.info(`${property} <- ${result[property]}`); |
||||
core.setOutput(property, result[property]); |
||||
} |
||||
|
||||
core.endGroup(); |
||||
} catch (error) { |
||||
core.restFailed(error.message); |
||||
} |
||||
} |
||||
|
||||
async function readFile(fs, path) { |
||||
return new Promise((resolve, reject) => { |
||||
fs.readFile(path, (error, data) => { |
||||
if (error) return reject(error); |
||||
return resolve(data); |
||||
}); |
||||
}); |
||||
} |
||||
@ -0,0 +1,9 @@ |
||||
|
||||
module.exports = async ({ github, context, core }) => { |
||||
const { owner, repo } = context.repo; |
||||
const url = `https://api.github.com/repos/${owner}/${repo}/actions/runs/${context.runId}/jobs` |
||||
const result = await github.request(url) |
||||
const link = `https://github.com/grafana/grafana/runs/${result.data.jobs[0].id}?check_suite_focus=true`; |
||||
|
||||
core.setOutput('link', link); |
||||
} |
||||
Loading…
Reference in new issue