From 2ff761f1ba2c50e4e8be375dce1d1513f30a0f94 Mon Sep 17 00:00:00 2001 From: Naveenraj M Date: Mon, 30 Mar 2020 18:23:27 +0530 Subject: [PATCH] read values from spec file --- lib/download-release-archive.js | 2 +- lib/main.js | 29 +++++++++++++++++++++------- src/download-release-archive.ts | 2 +- src/main.ts | 34 +++++++++++++++++++++++++-------- 4 files changed, 50 insertions(+), 17 deletions(-) diff --git a/lib/download-release-archive.js b/lib/download-release-archive.js index 7252730..348a884 100644 --- a/lib/download-release-archive.js +++ b/lib/download-release-archive.js @@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; const { Octokit } = require('@octokit/rest'); -const fs = require('fs'); +//const fs = require('fs'); const tc = require('@actions/tool-cache'); function download_archive(owner, repo, ref) { return __awaiter(this, void 0, void 0, function* () { diff --git a/lib/main.js b/lib/main.js index 7c56d53..fca350a 100644 --- a/lib/main.js +++ b/lib/main.js @@ -12,8 +12,8 @@ const core = require('@actions/core'); const github = require('@actions/github'); const exec = require('@actions/exec'); const io = require('@actions/io'); -const download_tar = require('./download-release-archive'); const cp = require('child_process'); +const fs = require('fs'); function run() { return __awaiter(this, void 0, void 0, function* () { try { @@ -22,25 +22,40 @@ function run() { const owner = context.repo.owner; const repo = context.repo.repo; const ref = context.ref; - const version = "1.0.0"; // get inputs from workflow + // specFile name const specFile = core.getInput('spec_file'); + // Read spec file and get values + var data = fs.readFileSync('cello/cello.spec', 'utf8'); + let name = ''; + let version = ''; + for (var line of data.split('\n')) { + var lineArray = line.split(/[ ]+/); + if (lineArray[0].includes('Name')) { + name = name + lineArray[1]; + } + if (lineArray[0].includes('Version')) { + version = version + lineArray[1]; + } + } + console.log(`name: ${name}`); + console.log(`version: ${version}`); // setup rpm tree yield exec.exec('rpmdev-setuptree'); // Copy spec file from path specFile to /root/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}`); + // create directory to match source file - name-version + yield exec.exec(`mkdir ${name}-${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 ${name}-${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 ${name}-${version}.tar.gz ${name}-${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/`); + yield exec.exec(`cp ${name}-${version}.tar.gz /github/home/rpmbuild/SOURCES/`); // Execute rpmbuild try { yield exec.exec(`rpmbuild -ba /github/home/rpmbuild/SPECS/${specFile}`); diff --git a/src/download-release-archive.ts b/src/download-release-archive.ts index 2228069..a74cd10 100644 --- a/src/download-release-archive.ts +++ b/src/download-release-archive.ts @@ -1,5 +1,5 @@ const { Octokit } = require('@octokit/rest'); -const fs = require('fs'); +//const fs = require('fs'); const tc = require('@actions/tool-cache'); diff --git a/src/main.ts b/src/main.ts index 3a6072f..4d099ea 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2,8 +2,8 @@ const core = require('@actions/core'); const github = require('@actions/github'); const exec = require('@actions/exec'); const io = require('@actions/io'); -const download_tar = require('./download-release-archive'); const cp = require('child_process'); +const fs = require('fs'); async function run() { try { @@ -15,11 +15,29 @@ async function run() { const repo = context.repo.repo const ref = context.ref - const version = "1.0.0" - // get inputs from workflow + // specFile name const specFile = core.getInput('spec_file'); + // Read spec file and get values + var data = fs.readFileSync('cello/cello.spec', 'utf8'); + + let name = ''; + let version = ''; + + for (var line of data.split('\n')){ + var lineArray = line.split(/[ ]+/); + if(lineArray[0].includes('Name')){ + name = name+lineArray[1]; + } + if(lineArray[0].includes('Version')){ + version = version+lineArray[1]; + } + } + + console.log(`name: ${name}`); + console.log(`version: ${version}`); + // setup rpm tree await exec.exec('rpmdev-setuptree'); @@ -29,19 +47,19 @@ async function run() { // 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}`); + // create directory to match source file - name-version + await exec.exec(`mkdir ${name}-${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 ${name}-${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 ${name}-${version}.tar.gz ${name}-${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/`); + await exec.exec(`cp ${name}-${version}.tar.gz /github/home/rpmbuild/SOURCES/`); // Execute rpmbuild try {