From 4ba36fb29a45d4bbeaea74d21e908555b31685e8 Mon Sep 17 00:00:00 2001 From: Ilias Trichopoulos Date: Mon, 15 Jan 2024 08:32:06 +0800 Subject: [PATCH 1/3] Support PNPM --- index.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index b4db1482..3456307f 100644 --- a/index.js +++ b/index.js @@ -79,10 +79,13 @@ const runAction = () => { const pkgJsonPath = join(pkgRoot, "package.json"); const pkgLockPath = join(pkgRoot, "package-lock.json"); + const pnpmLockPath = join(pkgRoot, "pnpm-lock.yaml") - // Determine whether NPM should be used to run commands (instead of Yarn, which is the default) + // Determine whether NPM or PNPM should be used to run commands (instead of Yarn, which is the default) const useNpm = existsSync(pkgLockPath); - log(`Will run ${useNpm ? "NPM" : "Yarn"} commands in directory "${pkgRoot}"`); + const usePnpm = existsSync(pnpmLockPath); + const scriptRunner = useNpm ? "npm" : usePnpm ? "pnpm" : "yarn" + log(`Will run ${scriptRunner} commands in directory "${pkgRoot}"`); // Make sure `package.json` file exists if (!existsSync(pkgJsonPath)) { @@ -105,16 +108,16 @@ const runAction = () => { // Disable console advertisements during install phase setEnv("ADBLOCK", true); - log(`Installing dependencies using ${useNpm ? "NPM" : "Yarn"}…`); - run(useNpm ? "npm install" : "yarn", pkgRoot); + log(`Installing dependencies using ${scriptRunner}…`); + run(`${scriptRunner} install`, pkgRoot); // Run NPM build script if it exists if (skipBuild) { log("Skipping build script because `skip_build` option is set"); } else { log("Running the build script…"); - if (useNpm) { - run(`npm run ${buildScriptName} --if-present`, pkgRoot); + if (useNpm || usePnpm) { + run(`${scriptRunner} run ${buildScriptName} --if-present`, pkgRoot); } else { // TODO: Use `yarn run ${buildScriptName} --if-present` once supported // https://github.com/yarnpkg/yarn/issues/6894 @@ -130,7 +133,7 @@ const runAction = () => { for (let i = 0; i < maxAttempts; i += 1) { try { run( - `${useNpm ? "npx --no-install" : "yarn run"} ${cmd} --${platform} ${ + `${useNpm ? "npx --no-install" : usePnpm ? "pnpm exec" : "yarn run"} ${cmd} --${platform} ${ release ? "--publish always" : "" } ${args}`, appRoot, From e42a7c36dd7bc221694adefe026f861a47e5d5bd Mon Sep 17 00:00:00 2001 From: Ilias Trichopoulos Date: Mon, 15 Jan 2024 10:52:23 +0800 Subject: [PATCH 2/3] Fix PNPM build script run --- index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 3456307f..d6387cdb 100644 --- a/index.js +++ b/index.js @@ -116,8 +116,10 @@ const runAction = () => { log("Skipping build script because `skip_build` option is set"); } else { log("Running the build script…"); - if (useNpm || usePnpm) { - run(`${scriptRunner} run ${buildScriptName} --if-present`, pkgRoot); + if (useNpm) { + run(`npm run ${buildScriptName} --if-present`, pkgRoot); + } else if (usePnpm) { + run(`pnpm run --if-present ${buildScriptName}`, pkgRoot); } else { // TODO: Use `yarn run ${buildScriptName} --if-present` once supported // https://github.com/yarnpkg/yarn/issues/6894 From 3fde6e8dd422fab68b103a904f2ecccd2a8c7fc9 Mon Sep 17 00:00:00 2001 From: Ilias Trichopoulos Date: Mon, 15 Jan 2024 10:33:17 +0800 Subject: [PATCH 3/3] Add support for monorepo --- README.md | 1 + action.yml | 4 ++++ index.js | 5 +++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 26623821..b368e400 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,7 @@ You can configure the action further with the following options: - `build_script_name`: Name of the optional NPM build script which is executed before `electron-builder` (default: `"build"`) - `skip_build`: Whether the action should execute the NPM build script before running `electron-builder` - `use_vue_cli`: Whether to run `electron-builder` using the [Vue CLI plugin](https://nklayman.github.io/vue-cli-plugin-electron-builder) instead of calling the command directly +- `is_monorepo`: Whether the package is in a monorepo (will look for lockfiles in parent directories) - `args`: Other arguments to pass to the `electron-builder` command, e.g. configuration overrides (default: `""`) - `max_attempts`: Maximum number of attempts for completing the build and release step (default: `1`) diff --git a/action.yml b/action.yml index cd802b9d..c1d6f12e 100644 --- a/action.yml +++ b/action.yml @@ -38,6 +38,10 @@ inputs: description: Whether to run `electron-builder` using the Vue CLI plugin instead of calling the command directly required: false default: false + is_monorepo: + description: Whether the package is in a monorepo (will look for lockfiles in parent directories) + required: false + default: false args: description: Other arguments to pass to the `electron-builder` command, e.g. configuration overrides required: false diff --git a/index.js b/index.js index d6387cdb..8bc5c54b 100644 --- a/index.js +++ b/index.js @@ -70,6 +70,7 @@ const runAction = () => { const buildScriptName = getInput("build_script_name", true); const skipBuild = getInput("skip_build") === "true"; const useVueCli = getInput("use_vue_cli") === "true"; + const isMonorepo = getInput("is_monorepo") === "true"; const args = getInput("args") || ""; const maxAttempts = Number(getInput("max_attempts") || "1"); @@ -78,8 +79,8 @@ const runAction = () => { const appRoot = getInput("app_root") || pkgRoot; const pkgJsonPath = join(pkgRoot, "package.json"); - const pkgLockPath = join(pkgRoot, "package-lock.json"); - const pnpmLockPath = join(pkgRoot, "pnpm-lock.yaml") + const pkgLockPath = join(pkgRoot, `${isMonorepo ? "../../" : ""}package-lock.json`); + const pnpmLockPath = join(pkgRoot, `${isMonorepo ? "../../" : ""}pnpm-lock.yaml`) // Determine whether NPM or PNPM should be used to run commands (instead of Yarn, which is the default) const useNpm = existsSync(pkgLockPath);