mirror of
https://github.com/Kir-Antipov/mc-publish.git
synced 2024-11-22 00:11:02 -05:00
Added fail-mode
input
This commit is contained in:
parent
58a1f9bab8
commit
3f02162129
5 changed files with 84 additions and 11 deletions
17
README.md
17
README.md
|
@ -123,6 +123,7 @@ jobs:
|
|||
| [java](#user-content-java) | A list of supported Java versions | *empty string* | `Java 8` <br> `Java 1.8` <br> `8` |
|
||||
| [retry-attempts](#user-content-retry-attempts) | The maximum number of attempts to publish assets | `2` | `2` <br> `10` <br> `-1` |
|
||||
| [retry-delay](#user-content-retry-delay) | Time delay between attempts to publish assets (in milliseconds) | `10000` | `10000` <br> `60000` <br> `0` |
|
||||
| [fail-mode](#user-content-fail-mode) | Determines how errors that occur during mod publishing process are handled | `fail` | `fail` <br> `warn` <br> `skip` |
|
||||
|
||||
Note, that you can use any top-level property *(`name`, `version`, `dependencies`, `files`, etc.)* as a target-specific one. This can help you fine-tune `mc-publish` to suit your tastes and needs. For example, consider the following configuration:
|
||||
|
||||
|
@ -717,4 +718,18 @@ Time delay between attempts to publish assets (in milliseconds).
|
|||
|
||||
```yaml
|
||||
retry-delay: 10000
|
||||
```
|
||||
```
|
||||
|
||||
#### fail-mode
|
||||
|
||||
Determines how errors that occur during mod publishing process are handled. Default value is `fail`.
|
||||
|
||||
```yaml
|
||||
fail-mode: fail
|
||||
```
|
||||
|
||||
Available values:
|
||||
|
||||
- `fail` - immediately sets the action status to **failed** and terminates its execution
|
||||
- `warn` - warns about errors. The action won't be terminated, nor its status will be set to **failed**
|
||||
- `skip` - warns about errors. The action won't be terminated, but its status will be set to **failed** after all specified targets have been processed
|
|
@ -77,6 +77,8 @@ inputs:
|
|||
retry-delay:
|
||||
description: Time delay between attempts to publish assets (in milliseconds)
|
||||
default: 10000
|
||||
fail-mode:
|
||||
description: Determines how errors that occur during mod publishing process are handled
|
||||
runs:
|
||||
using: node12
|
||||
main: dist/index.js
|
29
package-lock.json
generated
29
package-lock.json
generated
|
@ -2796,6 +2796,15 @@
|
|||
"integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==",
|
||||
"dev": true
|
||||
},
|
||||
"aggregate-error": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/aggregate-error/-/aggregate-error-4.0.1.tgz",
|
||||
"integrity": "sha512-0poP0T7el6Vq3rstR8Mn4V/IQrpBLO6POkUSrN7RhyY+GF/InCFShQzsQ39T25gkHhLgSLByyAz+Kjb+c2L98w==",
|
||||
"requires": {
|
||||
"clean-stack": "^4.0.0",
|
||||
"indent-string": "^5.0.0"
|
||||
}
|
||||
},
|
||||
"ajv": {
|
||||
"version": "6.12.6",
|
||||
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz",
|
||||
|
@ -3147,6 +3156,21 @@
|
|||
"integrity": "sha512-cOU9usZw8/dXIXKtwa8pM0OTJQuJkxMN6w30csNRUerHfeQ5R6U3kkU/FtJeIf3M202OHfY2U8ccInBG7/xogA==",
|
||||
"dev": true
|
||||
},
|
||||
"clean-stack": {
|
||||
"version": "4.2.0",
|
||||
"resolved": "https://registry.npmjs.org/clean-stack/-/clean-stack-4.2.0.tgz",
|
||||
"integrity": "sha512-LYv6XPxoyODi36Dp976riBtSY27VmFo+MKqEU9QCCWyTrdEPDog+RWA7xQWHi6Vbp61j5c4cdzzX1NidnwtUWg==",
|
||||
"requires": {
|
||||
"escape-string-regexp": "5.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"escape-string-regexp": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-5.0.0.tgz",
|
||||
"integrity": "sha512-/veY75JbMK4j1yjvuUxuVsiS/hr/4iHs9FTT6cgTexxdE0Ly/glccBAkloH/DofkjRbZU3bnoj38mOmhkZ0lHw=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"cliui": {
|
||||
"version": "7.0.4",
|
||||
"resolved": "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz",
|
||||
|
@ -3928,6 +3952,11 @@
|
|||
"integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o=",
|
||||
"dev": true
|
||||
},
|
||||
"indent-string": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/indent-string/-/indent-string-5.0.0.tgz",
|
||||
"integrity": "sha512-m6FAo/spmsW2Ab2fU35JTYwtOKa2yAwXSwgjSv1TJzh4Mh7mC3lzAOVLBprb72XsTrgkEIsl7YrFNAiDiRhIGg=="
|
||||
},
|
||||
"inflight": {
|
||||
"version": "1.0.6",
|
||||
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
"dependencies": {
|
||||
"@actions/core": "^1.8.2",
|
||||
"@actions/github": "^5.0.3",
|
||||
"aggregate-error": "^4.0.1",
|
||||
"fast-glob": "^3.2.11",
|
||||
"form-data": "^3.0.1",
|
||||
"node-fetch": "^2.6.7",
|
||||
|
|
46
src/index.ts
46
src/index.ts
|
@ -1,16 +1,24 @@
|
|||
import { getRequiredFiles, gradleOutputSelector } from "./utils/file-utils";
|
||||
import PublisherFactory from "./publishing/publisher-factory";
|
||||
import PublisherTarget from "./publishing/publisher-target";
|
||||
import { getInputAsObject, mapNumberInput } from "./utils/input-utils";
|
||||
import { getInputAsObject, mapEnumInput, mapNumberInput } from "./utils/input-utils";
|
||||
import { getDefaultLogger } from "./utils/logger-utils";
|
||||
import { retry } from "./utils/function-utils";
|
||||
import LoggingStopwatch from "./utils/logging-stopwatch";
|
||||
import AggregateError from "aggregate-error";
|
||||
|
||||
enum FailMode {
|
||||
Fail,
|
||||
Warn,
|
||||
Skip,
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const commonOptions = getInputAsObject();
|
||||
const publisherFactory = new PublisherFactory();
|
||||
const logger = getDefaultLogger();
|
||||
const publishedTo = new Array<string>();
|
||||
const errors = new Array<Error>();
|
||||
|
||||
for (const target of PublisherTarget.getValues()) {
|
||||
const targetName = PublisherTarget.toString(target);
|
||||
|
@ -24,29 +32,47 @@ async function main() {
|
|||
const files = await getRequiredFiles(fileSelector);
|
||||
const retryAttempts = mapNumberInput(options.retryAttempts);
|
||||
const retryDelay = mapNumberInput(options.retryDelay);
|
||||
|
||||
const failMode = mapEnumInput(options.failMode, FailMode, FailMode.Fail as FailMode);
|
||||
const publisher = publisherFactory.create(target, logger);
|
||||
const stopwatch = LoggingStopwatch.startNew(logger, `Publishing assets to ${targetName}...`, ms => `Successfully published assets to ${targetName} (in ${ms} ms)`);
|
||||
|
||||
await retry({
|
||||
const func = {
|
||||
func: () => publisher.publish(files, options),
|
||||
maxAttempts: retryAttempts,
|
||||
delay: retryDelay,
|
||||
errorCallback: e => {
|
||||
logger.error(`${e}`);
|
||||
errorCallback: (e: Error) => {
|
||||
logger.error(e);
|
||||
logger.info(`Retrying to publish assets to ${targetName} in ${retryDelay} ms...`);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const stopwatch = LoggingStopwatch.startNew(logger, `Publishing assets to ${targetName}...`, ms => `Successfully published assets to ${targetName} (in ${ms} ms)`);
|
||||
try {
|
||||
await retry(func);
|
||||
} catch(e: any) {
|
||||
switch (failMode) {
|
||||
case FailMode.Warn:
|
||||
logger.warn(e);
|
||||
continue;
|
||||
case FailMode.Skip:
|
||||
logger.warn(`An error occurred while uploading assets to ${targetName}`);
|
||||
errors.push(e);
|
||||
continue;
|
||||
default:
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
stopwatch.stop();
|
||||
publishedTo.push(targetName);
|
||||
}
|
||||
|
||||
if (publishedTo.length) {
|
||||
logger.info(`Your assets have been successfully published to: ${publishedTo.join(", ")}`);
|
||||
} else {
|
||||
} else if (!errors.length) {
|
||||
logger.warn("You didn't specify any targets, your assets have not been published");
|
||||
}
|
||||
|
||||
if (errors.length) {
|
||||
throw new AggregateError(errors);
|
||||
}
|
||||
}
|
||||
|
||||
main().catch(error => getDefaultLogger().fatal(error instanceof Error ? `${error}` : `Something went horribly wrong: ${error}`));
|
||||
main().catch(error => getDefaultLogger().fatal(error instanceof Error ? error : `Something went horribly wrong: ${error}`));
|
||||
|
|
Loading…
Reference in a new issue