generated from actions/javascript-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.js
41 lines (36 loc) · 1.13 KB
/
setup.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
const {exec} = require('child_process');
const core = require('@actions/core');
/**
* Execute simple shell command (async wrapper).
* @param {String} cmd
* @return {Object} { stdout: String, stderr: String }
*/
async function sh(cmd) {
return new Promise(function (resolve, reject) {
exec(cmd, (err, stdout, stderr) => {
if (err) {
reject(err);
} else {
resolve({stdout, stderr});
}
});
});
}
/**
* Get the repository owner from the repository string.
* @param {string} repository
* @return {string} The owner of the repository.
*/
function getRepositoryOwner(repository) {
return repository ? repository.split('/')[0] : null;
}
async function gitup(token) {
await sh(`git config --global user.name GitHub Action`)
await sh(`git config --global user.email [email protected]`)
await sh(`git config --global url."https://${token}:[email protected]/".insteadOf "https://github.com/"`);
}
function envup() {
const owner = getRepositoryOwner(process.env.GITHUB_REPOSITORY);
core.exportVariable('GOPRIVATE', `github.com/${owner}/*`);
}
module.exports = {gitup, envup};