-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.ts
70 lines (57 loc) · 2.21 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import * as core from "@actions/core";
import * as tc from "@actions/tool-cache";
import { coerce } from "semver";
import { Repository } from "./types";
import getReleaseByTag from "./getReleaseByTag";
import downloadAsset from "./downloadAsset";
import installAsset from "./installAsset";
const REPOSITORIES: Repository[] = [
{ owner: "processing", repo: "processing4" },
{ owner: "processing", repo: "processing" },
];
async function run() {
const tag = core.getInput("tag") || undefined;
const assetName = core.getInput("asset-name") || undefined;
core.info(`setup-processing: tag=${tag}, assetName=${assetName}`);
core.debug(
`Attempting to find release with the following tag: ${
tag ?? "(Infered, none given)"
}...`
);
const release = await getReleaseByTag(REPOSITORIES, tag);
core.debug(`Found release: ${JSON.stringify(release)}`);
core.debug(`Trying to locate existing Processing installation...`);
let semverTag = getRevisionNumber(release.tag);
let cachedDirectory = tc.find("processing", semverTag);
if (cachedDirectory) {
core.info(`Processing (${release.tag}) is already cached. Aborting...`);
core.addPath(cachedDirectory);
return;
}
core.debug("No existing Processing installation found.");
core.debug(
`Attempting to download release asset with the following assetName: ${
assetName ?? "(Infered, none given)"
}...`
);
const downloadPath = await downloadAsset(release.assets, assetName);
core.debug(`Downloaded release asset at ${downloadPath}`);
core.debug(`Attempting to install...`);
const installPath = await installAsset(downloadPath, semverTag);
core.setOutput("install-dir", installPath);
core.debug(`Processing successfully installed!`);
function getRevisionNumber(tag: string): string {
const matches = tag.match(/.*-0*([0-9]+)-.*/);
if (matches === null) {
throw new Error(`Could not parse tag for revision number: tag=${tag}`);
}
const out = coerce(matches[1])?.format();
if (out === undefined) {
throw new Error(
`Could not coerce revision number to semver: number=${matches[1]}. Please file an issue`
);
}
return out;
}
}
run().catch((reason) => core.setFailed(reason.message));