diff --git a/.gitignore b/.gitignore index f83d13b..347e09b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,8 @@ # See http://help.github.com/ignore-files/ for more about ignoring files. +# editor +*.swp + # dependencies package-lock.json node_modules diff --git a/src/main.ts b/src/main.ts index 737cb00..423186f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,6 +4,7 @@ const exec = require('@actions/exec'); const io = require('@actions/io'); const cp = require('child_process'); const fs = require('fs'); +const path = require('path'); async function run() { try { @@ -18,10 +19,15 @@ async function run() { // get inputs from workflow // specFile name - const specFile = core.getInput('spec_file'); + const configPath = core.getInput('spec_file'); // user input, eg: `foo.spec' or `rpm/foo.spec' + const basename = path.basename(configPath); // always just `foo.spec` + const specFile = { + srcFullPath: `/github/workspace/${configPath}`, + destFullPath: `/github/home/rpmbuild/SPECS/${basename}`, + }; // Read spec file and get values - var data = fs.readFileSync(specFile, 'utf8'); + var data = fs.readFileSync(specFile.srcFullPath, 'utf8'); let name = ''; let version = ''; @@ -40,8 +46,8 @@ async function run() { // setup rpm tree await exec.exec('rpmdev-setuptree'); - // Copy spec file from path specFile to /root/rpmbuild/SPECS/ - await exec.exec(`cp /github/workspace/${specFile} /github/home/rpmbuild/SPECS/`); + // Copy spec file from path specFile to /github/home/rpmbuild/SPECS/ + await exec.exec(`cp ${specFile.srcFullPath} ${specFile.destFullPath}`); // Make the code in /github/workspace/ into a tar.gz, located in /github/home/rpmbuild/SOURCES/ const oldGitDir = process.env.GIT_DIR; @@ -52,7 +58,7 @@ async function run() { // Execute rpmbuild , -ba generates both RPMS and SPRMS try { await exec.exec( - `rpmbuild -ba /github/home/rpmbuild/SPECS/${specFile}` + `rpmbuild -ba ${specFile.destFullPath}` ); } catch (err) { core.setFailed(`action failed with error: ${err}`);