2021-09-30 10:01:53 -04:00
|
|
|
import { getRequiredFiles, gradleOutputSelector } from "./utils/file-utils";
|
2021-09-25 02:37:10 -04:00
|
|
|
import PublisherFactory from "./publishing/publisher-factory";
|
|
|
|
import PublisherTarget from "./publishing/publisher-target";
|
|
|
|
import { getInputAsObject } from "./utils/input-utils";
|
|
|
|
import { getDefaultLogger } from "./utils/logger-utils";
|
2022-01-12 10:16:19 -05:00
|
|
|
import { retry } from "./utils/function-utils";
|
2021-09-25 02:37:10 -04:00
|
|
|
|
|
|
|
async function main() {
|
|
|
|
const commonOptions = getInputAsObject();
|
|
|
|
const publisherFactory = new PublisherFactory();
|
|
|
|
const logger = getDefaultLogger();
|
|
|
|
const publishedTo = new Array<string>();
|
|
|
|
|
|
|
|
for (const target of PublisherTarget.getValues()) {
|
|
|
|
const targetName = PublisherTarget.toString(target);
|
|
|
|
const publisherOptions = commonOptions[targetName.toLowerCase()];
|
2021-12-10 09:00:43 -05:00
|
|
|
if (!publisherOptions?.token || typeof publisherOptions.token !== "string") {
|
2021-09-25 02:37:10 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-09-30 10:01:53 -04:00
|
|
|
const options = { ...commonOptions, ...publisherOptions };
|
|
|
|
const fileSelector = options.files && (typeof(options.files) === "string" || options.files.primary) ? options.files : gradleOutputSelector;
|
|
|
|
const files = await getRequiredFiles(fileSelector);
|
2022-01-12 10:16:19 -05:00
|
|
|
const retryAttempts = +options.retry?.["attempts"] || 0;
|
|
|
|
const retryDelay = +options.retry?.["delay"] || 0;
|
2021-09-30 10:01:53 -04:00
|
|
|
|
|
|
|
const publisher = publisherFactory.create(target, logger);
|
2021-09-25 02:37:10 -04:00
|
|
|
logger.info(`Publishing assets to ${targetName}...`);
|
|
|
|
const start = new Date();
|
2022-01-12 10:16:19 -05:00
|
|
|
|
|
|
|
await retry({
|
|
|
|
func: () => publisher.publish(files, options),
|
|
|
|
maxAttempts: retryAttempts,
|
|
|
|
delay: retryDelay,
|
|
|
|
errorCallback: e => {
|
|
|
|
logger.error(`${e}`);
|
|
|
|
logger.info(`Retrying to publish assets to ${targetName} in ${retryDelay} ms...`);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const end = new Date();
|
|
|
|
logger.info(`Successfully published assets to ${targetName} (in ${end.getTime() - start.getTime()} ms)`);
|
2021-09-25 02:37:10 -04:00
|
|
|
publishedTo.push(targetName);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (publishedTo.length) {
|
|
|
|
logger.info(`Your assets have been successfully published to: ${publishedTo.join(", ")}`);
|
|
|
|
} else {
|
|
|
|
logger.warn("You didn't specify any targets, your assets have not been published");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-12 10:16:19 -05:00
|
|
|
main().catch(error => getDefaultLogger().fatal(error instanceof Error ? `${error}` : `Something went horribly wrong: ${error}`));
|