Skip to content

Commit fe3edf8

Browse files
authoredJun 17, 2020
add max_attempts option. closes samuelmeuli#28 (samuelmeuli#30)
1 parent f92801c commit fe3edf8

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed
 

‎.github/workflows/test.yml

+1
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ jobs:
3535
github_token: ${{ secrets.github_token }}
3636
package_root: ${{ matrix.package_root }}
3737
use_vue_cli: ${{ contains(matrix.package_root, 'vue')}}
38+
max_attempts: "2"

‎README.md

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ You can configure the action further with the following options:
7676
- `skip_build`: Whether the action should execute the NPM build script before running `electron-builder`
7777
- `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
7878
- `args`: Other arguments to pass to the `electron-builder` command, e.g. configuration overrides (default: `""`)
79+
- `max_attempts`: Maximum number of attempts for completing the build and release step
7980

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

‎action.yml

+4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ inputs:
4242
description: Other arguments to pass to the `electron-builder` command, e.g. configuration overrides
4343
required: false
4444
default: ""
45+
max_attempts:
46+
description: Maximum number of attempts for completing the build and release step
47+
required: false
48+
default: "1"
4549

4650
# Deprecated
4751
app_root:

‎index.js

+19-6
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ const runAction = () => {
7171
const skipBuild = getInput("skip_build") === "true";
7272
const useVueCli = getInput("use_vue_cli") === "true";
7373
const args = getInput("args") || "";
74+
const maxAttempts = Number(getInput("max_attempts") || "1");
7475

7576
// TODO: Deprecated option, remove in v2.0. `electron-builder` always requires a `package.json` in
7677
// the same directory as the Electron app, so the `package_root` option should be used instead
@@ -126,12 +127,24 @@ const runAction = () => {
126127

127128
log(`Building${release ? " and releasing" : ""} the Electron app…`);
128129
const cmd = useVueCli ? "vue-cli-service electron:build" : "electron-builder";
129-
run(
130-
`${useNpm ? "npx --no-install" : "yarn run"} ${cmd} --${platform} ${
131-
release ? "--publish always" : ""
132-
} ${args}`,
133-
appRoot,
134-
);
130+
for (let i = 0; i < maxAttempts; i += 1) {
131+
try {
132+
run(
133+
`${useNpm ? "npx --no-install" : "yarn run"} ${cmd} --${platform} ${
134+
release ? "--publish always" : ""
135+
} ${args}`,
136+
appRoot,
137+
);
138+
break;
139+
} catch (err) {
140+
if (i < maxAttempts - 1) {
141+
log(`Attempt ${i + 1} failed:`);
142+
log(err);
143+
} else {
144+
throw err;
145+
}
146+
}
147+
}
135148
};
136149

137150
runAction();

0 commit comments

Comments
 (0)
Please sign in to comment.