-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
101 lines (93 loc) · 3.35 KB
/
index.js
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
const core = require("@actions/core");
const tc = require("@actions/tool-cache");
const exec = require("@actions/exec");
const io = require("@actions/io");
const path = require("path");
const target = core.getInput("target", { required: true });
const variant = core.getInput("variant", { required: true });
const build = core.getInput("build").toUpperCase() === "TRUE";
const buildDir = path.join("/opt/", target, variant);
const tags = {
"pmmp/musl-cross-make": "heracles",
"richfelker/musl-cross-make": "heracles",
};
(async () => {
try {
const url = `https://github.com/nao20010128nao/musl-cross-compilers/releases/download/${tags[variant]}/output-${target}-${variant.replace(
"/",
"_"
)}.tar.gz`;
let cachedPath;
if (build) {
const destDir = buildDir;
await io.mkdirP(destDir);
// https://stackoverflow.com/questions/11912878/gcc-error-gcc-error-trying-to-exec-cc1-execvp-no-such-file-or-directory
let ret = await exec.exec("sudo", ["apt", "update"], {
ignoreReturnCode: true,
});
if (ret != 0) {
console.error(`apt update failed with code ${ret}`);
}
ret = await exec.exec("sudo", ["apt", "install", "--reinstall", "gcc", "g++", "cpp-11", "cpp-9"], {
ignoreReturnCode: true,
});
if (ret != 0) {
console.error(`apt install failed with code ${ret}`);
}
ret = await exec.exec("git", ["clone", `https://github.com/${variant}.git`, destDir], {
ignoreReturnCode: true,
});
if (ret != 0) {
throw new Error(`git clone failed with code ${ret}`);
}
ret = await exec.exec("make", ["-j4"], {
cwd: destDir,
ignoreReturnCode: true,
env: {
TARGET: target,
},
});
if (ret != 0) {
throw new Error(`make -j4 failed with code ${ret}`);
}
ret = await exec.exec("make", ["install"], {
cwd: destDir,
ignoreReturnCode: true,
env: {
TARGET: target,
},
});
if (ret != 0) {
throw new Error(`make install failed with code ${ret}`);
}
cachedPath = destDir;
} else {
cachedPath = tc.find("mcm", `${target}-${variant}.tar.gz`);
}
if (cachedPath) {
console.log(`Found installation at ${cachedPath}`);
} else {
const toolchainPath = await tc.downloadTool(url);
const toolchainExtractedFolder = await tc.extractTar(toolchainPath);
cachedPath = await tc.cacheDir(toolchainExtractedFolder, "mcm", `${target}-${variant}.tar.gz`);
console.log(`Installed at ${cachedPath}`);
}
cachedPath = path.join(cachedPath, "output", "bin");
console.log(`Binaries are at ${cachedPath}`);
core.addPath(cachedPath);
core.setOutput("path", cachedPath);
} catch (e) {
if (build) {
console.log("Build error occured and uploading build directory as artifacts");
await exec.exec("tar", ["-czf", "/opt/mcm.tar.gz", buildDir]);
const artifact = require("@actions/artifact");
const artifactClient = artifact.create();
const artifactName = `musl-cross-compiler-error-${target}-${variant.replace("/", "_")}`;
const files = ["/opt/mcm.tar.gz"];
const rootDirectory = "/opt/";
const options = {};
await artifactClient.uploadArtifact(artifactName, files, rootDirectory, options);
}
core.setFailed(e);
}
})();