mirror of
https://github.com/audacity/audacity-actions.git
synced 2025-12-10 03:56:07 -06:00
107 lines
2.5 KiB
JavaScript
107 lines
2.5 KiB
JavaScript
const core = require('@actions/core');
|
|
const exec = require('@actions/exec');
|
|
|
|
const path = require('path');
|
|
const md5 = require('md5');
|
|
const fs = require('fs');
|
|
|
|
const runningOnCI = process.env['CI']
|
|
|
|
global.workspaceDir = process.env['GITHUB_WORKSPACE']
|
|
global.conanCachePath = path.join(workspaceDir, '.conan')
|
|
|
|
function log(msg) {
|
|
if (runningOnCI) {
|
|
core.info(msg);
|
|
} else {
|
|
console.log(msg);
|
|
}
|
|
}
|
|
|
|
function error(msg) {
|
|
if (runningOnCI) {
|
|
core.error(msg);
|
|
} else {
|
|
console.error(msg);
|
|
}
|
|
}
|
|
|
|
async function execWithLog(programm, arguments) {
|
|
if (runningOnCI) {
|
|
return exec.exec(programm, arguments);
|
|
} else {
|
|
return exec.exec(programm, arguments, {
|
|
listeners: {
|
|
/*debug: data => {
|
|
log(data);
|
|
},*/
|
|
stdout: data => {
|
|
log(data.toString());
|
|
},
|
|
stderr: data => {
|
|
error(data.toString());
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
async function getExecOutput(programm, arguments) {
|
|
if (runningOnCI) {
|
|
return exec.getExecOutput(programm, arguments);
|
|
} else {
|
|
return exec.getExecOutput(programm, arguments, {
|
|
listeners: {
|
|
stdout: data => {
|
|
log(data.toString());
|
|
},
|
|
stderr: data => {
|
|
error(data.toString());
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
async function awaitAll(array, functor) {
|
|
return await Promise.all(array.map(async (item) => functor(item)))
|
|
}
|
|
|
|
async function getMD5(filePath) {
|
|
const depsContent = await fs.promises.readFile(filePath);
|
|
return md5(depsContent);
|
|
}
|
|
|
|
function getDateString() {
|
|
const currentDate = new Date();
|
|
|
|
return [
|
|
currentDate.getFullYear(),
|
|
('0' + (currentDate.getMonth() + 1)).slice(-2),
|
|
('0' + currentDate.getDate()).slice(-2)
|
|
].join('')
|
|
}
|
|
|
|
const sleep = (waitTimeInMs) => new Promise(resolve => setTimeout(resolve, waitTimeInMs));
|
|
|
|
process.on('unhandledRejection', (reason, p) => {
|
|
error(reason);
|
|
core.setFailed(reason);
|
|
process.exit(1);
|
|
}).on('uncaughtException', err => {
|
|
error(err);
|
|
core.setFailed(err);
|
|
process.exit(1);
|
|
});
|
|
|
|
module.exports = {
|
|
log: log,
|
|
error: error,
|
|
execWithLog: execWithLog,
|
|
getExecOutput: getExecOutput,
|
|
sleep: sleep,
|
|
awaitAll: awaitAll,
|
|
getMD5: getMD5,
|
|
getDateString: getDateString,
|
|
}
|