From 12e618fe9a1db4cc92c9b2c37a7cc2b77b727abe Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Wed, 10 Jan 2024 19:25:59 +0000 Subject: [PATCH] ci(automerge): optimise inline js scripts --- .github/workflows/automerge.yml | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml index 150ee33..e61c010 100644 --- a/.github/workflows/automerge.yml +++ b/.github/workflows/automerge.yml @@ -24,25 +24,26 @@ jobs: uses: actions/github-script@v7 with: script: | - const fs = require('fs'); + const { writeFile } = require("node:fs/promises"); + const { owner, repo } = context.repo; const artifacts = await github.rest.actions.listWorkflowRunArtifacts({ - owner: context.repo.owner, - repo: context.repo.repo, + owner, + repo, run_id: ${{ github.event.workflow_run.id }}, }); - const matchArtifact = artifacts.data.artifacts.filter((artifact) => { - return artifact.name == 'pr'; - })[0]; + const matchArtifact = artifacts.data.artifacts.find( + (artifact) => artifact.name == "pr" + ); const download = await github.rest.actions.downloadArtifact({ - owner: context.repo.owner, - repo: context.repo.repo, + owner, + repo, artifact_id: matchArtifact.id, - archive_format: 'zip', + archive_format: "zip", }); - fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data)); + await writeFile("${{github.workspace}}/pr.zip", Buffer.from(download.data)); - name: Unzip artifact run: unzip pr.zip @@ -52,12 +53,14 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | - const fs = require('fs'); - const pull_number = Number(fs.readFileSync('./NR')); + const { readFile } = require("node:fs/promises"); + const { owner, repo } = context.repo; + + const pull_number = Number(await readFile("./NR", "utf8")); await github.rest.pulls.merge({ merge_method: "squash", - owner: context.repo.owner, - repo: context.repo.repo, - pull_number: pull_number, + owner, + repo, + pull_number, });