From 7e607fe3255965f51ec46c6cc30d8fa4b915caf3 Mon Sep 17 00:00:00 2001 From: Naveenraj M Date: Sun, 29 Mar 2020 20:07:44 +0530 Subject: [PATCH] dowloaded archive into tar --- lib/download-release-archive.js | 24 +++++++++------------- lib/main.js | 6 ++---- src/download-release-archive.ts | 35 ++++++++++++--------------------- src/main.ts | 7 +++---- 4 files changed, 27 insertions(+), 45 deletions(-) diff --git a/lib/download-release-archive.js b/lib/download-release-archive.js index 33634b4..59b70f4 100644 --- a/lib/download-release-archive.js +++ b/lib/download-release-archive.js @@ -16,27 +16,21 @@ function download_archive(owner, repo, ref) { try { const octokit = new Octokit(); const archive_format = "tarball"; - const ref = "v1.0.0"; + const tag = "v1.0.0"; + const tarFile = `${tag}.tar.gz`; console.log("Calling API ..."); - octokit.repos.getBranch({ + octokit.repos.getArchiveLink({ owner, repo, + archive_format, ref }).then(({ data }) => { - console.log(data); + fs.writeFileSync(tarFile, Buffer.from(data)); + }).catch(function (error) { + console.log(error); }); - // octokit.repos.getArchiveLink({ - // owner, - // repo, - // archive_format, - // ref - // }).then(( { data }) => { - // console.log(data) - // }); - //console.log(`Download Location : ${downloadLocation}`); - //const tarBallPath = await tc.downloadTool(downloadLocation); - //console.log(`Tarball Location : ${tarBallPath}`); - //return tarBallPath; + console.log(`Tarball Location : ${tarFile}`); + return tarFile; } catch (error) { core.setFailed(error.message); diff --git a/lib/main.js b/lib/main.js index 709ebb9..c5c6ce0 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,16 +28,14 @@ function run() { console.log(`Hello ${specFile} from inside a container`); // Get repo files from /github/workspace/ yield exec.exec('ls -la /github/workspace'); - // LOG: know current directory - yield exec.exec('pwd && echo $HOME && ls'); // Copy spec file from path specFile to /root/rpmbuild/SPECS/ - //await io.cp('path/to/file', 'path/to/dest'); + yield io.cp('/github/workspace/cello.spec', '/root/rpmbuild/SPECS/'); // Get tar.gz file of release // 1. Write API call to download tar.gz from release OR // 2. Create tar.gz of /github/workspace to get tar of source code // 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('path/to/file', '/root/rpmbuild/SOURCES'); + yield io.cp(tarBallPath, '/root/rpmbuild/SOURCES'); // Execute rpmbuild try { yield exec.exec(`rpmbuild -ba ${specFile}`); diff --git a/src/download-release-archive.ts b/src/download-release-archive.ts index 46d5a5f..0db3181 100644 --- a/src/download-release-archive.ts +++ b/src/download-release-archive.ts @@ -9,35 +9,26 @@ async function download_archive(owner, repo, ref ) { const octokit = new Octokit(); const archive_format = "tarball"; - const ref = "v1.0.0" + + const tag = "v1.0.0" + + const tarFile = `${tag}.tar.gz`; console.log("Calling API ..."); - - octokit.repos.getBranch({ + octokit.repos.getArchiveLink({ owner, repo, + archive_format, ref - }).then(( { data }) => { - console.log(data); - }); + }).then(( { data }) => { + fs.writeFileSync(tarFile, Buffer.from(data)); + }).catch( function(error){ + console.log(error); + }); + console.log(`Tarball Location : ${tarFile}`); - // octokit.repos.getArchiveLink({ - // owner, - // repo, - // archive_format, - // ref - // }).then(( { data }) => { - // console.log(data) - // }); - - //console.log(`Download Location : ${downloadLocation}`); - - //const tarBallPath = await tc.downloadTool(downloadLocation); - - //console.log(`Tarball Location : ${tarBallPath}`); - - //return tarBallPath; + return tarFile; } catch (error) { core.setFailed(error.message); diff --git a/src/main.ts b/src/main.ts index bd879c4..b5c27ed 100644 --- a/src/main.ts +++ b/src/main.ts @@ -26,11 +26,10 @@ async function run() { // Get repo files from /github/workspace/ await exec.exec('ls -la /github/workspace'); - // LOG: know current directory - await exec.exec('pwd && echo $HOME && ls'); + // Copy spec file from path specFile to /root/rpmbuild/SPECS/ - //await io.cp('path/to/file', 'path/to/dest'); + await io.cp('/github/workspace/cello.spec', '/root/rpmbuild/SPECS/'); // Get tar.gz file of release // 1. Write API call to download tar.gz from release OR @@ -38,7 +37,7 @@ async function run() { // 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('path/to/file', '/root/rpmbuild/SOURCES'); + await io.cp(tarBallPath, '/root/rpmbuild/SOURCES'); // Execute rpmbuild try {