From 1e3cf7586206dc47dd9711998e19aac7c48966aa Mon Sep 17 00:00:00 2001 From: Levente Balogh Date: Tue, 4 Jan 2022 10:23:28 +0100 Subject: [PATCH] Github Actions: update the reporting for the levitate workflow (#43621) * chore: stop checking out the repo and use the `unzip` command * refactor: remove deprecated workflow script * refactor: add whitespace around template variable --- .../detect-breaking-changes-report.yml | 52 ++++++++++++------- .../scripts/get-workflow-run-artifact.js | 45 ---------------- 2 files changed, 34 insertions(+), 63 deletions(-) delete mode 100644 .github/workflows/scripts/get-workflow-run-artifact.js diff --git a/.github/workflows/detect-breaking-changes-report.yml b/.github/workflows/detect-breaking-changes-report.yml index 5c7c3c3f209..826cab4d615 100644 --- a/.github/workflows/detect-breaking-changes-report.yml +++ b/.github/workflows/detect-breaking-changes-report.yml @@ -9,37 +9,53 @@ jobs: notify: name: Report runs-on: ubuntu-latest + env: + ARTIFACT_FOLDER: '${{ github.workspace }}/tmp' + ARTIFACT_NAME: 'levitate' steps: - - uses: actions/checkout@v2 - - - name: Setup environment - uses: actions/setup-node@v2 - with: - node-version: 16 - - run: npm install adm-zip - - - name: Download artifact + - name: 'Download artifact' uses: actions/github-script@v5 - id: download-artifact env: - RUN_ID: ${{github.event.workflow_run.id }} + RUN_ID: ${{ github.event.workflow_run.id }} with: - result-encoding: string script: | + const fs = require('fs'); + + const { owner, repo } = context.repo; const runId = process.env.RUN_ID; - const artifactName = 'levitate'; - const script = require('./.github/workflows/scripts/get-workflow-run-artifact.js'); - return await script({ github, context, core, runId, artifactName }); + 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@v5 id: levitate-run - env: - ARTIFACT_FOLDER: ${{ steps.download-artifact.outputs.result }} with: script: | - const filePath = `${process.env.ARTIFACT_FOLDER}/result.json`; + const filePath = `${ process.env.ARTIFACT_FOLDER }/result.json`; const script = require('./.github/workflows/scripts/json-file-to-job-output.js'); await script({ core, filePath }); diff --git a/.github/workflows/scripts/get-workflow-run-artifact.js b/.github/workflows/scripts/get-workflow-run-artifact.js deleted file mode 100644 index a59276ed1d8..00000000000 --- a/.github/workflows/scripts/get-workflow-run-artifact.js +++ /dev/null @@ -1,45 +0,0 @@ -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(); - }); - }); -} \ No newline at end of file