Skip to content
This repository has been archived by the owner on Oct 13, 2024. It is now read-only.

Commit

Permalink
Deprecate app_root option, use package_root as default
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelmeuli committed Jan 9, 2020
1 parent 9375f4c commit 6a20bbf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 28 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ After building successfully, the action will publish your release artifacts. By

You can configure the action further with the following options:

- `app_root`: Directory where `electron-builder` commands should be run (default: repository root)
- `package_root`: Directory where NPM/Yarn commands should be run (default: repository root)
- `package_root`: Directory where NPM/Yarn commands should be run (default: `"."`)

See [`action.yml`](./action.yml) for a list of all possible input variables.

Expand Down
9 changes: 5 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ inputs:
windows_certs_password:
description: Password for decrypting `windows_certs`
required: false
app_root:
description: Directory where `electron-builder` commands should be run
required: false
default: "."
package_root:
description: Directory where NPM/Yarn commands should be run
required: false
default: "."

# Deprecated
app_root:
description: Directory where `electron-builder` commands should be run
required: false

runs:
using: node12
main: index.js
Expand Down
37 changes: 15 additions & 22 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ const { execSync } = require("child_process");
const { existsSync, readFileSync } = require("fs");
const { join } = require("path");

const NPM_LOCKFILE_PATH = "./package-lock.json";
const PACKAGE_JSON_PATH = "./package.json";

/**
* Logs to the console
*/
Expand All @@ -23,15 +20,6 @@ const exit = msg => {
*/
const run = (cmd, cwd) => execSync(cmd, { encoding: "utf8", stdio: "inherit", cwd });

/**
* Exits if the `package.json` file is missing
*/
const verifyPackageJson = cwd => {
if (!existsSync(join(cwd, PACKAGE_JSON_PATH))) {
exit("Missing `package.json` file");
}
};

/**
* Determines the current operating system (one of ["mac", "windows", "linux"])
*/
Expand Down Expand Up @@ -78,18 +66,23 @@ const getInput = (name, required) => {
const runAction = () => {
const platform = getPlatform();
const release = getInput("release", true) === "true";
const appRoot = getInput("app_root", true);
const pkgRoot = getInput("package_root", true);

// Determine whether NPM should be used to run commands (instead of Yarn, which is the default)
const useNpm = existsSync(join(pkgRoot, NPM_LOCKFILE_PATH));
// TODO: Deprecated option, remove in v2.0. `electron-builder` always requires a `package.json` in
// the same directory as the Electron app, so the `package_root` option should be used instead
const appRoot = getInput("app_root") || pkgRoot;

const pkgJsonPath = join(pkgRoot, "package.json");
const pkgLockPath = join(pkgRoot, "package-lock.json");

// Log information about working directories
// Determine whether NPM 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}"`);
log(`Will run \`electron-builder\` commands in directory "${appRoot}"`);

// Make sure `package.json` file exists
verifyPackageJson(pkgRoot);
if (!existsSync(pkgJsonPath)) {
exit(`\`package.json\` file not found at path "${pkgJsonPath}"`);
}

// Copy "github_token" input variable to "GH_TOKEN" env variable (required by `electron-builder`)
setEnv("GH_TOKEN", getInput("github_token", true));
Expand All @@ -116,14 +109,14 @@ const runAction = () => {
run("npm run build --if-present", pkgRoot);
} else {
// TODO: Use `yarn run build --if-present` once supported
// (https://github.com/yarnpkg/yarn/issues/6894)
const packageJson = JSON.parse(readFileSync(PACKAGE_JSON_PATH, "utf8"));
if (packageJson.scripts && packageJson.scripts.build) {
// https://github.com/yarnpkg/yarn/issues/6894
const pkgJson = JSON.parse(readFileSync(pkgJsonPath, "utf8"));
if (pkgJson.scripts && pkgJson.scripts.build) {
run("yarn build", pkgRoot);
}
}

log(`${release ? "Releasing" : "Building"} the Electron app…`);
log(`Building${release ? " and releasing" : ""} the Electron app…`);
run(
`${useNpm ? "npx --no-install" : "yarn run"} electron-builder --${platform} ${
release ? "--publish always" : ""
Expand Down

0 comments on commit 6a20bbf

Please sign in to comment.