Skip to content

Commit

Permalink
Add missing files
Browse files Browse the repository at this point in the history
  • Loading branch information
iamralch committed Mar 18, 2021
1 parent a44d5bf commit db6c084
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 7 deletions.
8 changes: 5 additions & 3 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions index.js
@@ -1,13 +1,15 @@
const core = require('@actions/core');
const {gitup} = require('./setup');
const {gitup, envup} = require('./setup');

// most @actions toolkit packages have async methods
async function run() {
try {
const ms = core.getInput('token');
// get input
const token = core.getInput('token');

// setup env
core.info(`Setup env ...`);
await envup();
envup();

// setup git
core.info(`Setup git ...`);
Expand Down
41 changes: 41 additions & 0 deletions setup.js
@@ -0,0 +1,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 github-action@users.noreply.github.com`)
await sh(`git config --global url."https://${token}:x-oauth-basic@github.com/".insteadOf "https://github.com/"`);
}

function envup() {
const owner = getRepositoryOwner(process.env.GITHUB_REPOSITORY);
core.exportVariable('GOPRIVATE', `github.com/${owner}/*`);
}

module.exports = {gitup, envup};

0 comments on commit db6c084

Please sign in to comment.