-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-angle.js
More file actions
165 lines (142 loc) · 5.55 KB
/
setup-angle.js
File metadata and controls
165 lines (142 loc) · 5.55 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
//
// Copyright (c) 2025, Byteplug LLC.
//
// This source file is part of a project made by the Erlangsters community and
// is released under the MIT license. Please refer to the LICENSE.md file that
// can be found at the root of the project repository.
//
// Written by Jonathan De Wachter <jonathan.dewachter@byteplug.io>
//
const core = require('@actions/core');
const path = require('path');
const os = require('os');
const tc = require('@actions/tool-cache');
// XXX: Perhaps allow customizing where the pre-built ANGLE binaries are
// downloaded from.
// XXX: Fix the branch/commit temporary workaround.
// By default, this is where it downloads the pre-built ANGLE binaries.
const S3_ENDPOINT_URL = 'https://hel1.your-objectstorage.com';
const S3_BUCKET_NAME = 'erlangsters';
const S3_PATH_PREFIX = 'angle';
// The available ANGLE branches, in descending order (important!).
const ANGLE_BRANCHES = [
"fdff117"
];
// The default ANGLE branch.
function defaultBranch() {
return ANGLE_BRANCHES[0];
}
// Detect the runner's OS and architecture so we can download the correct
// pre-built ANGLE binaries.
function getRunnerOS() {
const platform = os.platform();
if (platform === 'win32') {
return 'windows';
} else if (platform === 'darwin') {
return 'macos';
} else {
throw new Error(`Unsupported platform: ${platform}`);
}
}
function getRunnerArchitecture() {
const arch = os.arch();
if (arch === 'x64') {
return 'amd64';
} else if (arch === 'arm64') {
return 'arm64';
} else {
throw new Error(`Unsupported architecture: ${arch}`);
}
}
function detectPlatform() {
const platform = {
os: getRunnerOS(),
arch: getRunnerArchitecture()
};
return platform;
}
// Compute the platform name, which is used in the tarball name of the
// pre-built binaries.
function computePlatformName(platform) {
return `${platform.os}-${platform.arch}`;
}
// The name of the tarball (which contains the pre-built binaries) follows a
// specific format: angle-<branch>-<os>-<arch>.tar.gz (the '/' in the branch
// name is replaced by '-').
function computeTarballName(version, platform) {
const platformName = computePlatformName(platform);
// Replace '/' with '-' in the branch name to create a valid tarball name.
const tarballName = `angle-${version}-${platformName}.tar.gz`;
return tarballName;
}
function computeFolderName(version, platform) {
const platformName = computePlatformName(platform);
// Replace '/' with '-' in the branch name to create a valid tarball name.
const tarballName = `angle-${version}-${platformName}`;
return tarballName;
}
// The tarballs folder is where the pre-built binaries are stored in the S3
// bucket (for a given Erlang version).
function computeTarballsFolder(version) {
const tarballFolder = `${S3_ENDPOINT_URL}/${S3_BUCKET_NAME}/${S3_PATH_PREFIX}/${version}`;
return tarballFolder;
}
async function run() {
try {
// Read the ANGLE branch from the input. Use the default ANGLE branch if
// not specified.
let angleBranch = core.getInput('angle-branch');
if (!angleBranch) {
console.log('No ANGLE branch specified, using the default branch.');
angleBranch = defaultBranch();
}
else {
console.log(`ANGLE branch ${angleBranch} is requested.`);
// Abort if branch is not available.
if (!ANGLE_BRANCHES.includes(angleBranch)) {
throw new Error(`ANGLE branch ${angleBranch} is not available. Available branches: ${ANGLE_BRANCHES.join(', ')}.`);
}
}
console.log(`ANGLE branch to install is ${angleBranch}.`);
// Detect the platform where the action is running (so we understand what
// pre-built binaries to install).
const platform = detectPlatform();
console.log(`Detected platform is ${JSON.stringify(platform)}.`);
// Based on the platform, compute the location of the tarball to download
// from the S3 bucket.
const platformName = computePlatformName(platform);
const tarballName = computeTarballName(angleBranch, platform);
const tarballsFolder = computeTarballsFolder(angleBranch, platform);
const tarballLocation = `${tarballsFolder}/${tarballName}`;
console.log(`Computed pre-built binary URL is ${tarballLocation}`);
// We download (if not already cached) the pre-built binaries and extract
// into the installation directory.
let toolPath = tc.find('angle', angleBranch, platform.arch);
if (!toolPath) {
// Try to download the tarball from the S3 bucket.
let tarballDownloadPath;
try {
tarballDownloadPath = await tc.downloadTool(tarballLocation);
console.log(`Downloaded ANGLE to ${tarballDownloadPath}.`);
} catch (error) {
throw new Error(`Failed to download ANGLE tarball: ${error.message}`);
}
const tempExtractedPath = await tc.extractTar(tarballDownloadPath);
console.log(`Extracted ANGLE to ${tempExtractedPath}.`);
// Cache the final installation directory
toolPath = await tc.cacheDir(tempExtractedPath, 'angle', angleBranch, platform.arch);
console.log(`Cached ANGLE to ${toolPath}`);
} else {
console.log(`ANGLE found in cache at ${toolPath}`);
}
const angleLocation = path.join(toolPath, computeFolderName(angleBranch, platform));
// Indicate the ANGLE branch that has actually been installed.
core.setOutput('angle-branch', angleBranch);
// Indicate the location of the ANGLE installation.
core.setOutput('angle-location', angleLocation);
console.log(`ANGLE successfully installed at ${angleLocation}.`);
} catch (error) {
core.setFailed(error.message);
}
}
run();