-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
87 lines (70 loc) · 3.26 KB
/
index.js
File metadata and controls
87 lines (70 loc) · 3.26 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
const assert = require('assert');
const core = require('@actions/core');
const exec = require('@actions/exec');
const fs = require('fs');
const mvdir = require('mvdir');
const path = require('path');
const tc = require('@actions/tool-cache');
const { Octokit } = require("@octokit/rest");
const chmodx = (path) => fs.promises.chmod(path, '755');
async function find(version, os, cc, options = {}) {
const owner = 'wangwei1237';
const repo = 'setup-vmaf';
const octokit = new Octokit({ auth: options.token });
const response = await octokit.repos.listReleases({ owner, repo });
const release = response.data.find(({ tag_name }) => tag_name.startsWith('libvmaf-' + version));
if (!release) {
return {release, tag: '', url: ''};
}
return {
release,
tag: release.tag_name,
url: `https://github.com/${owner}/${repo}/releases/download/${release.tag_name}/libvmaf-${os}-${cc}.tar.gz`,
};
}
// most @actions toolkit packages have async methods
async function run() {
try {
const token = [process.env.INPUT_TOKEN, process.env.INPUT_GITHUB_TOKEN, process.env.GITHUB_TOKEN]
.filter((token) => token)[0];
const platform = core.getInput('os');
const cc = core.getInput('cc');
const version = core.getInput('version').slice(1);
const {tag, url} = await find(version, platform, cc, { token });
if (!tag) {
console.log('can not find libvmaf-' + version + ', please contact the author of setup-vmaf actions.');
throw('can not find libvmaf-' + version + ', please contact the author of setup-vmaf actions.');
}
// Search in the cache if version is already installed
let installPath = tc.find('libvmaf', version, platform + '-' + cc);
if (!installPath) {
const downloadPath = await tc.downloadTool(url, void 0, token);
const extractPath = await tc.extractTar(downloadPath);
installPath = await tc.cacheDir(extractPath, 'libvmaf', version, platform + '-' + cc);
}
assert.ok(installPath);
console.log('mv the libvmaf to path: ${{github.workspace}}/../../');
const targetPath = '../../libvmaf';
await mvdir(installPath + '/libvmaf', targetPath, {copy: true});
const vmafPath = path.join(targetPath, '/bin/vmaf');
await chmodx(vmafPath);
assert.ok(await exec.exec(vmafPath, ['--version']) === 0);
core.addPath(targetPath + '/bin');
let pkgconfigPath = '';
if (platform.startsWith('ubuntu')) {
pkgconfigPath = targetPath + '/lib/x86_64-linux-gnu/pkgconfig';
} else if (platform.startsWith('macos')) {
pkgconfigPath = targetPath + '/lib/pkgconfig';
}
// fix the include path for pkgconfig.
let pkgconfig = fs.readFileSync(pkgconfigPath + '/libvmaf.pc', 'utf8');
pkgconfig = pkgconfig.replace(/Cflags:.*/, 'Cflags: -I${includedir}');
fs.writeFileSync(pkgconfigPath + '/libvmaf.pc', pkgconfig, 'utf8');
console.log('pkgconfigPath: ' + pkgconfigPath);
core.setOutput('libvmaf-path', targetPath);
core.setOutput('pkgconfig-path', pkgconfigPath);
} catch (error) {
core.setFailed(error.message);
}
}
run();