From d62c3d86bdaf74cd1afea3a96bffc6cca4d68d40 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 19 Sep 2024 23:59:36 +0800 Subject: [PATCH] chore: bump gha-utils from 0.2.0 to 0.3.0 (#446) Bumps [gha-utils](https://github.com/threeal/gha-utils) from 0.2.0 to 0.3.0. - [Release notes](https://github.com/threeal/gha-utils/releases) - [Commits](https://github.com/threeal/gha-utils/compare/v0.2.0...v0.3.0) --- updated-dependencies: - dependency-name: gha-utils dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Signed-off-by: Alfi Maulana Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Alfi Maulana --- dist/action.mjs | 28 +++++++++++++++++++++++----- package.json | 2 +- src/action.ts | 2 +- yarn.lock | 10 +++++----- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/dist/action.mjs b/dist/action.mjs index 189557b..4f22d6e 100644 --- a/dist/action.mjs +++ b/dist/action.mjs @@ -1,8 +1,23 @@ -import fs from 'node:fs'; +import 'node:fs'; +import fsPromises from 'node:fs/promises'; import os from 'node:os'; import path from 'node:path'; import { execFileSync } from 'node:child_process'; +/** + * Retrieves the value of an environment variable. + * + * @param name - The name of the environment variable. + * @returns The value of the environment variable. + * @throws Error if the environment variable is not defined. + */ +function mustGetEnvironment(name) { + const value = process.env[name]; + if (value === undefined) { + throw new Error(`the ${name} environment variable must be defined`); + } + return value; +} /** * Retrieves the value of a GitHub Actions input. * @@ -17,11 +32,14 @@ function getInput(name) { * Sets the value of a GitHub Actions output. * * @param name - The name of the GitHub Actions output. - * @param value - The value of the GitHub Actions output + * @param value - The value to set for the GitHub Actions output. + * @returns A promise that resolves when the value is successfully set. */ -function setOutput(name, value) { - fs.appendFileSync(process.env["GITHUB_OUTPUT"], `${name}=${value}${os.EOL}`); +async function setOutput(name, value) { + const filePath = mustGetEnvironment("GITHUB_OUTPUT"); + await fsPromises.appendFile(filePath, `${name}=${value}${os.EOL}`); } + /** * Logs an error message in GitHub Actions. * @@ -109,7 +127,7 @@ function getContext() { try { const context = getContext(); configureProject(context); - setOutput("build-dir", context.buildDir); + await setOutput("build-dir", context.buildDir); if (context.build.enabled) { buildProject(context); } diff --git a/package.json b/package.json index 97753e4..aec7fb8 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "test": "jest" }, "dependencies": { - "gha-utils": "^0.2.0" + "gha-utils": "^0.3.0" }, "devDependencies": { "@eslint/js": "^9.10.0", diff --git a/src/action.ts b/src/action.ts index 58b499a..cd1df4b 100644 --- a/src/action.ts +++ b/src/action.ts @@ -7,7 +7,7 @@ try { configureProject(context); - setOutput("build-dir", context.buildDir); + await setOutput("build-dir", context.buildDir); if (context.build.enabled) { buildProject(context); diff --git a/yarn.lock b/yarn.lock index 7cb2244..5eb2328 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2376,10 +2376,10 @@ __metadata: languageName: node linkType: hard -"gha-utils@npm:^0.2.0": - version: 0.2.0 - resolution: "gha-utils@npm:0.2.0" - checksum: 10c0/34e597b9011518c36abbb4bbbfb0ecaf16171e2bafad3a9ddbbdd3c3b2c1234eb8afc06fc84837565afca5e9ca9d48eb62a7238613ab808d8e1c7e0b6651e2c6 +"gha-utils@npm:^0.3.0": + version: 0.3.0 + resolution: "gha-utils@npm:0.3.0" + checksum: 10c0/f8fe13abc48640d60072518260c8e6d5fb695e933c3ef2e16970838d3676254d21ed239e4267ae65f83dc5c167a1bd97959005b713217ead7bf8873e79b2343b languageName: node linkType: hard @@ -4108,7 +4108,7 @@ __metadata: "@types/jest": "npm:^29.5.13" "@types/node": "npm:^22.5.5" eslint: "npm:^9.9.1" - gha-utils: "npm:^0.2.0" + gha-utils: "npm:^0.3.0" jest: "npm:^29.7.0" prettier: "npm:^3.3.3" rollup: "npm:^4.21.3"