mirror of
https://github.com/naveenrajm7/rpmbuild.git
synced 2025-07-12 04:13:50 +00:00
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.
This commit is contained in:
14
src/main.ts
14
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}`);
|
||||
|
Reference in New Issue
Block a user