code clean

This commit is contained in:
Naveenraj M
2020-03-30 16:01:37 +05:30
parent dd228e741d
commit 08c27c427d
2 changed files with 18 additions and 24 deletions

View File

@ -23,23 +23,24 @@ function run() {
const repo = context.repo.repo; const repo = context.repo.repo;
const ref = context.ref; const ref = context.ref;
const version = "1.0.0"; const version = "1.0.0";
console.log(`We can even get context data, like the owner: ${owner}, repo: ${repo}, ref: ${ref}`); // get inputs from workflow
const specFile = core.getInput('specFile'); const specFile = core.getInput('spec_file');
console.log(`Hello ${specFile} from inside a container`);
// setup rpm tree // setup rpm tree
yield exec.exec('rpmdev-setuptree'); yield exec.exec('rpmdev-setuptree');
// Copy spec file from path specFile to /root/rpmbuild/SPECS/ // Copy spec file from path specFile to /root/rpmbuild/SPECS/
yield io.cp(`/github/workspace/${specFile}`, '/github/home/rpmbuild/SPECS/'); yield exec.exec(`cp /github/workspace/${specFile} /github/home/rpmbuild/SPECS/`);
// Dowload tar.gz file of source code
yield exec.exec(`curl -L --output tmp.tar.gz https://api.github.com/repos/${owner}/${repo}/tarball/${ref}`); yield exec.exec(`curl -L --output tmp.tar.gz https://api.github.com/repos/${owner}/${repo}/tarball/${ref}`);
// create directory to match source file - repo-version
yield exec.exec(`mkdir ${repo}-${version}`); yield exec.exec(`mkdir ${repo}-${version}`);
// Extract source code to directory
yield exec.exec(`tar xvf tmp.tar.gz -C ${repo}-${version} --strip-components 1`); yield exec.exec(`tar xvf tmp.tar.gz -C ${repo}-${version} --strip-components 1`);
// Create Source tar.gz file
yield exec.exec(`tar -czvf ${repo}-${version}.tar.gz ${repo}-${version}`); yield exec.exec(`tar -czvf ${repo}-${version}.tar.gz ${repo}-${version}`);
// Get repo files from /github/workspace/ // Get repo files from /github/workspace/
yield exec.exec('ls -la '); yield exec.exec('ls -la ');
// Copy tar.gz file to source
yield exec.exec(`cp ${repo}-${version}.tar.gz /github/home/rpmbuild/SOURCES/`); yield exec.exec(`cp ${repo}-${version}.tar.gz /github/home/rpmbuild/SOURCES/`);
// Copy tar.gz file to /root/rpmbuild/SOURCES
// make sure the name of tar.gz is same as given in Source of spec file
//await io.cp(tarBallPath, '/root/rpmbuild/SOURCES');
// Execute rpmbuild // Execute rpmbuild
try { try {
yield exec.exec(`rpmbuild -ba /github/home/rpmbuild/SPECS/${specFile}`); yield exec.exec(`rpmbuild -ba /github/home/rpmbuild/SPECS/${specFile}`);
@ -47,13 +48,10 @@ function run() {
catch (err) { catch (err) {
core.setFailed(`action failed with error: ${err}`); core.setFailed(`action failed with error: ${err}`);
} }
// Get path for rpm // Verify RPM created
//const rpmPath = await exec.exec('node', ['index.js', 'foo=bar'], options);
yield exec.exec('ls /github/home/rpmbuild/RPMS'); yield exec.exec('ls /github/home/rpmbuild/RPMS');
// setOutput rpm_path to /root/rpmbuild/RPMS , to be consumed by other actions like // setOutput rpm_path to /root/rpmbuild/RPMS , to be consumed by other actions like
// actions/upload-release-asset // actions/upload-release-asset
// If you want to upload yourself , need to write api call to upload as asset
//core.setOutput("rpmPath", rpmPath)
let myOutput = ''; let myOutput = '';
yield cp.exec('ls /github/home/rpmbuild/SRPMS/', (err, stdout, stderr) => { yield cp.exec('ls /github/home/rpmbuild/SRPMS/', (err, stdout, stderr) => {
if (err) { if (err) {

View File

@ -17,33 +17,32 @@ async function run() {
const version = "1.0.0" const version = "1.0.0"
console.log(`We can even get context data, like the owner: ${owner}, repo: ${repo}, ref: ${ref}`); // get inputs from workflow
const specFile = core.getInput('spec_file');
const specFile = core.getInput('specFile');
console.log(`Hello ${specFile} from inside a container`);
// setup rpm tree // setup rpm tree
await exec.exec('rpmdev-setuptree'); await exec.exec('rpmdev-setuptree');
// Copy spec file from path specFile to /root/rpmbuild/SPECS/ // Copy spec file from path specFile to /root/rpmbuild/SPECS/
await io.cp(`/github/workspace/${specFile}`, '/github/home/rpmbuild/SPECS/'); await exec.exec(`cp /github/workspace/${specFile} /github/home/rpmbuild/SPECS/`);
// Dowload tar.gz file of source code
await exec.exec(`curl -L --output tmp.tar.gz https://api.github.com/repos/${owner}/${repo}/tarball/${ref}`) await exec.exec(`curl -L --output tmp.tar.gz https://api.github.com/repos/${owner}/${repo}/tarball/${ref}`)
// create directory to match source file - repo-version
await exec.exec(`mkdir ${repo}-${version}`); await exec.exec(`mkdir ${repo}-${version}`);
// Extract source code to directory
await exec.exec(`tar xvf tmp.tar.gz -C ${repo}-${version} --strip-components 1`); await exec.exec(`tar xvf tmp.tar.gz -C ${repo}-${version} --strip-components 1`);
// Create Source tar.gz file
await exec.exec(`tar -czvf ${repo}-${version}.tar.gz ${repo}-${version}`); await exec.exec(`tar -czvf ${repo}-${version}.tar.gz ${repo}-${version}`);
// Get repo files from /github/workspace/ // Get repo files from /github/workspace/
await exec.exec('ls -la '); await exec.exec('ls -la ');
// Copy tar.gz file to source
await exec.exec(`cp ${repo}-${version}.tar.gz /github/home/rpmbuild/SOURCES/`); await exec.exec(`cp ${repo}-${version}.tar.gz /github/home/rpmbuild/SOURCES/`);
// Copy tar.gz file to /root/rpmbuild/SOURCES
// make sure the name of tar.gz is same as given in Source of spec file
//await io.cp(tarBallPath, '/root/rpmbuild/SOURCES');
// Execute rpmbuild // Execute rpmbuild
try { try {
await exec.exec( await exec.exec(
@ -53,14 +52,11 @@ async function run() {
core.setFailed(`action failed with error: ${err}`); core.setFailed(`action failed with error: ${err}`);
} }
// Get path for rpm // Verify RPM created
//const rpmPath = await exec.exec('node', ['index.js', 'foo=bar'], options);
await exec.exec('ls /github/home/rpmbuild/RPMS'); await exec.exec('ls /github/home/rpmbuild/RPMS');
// setOutput rpm_path to /root/rpmbuild/RPMS , to be consumed by other actions like // setOutput rpm_path to /root/rpmbuild/RPMS , to be consumed by other actions like
// actions/upload-release-asset // actions/upload-release-asset
// If you want to upload yourself , need to write api call to upload as asset
//core.setOutput("rpmPath", rpmPath)
let myOutput = ''; let myOutput = '';
await cp.exec('ls /github/home/rpmbuild/SRPMS/', (err, stdout, stderr) => { await cp.exec('ls /github/home/rpmbuild/SRPMS/', (err, stdout, stderr) => {