-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.ts
126 lines (122 loc) · 4.39 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import { main } from "@digicert/ssm-client-tools-installer";
import * as core from "@actions/core";
import * as tc from "@actions/tool-cache";
import path from "path";
import * as io from "@actions/io";
import fs from "fs";
import os from "os";
const osPlat: string = os.platform();
const signtools =
osPlat == "win32"
? [
"smctl",
"ssm-scd",
"signtool",
"nuget",
"mage",
"apksigner",
"jarsigner",
]
: ["smctl", "ssm-scd", "nuget", "mage", "apksigner"];
const toolInstaller = async (toolName: string, toolPath: string = "") => {
let cacheDir;
switch (toolName) {
case "smctl":
cacheDir = await tc.cacheDir(toolPath, toolName, "latest");
core.addPath(cacheDir);
core.debug(`tools cache has been updated with the path: ${cacheDir}`);
break;
case "signtool":
const sign =
"C:\\Program Files (x86)\\Windows Kits\\10\\bin\\10.0.17763.0\\x86\\";
cacheDir = await tc.cacheDir(sign, toolName, "latest");
core.addPath(cacheDir);
core.debug(`tools cache has been updated with the path: ${cacheDir}`);
break;
case "ssm-scd":
cacheDir = await tc.cacheDir(toolPath, toolName, "latest");
core.addPath(cacheDir);
core.debug(`tools cache has been updated with the path: ${cacheDir}`);
break;
case "nuget":
core.debug("Downloading Nuget tool");
const nugetPath = await tc.downloadTool(
"https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
);
// Rename the file which is a GUID without extension
var folder = path.dirname(nugetPath);
var fullPath = path.join(folder, "nuget.exe");
fs.renameSync(nugetPath, fullPath);
cacheDir = await tc.cacheDir(folder, toolName, "latest");
core.addPath(cacheDir);
core.debug(`tools cache has been updated with the path: ${cacheDir}`);
break;
case "mage":
const magedownloadUrl =
osPlat == "win32"
? `https://github.com/magefile/mage/releases/download/v1.14.0/mage_1.14.0_Windows-64bit.zip `
: `https://github.com/magefile/mage/releases/download/v1.14.0/mage_1.14.0_Linux-64bit.tar.gz`;
let downloadPath = "";
try {
downloadPath = await tc.downloadTool(magedownloadUrl);
} catch (err: any) {
core.debug(err);
throw new Error(`failed to download Mage v: ${err.message}`);
}
// Extract tar
const extractPath =
osPlat == "win32"
? await tc.extractZip(downloadPath)
: await tc.extractTar(downloadPath);
cacheDir = await tc.cacheDir(extractPath, toolName, "latest");
core.addPath(cacheDir);
core.debug(`tools cache has been updated with the path: ${cacheDir}`);
break;
case "apksigner":
const buildToolsVersion = process.env.BUILD_TOOLS_VERSION || "30.0.2";
const androidHome = process.env.ANDROID_HOME;
if (!androidHome) {
core.error("require ANDROID_HOME to be execute");
throw new Error("ANDROID_HOME is null");
}
const buildTools = path.join(
androidHome,
`build-tools/${buildToolsVersion}`
);
if (!fs.existsSync(buildTools)) {
core.error(`Couldnt find the Android build tools @ ${buildTools}`);
}
// find apksigner path
const apkSigner = path.join(buildTools, "apksigner");
core.debug(`Found 'apksigner' @ ${apkSigner}`);
core.debug("Verifying Signed APK");
const toolcache = await tc.cacheDir(buildTools, "apksigner", "0.9");
core.addPath(toolcache);
break;
case "jarsigner":
const jarSignerPath = await io.which("jarsigner", true);
core.debug(`Found 'jarsigner' @ ${jarSignerPath}`);
core.addPath(jarSignerPath);
break;
}
};
(async () => {
try {
process.env.SHOULD_CHECK_INSTALLED = "false";
const result = await main("keypair-signing");
const message = JSON.parse(result);
if (message) {
core.setOutput("extractPath", message.imp_file_paths.extractPath);
core.setOutput("PKCS11_CONFIG", message.imp_file_paths.PKCS11_CONFIG);
signtools.map(async (sgtool) =>
(await (sgtool == "smctl" || sgtool == "ssm-scd"))
? toolInstaller(sgtool, message.imp_file_paths.extractPath)
: toolInstaller(sgtool)
);
} else {
core.setFailed("Installation Failed");
}
} catch (error: any) {
core.setFailed(error.message);
}
})();