From 3bde4aa751c8bdf4f23edc86455b22061480583a Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Mon, 18 Nov 2024 13:34:43 +0000 Subject: chore: use Biome VCS ignore file (#12465) --- .github/scripts/utils.mjs | 86 ++++++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 46 deletions(-) (limited to '.github/scripts/utils.mjs') diff --git a/.github/scripts/utils.mjs b/.github/scripts/utils.mjs index da5befc2c..9aaa383d8 100644 --- a/.github/scripts/utils.mjs +++ b/.github/scripts/utils.mjs @@ -1,59 +1,53 @@ -import * as fs from 'node:fs' -import * as os from 'node:os' -import * as crypto from 'node:crypto' +import * as fs from 'node:fs'; +import * as os from 'node:os'; +import * as crypto from 'node:crypto'; /** Based on https://github.com/actions/toolkit/blob/4e3b068ce116d28cb840033c02f912100b4592b0/packages/core/src/file-command.ts */ export function setOutput(key, value) { - const filePath = process.env['GITHUB_OUTPUT'] || '' - if (filePath) { - return issueFileCommand('OUTPUT', prepareKeyValueMessage(key, value)) - } - process.stdout.write(os.EOL) + const filePath = process.env['GITHUB_OUTPUT'] || ''; + if (filePath) { + return issueFileCommand('OUTPUT', prepareKeyValueMessage(key, value)); + } + process.stdout.write(os.EOL); } function issueFileCommand(command, message) { - const filePath = process.env[`GITHUB_${command}`] - if (!filePath) { - throw new Error( - `Unable to find environment variable for file command ${command}` - ) - } - if (!fs.existsSync(filePath)) { - throw new Error(`Missing file at path: ${filePath}`) - } - - fs.appendFileSync(filePath, `${toCommandValue(message)}${os.EOL}`, { - encoding: 'utf8' - }) + const filePath = process.env[`GITHUB_${command}`]; + if (!filePath) { + throw new Error(`Unable to find environment variable for file command ${command}`); + } + if (!fs.existsSync(filePath)) { + throw new Error(`Missing file at path: ${filePath}`); + } + + fs.appendFileSync(filePath, `${toCommandValue(message)}${os.EOL}`, { + encoding: 'utf8', + }); } function prepareKeyValueMessage(key, value) { - const delimiter = `gh-delimiter-${crypto.randomUUID()}` - const convertedValue = toCommandValue(value) - - // These should realistically never happen, but just in case someone finds a - // way to exploit uuid generation let's not allow keys or values that contain - // the delimiter. - if (key.includes(delimiter)) { - throw new Error( - `Unexpected input: name should not contain the delimiter "${delimiter}"` - ) - } - - if (convertedValue.includes(delimiter)) { - throw new Error( - `Unexpected input: value should not contain the delimiter "${delimiter}"` - ) - } - - return `${key}<<${delimiter}${os.EOL}${convertedValue}${os.EOL}${delimiter}` + const delimiter = `gh-delimiter-${crypto.randomUUID()}`; + const convertedValue = toCommandValue(value); + + // These should realistically never happen, but just in case someone finds a + // way to exploit uuid generation let's not allow keys or values that contain + // the delimiter. + if (key.includes(delimiter)) { + throw new Error(`Unexpected input: name should not contain the delimiter "${delimiter}"`); + } + + if (convertedValue.includes(delimiter)) { + throw new Error(`Unexpected input: value should not contain the delimiter "${delimiter}"`); + } + + return `${key}<<${delimiter}${os.EOL}${convertedValue}${os.EOL}${delimiter}`; } function toCommandValue(input) { - if (input === null || input === undefined) { - return '' - } else if (typeof input === 'string' || input instanceof String) { - return input - } - return JSON.stringify(input) + if (input === null || input === undefined) { + return ''; + } else if (typeof input === 'string' || input instanceof String) { + return input; + } + return JSON.stringify(input); } -- cgit v1.2.3 From f64934086e84966bcfd02b699d64a80cb8392fa2 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Mon, 18 Nov 2024 13:35:34 +0000 Subject: [ci] format --- .github/scripts/announce.mjs | 4 ++-- .github/scripts/bundle-size.mjs | 2 +- .github/scripts/utils.mjs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to '.github/scripts/utils.mjs') diff --git a/.github/scripts/announce.mjs b/.github/scripts/announce.mjs index 27a3c7101..2e05a7ae8 100755 --- a/.github/scripts/announce.mjs +++ b/.github/scripts/announce.mjs @@ -1,6 +1,6 @@ -import { globby as glob } from 'globby'; -import { fileURLToPath } from 'node:url'; import { readFile } from 'node:fs/promises'; +import { fileURLToPath } from 'node:url'; +import { globby as glob } from 'globby'; import { setOutput } from './utils.mjs'; const { GITHUB_REF = 'main' } = process.env; diff --git a/.github/scripts/bundle-size.mjs b/.github/scripts/bundle-size.mjs index b5ef31b48..76d6b3f29 100644 --- a/.github/scripts/bundle-size.mjs +++ b/.github/scripts/bundle-size.mjs @@ -1,5 +1,5 @@ -import { build } from 'esbuild'; import { existsSync } from 'node:fs'; +import { build } from 'esbuild'; const CLIENT_RUNTIME_PATH = 'packages/astro/src/runtime/client/'; diff --git a/.github/scripts/utils.mjs b/.github/scripts/utils.mjs index 9aaa383d8..768302230 100644 --- a/.github/scripts/utils.mjs +++ b/.github/scripts/utils.mjs @@ -1,6 +1,6 @@ +import * as crypto from 'node:crypto'; import * as fs from 'node:fs'; import * as os from 'node:os'; -import * as crypto from 'node:crypto'; /** Based on https://github.com/actions/toolkit/blob/4e3b068ce116d28cb840033c02f912100b4592b0/packages/core/src/file-command.ts */ export function setOutput(key, value) { -- cgit v1.2.3