From 626822dc92cd00924eadb5680fd4694a80143349 Mon Sep 17 00:00:00 2001 From: Belden Lyman Date: Fri, 17 Sep 2021 10:59:52 -0700 Subject: [PATCH 1/2] Fix comment Drive-by: * Ignore vim swapfiles --- .gitignore | 3 +++ src/main.ts | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) 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..6f446b6 100644 --- a/src/main.ts +++ b/src/main.ts @@ -40,7 +40,7 @@ async function run() { // setup rpm tree await exec.exec('rpmdev-setuptree'); - // Copy spec file from path specFile to /root/rpmbuild/SPECS/ + // Copy spec file from path specFile to /github/home/rpmbuild/SPECS/ await exec.exec(`cp /github/workspace/${specFile} /github/home/rpmbuild/SPECS/`); // Make the code in /github/workspace/ into a tar.gz, located in /github/home/rpmbuild/SOURCES/ From 2857cd9b80e22d0a348ff8c6ca6fb067d9c0682f Mon Sep 17 00:00:00 2001 From: Belden Lyman Date: Fri, 17 Sep 2021 11:00:28 -0700 Subject: [PATCH 2/2] Ensure rpmbuild can find spec files in subdirs Resolves https://github.com/naveenrajm7/rpmbuild/issues/7 Previously, ```js await exec.exec( `rpmbuild -ba /github/home/rpmbuild/SPECS/${specFile}` ); ``` would fail when given this input: ```yml - name: build RPM package id: my-rpm uses: naveenrajm7/rpmbuild with: spec_file: "rpm/my-specfile.spec" ``` The failure arises because previously, the code said: ```js const specFile = core.getInput('spec_file'); await exec.exec(`cp /github/workspace/${specFile} /github/home/rpmbuild/SPECS/`); ``` Which meant the commands which ended up being run in the rpmbuild-container were equivalent to: ```sh $ cp /github/workspace/rpm/my-specfile.spec /github/home/rpmbuild/SPECS/ $ rpmbuild -ba /home/github/home/rpmbuild/SPECS/rpm/my-specfile.spec ``` `rpmbuild -ba` fails in this situation because the `cp` does not copy the specfile into `/github/home/rpmbuild/SPECS/rpm/my-specfile.spec`, but instead into `/github/home/rpmbuild/SPECS/my-specfile.spec`. The solution is to use the basename of the specfile for `rpmbuild -ba`. As a matter of personal preference, I've changed the shell commands to always operate on source-file and destination-file, rather than on source-file and destination-paths. I've just generally found my own scripts easier to maintain when I'm a little more explicit like this. --- src/main.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main.ts b/src/main.ts index 6f446b6..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 = ''; @@ -41,7 +47,7 @@ async function run() { await exec.exec('rpmdev-setuptree'); // Copy spec file from path specFile to /github/home/rpmbuild/SPECS/ - await exec.exec(`cp /github/workspace/${specFile} /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}`);