From 9019e7252b3ae57d3ea1eeed87f5799fc296ed88 Mon Sep 17 00:00:00 2001 From: Naveenraj M Date: Mon, 30 Mar 2020 02:15:32 +0530 Subject: [PATCH] create tar.gz from source --- lib/main.js | 40 ++++++++++++++++++++-------------------- src/main.ts | 44 +++++++++++++++++++++++--------------------- 2 files changed, 43 insertions(+), 41 deletions(-) diff --git a/lib/main.js b/lib/main.js index d660e61..9798d99 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,34 +24,21 @@ function run() { 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`); + // setup rpm tree yield exec.exec('rpmdev-setuptree'); - // Get repo files from /github/workspace/ - yield exec.exec('ls -la '); // Copy spec file from path specFile to /root/rpmbuild/SPECS/ - yield io.cp('/github/workspace/cello.spec', '/github/home/rpmbuild/SPECS/'); - // Get tar.gz file of release - // await download_tar( - // owner, - // repo, - // ref - // ).then( function(filePath){ - // console.log(`Tar Path for copy : ${filePath}`); - // io.cp(`${repo}-1.0.tar.gz`, '/github/home/rpmbuild/SOURCES/'); - // }).catch(function(error){ - // console.log(error); - // }); - yield exec.exec('curl -L --output cello-1.0.0.tar.gz https://github.com/naveenrajm7/cello/archive/v1.0.0.tar.gz'); - //console.log(`Tar Path for copy : ${tarBallPath}`); - yield exec.exec('echo "$HOME"'); + yield io.cp(`/github/workspace/${specFile}`, '/github/home/rpmbuild/SPECS/'); + yield exec.exec(`cp -R /github/workspace/ /tmp/${repo}`); + yield exec.exec(`cd /tmp/ && tar -czvf ${repo}.tar.gz ${repo}`); // Get repo files from /github/workspace/ yield exec.exec('ls -la '); - yield io.cp(`${repo}-1.0.0.tar.gz`, '/github/home/rpmbuild/SOURCES/'); + yield io.cp(`/tmp/${repo}.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/cello.spec`); + yield exec.exec(`rpmbuild -ba /github/home/rpmbuild/SPECS/${specFile}`); } catch (err) { core.setFailed(`action failed with error: ${err}`); @@ -63,7 +50,20 @@ function run() { // actions/upload-release-asset // If you want to upload yourself , need to write api call to upload as asset //core.setOutput("rpmPath", rpmPath) - core.setOutput("source_rpm_path", "/github/home/rpmbuild/SRPMS"); // make option to upload source rpm + let myOutput = ''; + let myError = ''; + const options = {}; + options.listeners = { + stdout: (data) => { + myOutput += data.toString(); + }, + stderr: (data) => { + myError += data.toString(); + } + }; + options.cwd = '/github/home/rpmbuild/SRPMS/'; + yield exec.exec('ls', options); + core.setOutput("source_rpm_path", `/github/home/rpmbuild/SRPMS/${myOutput}`); // make option to upload source rpm } catch (error) { core.setFailed(error.message); diff --git a/src/main.ts b/src/main.ts index 8d4c695..fea8c69 100644 --- a/src/main.ts +++ b/src/main.ts @@ -19,33 +19,19 @@ async function run() { const specFile = core.getInput('specFile'); console.log(`Hello ${specFile} from inside a container`); + // setup rpm tree await exec.exec('rpmdev-setuptree'); - // Get repo files from /github/workspace/ - await exec.exec('ls -la '); - // Copy spec file from path specFile to /root/rpmbuild/SPECS/ - await io.cp('/github/workspace/cello.spec', '/github/home/rpmbuild/SPECS/'); + await io.cp(`/github/workspace/${specFile}`, '/github/home/rpmbuild/SPECS/'); - // Get tar.gz file of release - // await download_tar( - // owner, - // repo, - // ref - // ).then( function(filePath){ - // console.log(`Tar Path for copy : ${filePath}`); - // io.cp(`${repo}-1.0.tar.gz`, '/github/home/rpmbuild/SOURCES/'); - // }).catch(function(error){ - // console.log(error); - // }); + await exec.exec(`cp -R /github/workspace/ /tmp/${repo}`); - await exec.exec('curl -L --output cello-1.0.0.tar.gz https://github.com/naveenrajm7/cello/archive/v1.0.0.tar.gz') - //console.log(`Tar Path for copy : ${tarBallPath}`); - await exec.exec('echo "$HOME"'); + await exec.exec(`cd /tmp/ && tar -czvf ${repo}.tar.gz ${repo}`); // Get repo files from /github/workspace/ await exec.exec('ls -la '); - await io.cp(`${repo}-1.0.0.tar.gz`, '/github/home/rpmbuild/SOURCES/'); + await io.cp(`/tmp/${repo}.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 @@ -54,7 +40,7 @@ async function run() { // Execute rpmbuild try { await exec.exec( - `rpmbuild -ba /github/home/rpmbuild/SPECS/cello.spec` + `rpmbuild -ba /github/home/rpmbuild/SPECS/${specFile}` ); } catch (err) { core.setFailed(`action failed with error: ${err}`); @@ -68,7 +54,23 @@ async function run() { // actions/upload-release-asset // If you want to upload yourself , need to write api call to upload as asset //core.setOutput("rpmPath", rpmPath) - core.setOutput("source_rpm_path", "/github/home/rpmbuild/SRPMS") // make option to upload source rpm + let myOutput = ''; + let myError = ''; + + const options: any = { }; + options.listeners = { + stdout: (data: Buffer) => { + myOutput += data.toString(); + }, + stderr: (data: Buffer) => { + myError += data.toString(); + } + }; + options.cwd = '/github/home/rpmbuild/SRPMS/'; + + await exec.exec('ls', options); + + core.setOutput("source_rpm_path", `/github/home/rpmbuild/SRPMS/${myOutput}`); // make option to upload source rpm } catch (error) { core.setFailed(error.message);