From 08c27c427d059347bf3b818b35243a10274c5a70 Mon Sep 17 00:00:00 2001 From: Naveenraj M Date: Mon, 30 Mar 2020 16:01:37 +0530 Subject: [PATCH] code clean --- lib/main.js | 20 +++++++++----------- src/main.ts | 22 +++++++++------------- 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/lib/main.js b/lib/main.js index 6951def..7c56d53 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,23 +23,24 @@ function run() { const repo = context.repo.repo; const ref = context.ref; const version = "1.0.0"; - console.log(`We can even get context data, like the owner: ${owner}, repo: ${repo}, ref: ${ref}`); - const specFile = core.getInput('specFile'); - console.log(`Hello ${specFile} from inside a container`); + // get inputs from workflow + const specFile = core.getInput('spec_file'); // setup rpm tree yield exec.exec('rpmdev-setuptree'); // 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}`); + // create directory to match source file - 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`); + // Create Source tar.gz file yield exec.exec(`tar -czvf ${repo}-${version}.tar.gz ${repo}-${version}`); // Get repo files from /github/workspace/ yield exec.exec('ls -la '); + // Copy tar.gz file to source 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 try { yield exec.exec(`rpmbuild -ba /github/home/rpmbuild/SPECS/${specFile}`); @@ -47,13 +48,10 @@ function run() { catch (err) { core.setFailed(`action failed with error: ${err}`); } - // Get path for rpm - //const rpmPath = await exec.exec('node', ['index.js', 'foo=bar'], options); + // Verify RPM created yield exec.exec('ls /github/home/rpmbuild/RPMS'); // setOutput rpm_path to /root/rpmbuild/RPMS , to be consumed by other actions like // 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 = ''; yield cp.exec('ls /github/home/rpmbuild/SRPMS/', (err, stdout, stderr) => { if (err) { diff --git a/src/main.ts b/src/main.ts index 1b7759d..3a6072f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -17,33 +17,32 @@ async function run() { const version = "1.0.0" - console.log(`We can even get context data, like the owner: ${owner}, repo: ${repo}, ref: ${ref}`); - - const specFile = core.getInput('specFile'); - console.log(`Hello ${specFile} from inside a container`); + // get inputs from workflow + const specFile = core.getInput('spec_file'); // setup rpm tree await exec.exec('rpmdev-setuptree'); // 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}`) + // create directory to match source file - 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`); + // Create Source tar.gz file await exec.exec(`tar -czvf ${repo}-${version}.tar.gz ${repo}-${version}`); // Get repo files from /github/workspace/ await exec.exec('ls -la '); + // Copy tar.gz file to source 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 try { await exec.exec( @@ -53,14 +52,11 @@ async function run() { core.setFailed(`action failed with error: ${err}`); } - // Get path for rpm - //const rpmPath = await exec.exec('node', ['index.js', 'foo=bar'], options); + // Verify RPM created await exec.exec('ls /github/home/rpmbuild/RPMS'); // setOutput rpm_path to /root/rpmbuild/RPMS , to be consumed by other actions like // 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 = ''; await cp.exec('ls /github/home/rpmbuild/SRPMS/', (err, stdout, stderr) => {