generated from actions/javascript-action
-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
318 lines (279 loc) · 11 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
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
const path = require('path');
const core = require('@actions/core');
const exec = require('@actions/exec');
const cache = require('@actions/cache');
const github = require('@actions/github');
const tc = require('@actions/tool-cache');
const io = require('@actions/io');
const semver = require('semver');
const { parseEtcRelease, isSelfHosted, getWindowsDrive } = require('./utils');
function LinuxDistroConfig(versionIds, envMap, commands) {
return {
versionIds: versionIds,
env: envMap,
commands: commands,
};
}
function LinuxDistroCommand(command, args) {
return { cmd: command, args: args };
}
const combineBuildArgs = (systemArgs, userArgs) =>
systemArgs
.filter((systemArg) => !userArgs.some((userArg) => userArg.startsWith(systemArg.split('=')[0])))
.concat(userArgs);
// Github action runners (shared) currently run in passwordless sudo mode.
const DistroVersionPackageMap = {
Ubuntu: LinuxDistroConfig(['20.04', '22.04'], {}, [
LinuxDistroCommand('sudo', ['DEBIAN_FRONTEND=noninteractive', 'apt', 'update']),
LinuxDistroCommand('sudo', [
'DEBIAN_FRONTEND=noninteractive',
'apt',
'install',
'-y',
'build-essential',
'libglib2.0-dev',
'libgudev-1.0-dev',
'libssl-dev',
'libcairo-dev',
'libxml2-dev',
'libjpeg-dev',
'libmjpegtools-dev',
'libopenjp2-7-dev',
'libwxgtk3.0-gtk3-dev',
'libsoup2.4-dev',
'libjson-glib-1.0-0',
'libjson-glib-dev',
'gcc',
'pkg-config',
'git',
'python3-pip',
'flex',
'bison',
]),
LinuxDistroCommand('sudo', ['pip3', 'install', 'meson', 'ninja']),
]), // end of linuxdistroconfig
};
async function run() {
try {
const baseUrl = 'https://gstreamer.freedesktop.org/data/pkg';
const version = core.getInput('version');
const arch = core.getInput('arch');
const gitUrl = core.getInput('repoUrl');
const userBuildArgs = core.getMultilineInput('gstreamerOptions');
const msiUrl = core.getInput('msiUrl');
const devMsiUrl = core.getInput('devMsiUrl');
const buildRun = core.getInput('buildRun');
let gstreamerPath = '';
let gstreamerBinPath = '';
let gstreamerPkgConfigPath = '';
core.info(`Preparing to install GStreamer version ${version} on ${process.platform}...`);
// debug is only output if you set the secret `ACTIONS_RUNNER_DEBUG` to true
core.debug(new Date().toTimeString());
if (process.platform === 'win32') {
if (arch != 'x86' && arch != 'x86_64') {
core.setFailed('"arch" may only be x86 or x86_64');
}
const rootDriveLetter = isSelfHosted() ? 'C:' : getWindowsDrive(process.cwd()) + ':';
let installDir = '';
if (buildRun) {
installDir = process.env.GSTREAMER_INSTALL_DIR ?? path.join(rootDriveLetter, `gstreamer\\${buildRun}`)
} else {
installDir =
process.env.GSTREAMER_INSTALL_DIR ?? path.join(rootDriveLetter, 'gstreamer');
}
const installers = [
`gstreamer-1.0-msvc-${arch}-${version}.msi`,
`gstreamer-1.0-devel-msvc-${arch}-${version}.msi`,
];
if (msiUrl) {
core.info(`Downloading: ${msiUrl}`);
const msiInstallerPath = await tc.downloadTool(msiUrl, installers[0]);
if (msiInstallerPath) {
await exec.exec('msiexec', [
'/passive',
`INSTALLDIR=${installDir}`,
'ADDLOCAL=ALL',
'/i',
msiInstallerPath,
]);
} else {
core.setFailed(`Failed to download ${msiUrl}`);
}
core.info(`Downloading: ${devMsiUrl}`);
const devMsiInstallerPath = await tc.downloadTool(devMsiUrl, installers[1]);
if (devMsiInstallerPath) {
await exec.exec('msiexec', [
'/passive',
`INSTALLDIR=${installDir}`,
'ADDLOCAL=ALL',
'/i',
devMsiInstallerPath,
]);
} else {
core.setFailed(`Failed to download ${devMsiUrl}`);
}
} else {
for (const installer of installers) {
const url = `${baseUrl}/windows/${version}/msvc/${installer}`;
core.info(`Downloading: ${url}`);
const installerPath = await tc.downloadTool(url, installer);
if (installerPath) {
await exec.exec('msiexec', [
'/passive',
`INSTALLDIR=${installDir}`,
'ADDLOCAL=ALL',
'/i',
installerPath,
]);
} else {
core.setFailed(`Failed to download ${url}`);
}
}
}
gstreamerPath = path.join(installDir, '1.0', `msvc_${arch}`);
gstreamerBinPath = path.join(gstreamerPath, 'bin');
gstreamerPkgConfigPath = path.join(gstreamerPath, 'lib', 'pkgconfig');
// Set the GSTREAMER_1_0_ROOT_MSVC_<arch> variable
let gst_root_varname = 'GSTREAMER_1_0_ROOT_MSVC_' + arch.toUpperCase();
core.info(`Setting ${gst_root_varname} to ${gstreamerPath}`);
core.exportVariable(gst_root_varname, gstreamerPath);
} else if (process.platform === 'darwin') {
if (arch == 'x86') {
core.setFailed(`GStreamer binaries for ${process.platform} and x86 are not available`);
return;
}
let pkgType = arch;
if (semver.gte(version, '1.19.90')) {
pkgType = 'universal';
}
const installers = [
`gstreamer-1.0-${version}-${pkgType}.pkg`,
`gstreamer-1.0-devel-${version}-${pkgType}.pkg`,
];
for (const installer of installers) {
const url = `${baseUrl}/osx/${version}/${installer}`;
core.info(`Downloading: ${url}`);
const installerPath = await tc.downloadTool(url, installer);
if (installerPath) {
await exec.exec('sudo', ['installer', '-verbose', '-pkg', installerPath, '-target', '/']);
await io.rmRF(installerPath);
} else {
core.setFailed(`Failed to download ${url}`);
}
}
gstreamerPath = '/Library/Frameworks/GStreamer.framework';
gstreamerBinPath = `${gstreamerPath}/Commands`;
gstreamerPkgConfigPath = `${gstreamerPath}/lib/pkgconfig`;
} else if (process.platform === 'linux') {
// Determine what flavor of linux is running using exec. Branch from
// there to install the necessary package and tool dependencies for
// developing with gstreamer on that flavor of linux.
let distro = await parseEtcRelease();
if (distro.name && distro.versionId) {
core.info(`Determined: ${distro.name} - ${distro.versionId}`);
if (distro.name in DistroVersionPackageMap) {
let config = DistroVersionPackageMap[distro.name];
if (config.versionIds.includes(distro.versionId)) {
core.info('Performing pre-req package installation...');
// Do package installation for the distro config.
for (const command of config.commands) {
await exec.exec(command.cmd, command.args, { env: config.env });
}
let mesonVersion;
await exec.exec('meson', ['--version'], {
listeners: {
stdline: (line) => {
mesonVersion = `meson-${line}`;
},
},
});
// Come up with a unique key and attempt to fetch the cache under
// that key. If not found, clone, configure, build, and cache
// the result before continuing.
// NOTE: Increment keyVersion if anything about the caching changes.
const keyVersion = 1;
const gstsrc = 'gstreamer_src';
const prefix = '/usr';
const opt = { cwd: `${process.cwd()}/${gstsrc}` };
const key = `${github.context.repo.owner}-${github.context.repo.repo}-${gitUrl}-${version}-${arch}-${distro.name}-${distro.versionId}-${mesonVersion}-${keyVersion}`;
const cacheKey = await cache.restoreCache([gstsrc], key);
if (!cacheKey) {
core.info(`Pre-built not found in cache; creating a new one. (key: "${key}")`);
// Clone the source tree, configure, compile, and save cache.
await exec.exec('git', ['config', '--global', 'http.postBuffer', '524288000']);
await exec.exec('git', [
'clone',
'--progress',
'--verbose',
'--depth',
'1',
'--branch',
version,
gitUrl,
gstsrc,
]);
const linuxBuildArgs = [
'-Dges=disabled',
'-Dtests=disabled',
'-Dexamples=disabled',
'-Dgst-examples=disabled',
'-Ddoc=disabled',
'-Dgtk_doc=disabled',
'-Dgpl=enabled',
];
const buildArgs = combineBuildArgs(linuxBuildArgs, userBuildArgs);
await exec.exec(
'meson',
[
'setup',
`--prefix=${prefix}`,
...buildArgs,
'builddir',
],
opt
);
await exec.exec('meson', ['compile', '-C', 'builddir'], opt);
await cache.saveCache([gstsrc], key);
core.info(`New cache created for this key: "${key}"`);
} else {
core.info(`Found pre-built cache; using it. (key: "${key}")`);
}
// Install (runners are passwordless sudo, presently)
core.info(`Installing gstreamer ${version} to ${prefix}`);
await exec.exec('sudo', ['meson', 'install', '-C', 'builddir'], opt);
gstreamerPath = `${prefix}/lib/${arch}-linux-gnu/gstreamer-1.0`;
gstreamerBinPath = `${prefix}/bin`;
gstreamerPkgConfigPath = `${prefix}/lib/${arch}-linux-gnu/pkgconfig`;
} else {
core.setFailed(
`could not find a distro configuration matching ${distro.name}, ${distro.versionId}`
);
}
} else {
core.setFailed(`unknown distro name "${distro.name}" in available configurations`);
}
} else {
core.setFailed(`could not infer distro from /etc/*-release`);
}
} else {
// Pitch a fit / it's unsupported right now.
core.setFailed(`${process.platform} is unsupported by this action at this time.`);
}
core.debug(new Date().toTimeString());
// Configure the output(s), add 'bin' to the PATH (via GITHUB_PATH)
core.setOutput('gstreamerPath', gstreamerPath);
core.info(`Adding ${gstreamerBinPath} to PATH`);
core.addPath(gstreamerBinPath);
core.info(`Adding ${gstreamerPkgConfigPath} to PKG_CONFIG_PATH`);
let PKG_CONFIG_PATH = process.env.PKG_CONFIG_PATH;
if (PKG_CONFIG_PATH) {
PKG_CONFIG_PATH = `${PKG_CONFIG_PATH}:${gstreamerPkgConfigPath}`;
} else {
PKG_CONFIG_PATH = gstreamerPkgConfigPath;
}
core.exportVariable('PKG_CONFIG_PATH', PKG_CONFIG_PATH);
} catch (error) {
core.setFailed(error.message);
}
}
run();