mirror of
https://github.com/naveenrajm7/rpmbuild.git
synced 2025-07-13 12:33:51 +00:00
Compare commits
5 Commits
archive/ge
...
centos8
Author | SHA1 | Date | |
---|---|---|---|
55f9d4afcf | |||
0241680a99 | |||
b980813ffe | |||
2c036efa4b | |||
9ee1f018db |
@ -1,10 +1,11 @@
|
|||||||
# Using CentOS 7 with Node 12 as base image to support rpmbuild
|
# Using CentOS 8 as base image to support rpmbuild (packages will be Dist el8)
|
||||||
FROM centos:7
|
FROM centos:8
|
||||||
|
|
||||||
# Copying all contents of rpmbuild repo inside container
|
# Copying all contents of rpmbuild repo inside container
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Installing tools needed for rpmbuild , depends on specfile
|
# Installing tools needed for rpmbuild ,
|
||||||
|
# depends on BuildRequires field in specfile, (TODO: take as input & install)
|
||||||
RUN yum install -y rpm-build rpmdevtools gcc make coreutils python
|
RUN yum install -y rpm-build rpmdevtools gcc make coreutils python
|
||||||
|
|
||||||
# Setting up node to run our JS file
|
# Setting up node to run our JS file
|
||||||
|
@ -12,9 +12,11 @@ outputs:
|
|||||||
source_rpm_path:
|
source_rpm_path:
|
||||||
description: 'path to Source RPM file'
|
description: 'path to Source RPM file'
|
||||||
source_rpm_dir_path:
|
source_rpm_dir_path:
|
||||||
description: 'path to Source RPM directory'
|
description: 'path to SRPMS directory'
|
||||||
source_rpm_name:
|
source_rpm_name:
|
||||||
description: 'name of Source RPM file'
|
description: 'name of Source RPM file'
|
||||||
|
rpm_dir_path:
|
||||||
|
description: 'path to RPMS directory'
|
||||||
rpm_content_type:
|
rpm_content_type:
|
||||||
description: 'Content-type for Upload'
|
description: 'Content-type for Upload'
|
||||||
|
|
||||||
|
22
lib/main.js
22
lib/main.js
@ -19,6 +19,7 @@ function run() {
|
|||||||
try {
|
try {
|
||||||
// Get github context data
|
// Get github context data
|
||||||
const context = github.context;
|
const context = github.context;
|
||||||
|
// To be used to get contents of this git ref
|
||||||
const owner = context.repo.owner;
|
const owner = context.repo.owner;
|
||||||
const repo = context.repo.repo;
|
const repo = context.repo.repo;
|
||||||
const ref = context.ref;
|
const ref = context.ref;
|
||||||
@ -44,29 +45,30 @@ function run() {
|
|||||||
yield exec.exec('rpmdev-setuptree');
|
yield exec.exec('rpmdev-setuptree');
|
||||||
// Copy spec file from path specFile to /root/rpmbuild/SPECS/
|
// Copy spec file from path specFile to /root/rpmbuild/SPECS/
|
||||||
yield exec.exec(`cp /github/workspace/${specFile} /github/home/rpmbuild/SPECS/`);
|
yield exec.exec(`cp /github/workspace/${specFile} /github/home/rpmbuild/SPECS/`);
|
||||||
// Dowload tar.gz file of source code
|
// Dowload tar.gz file of source code, Reference : https://developer.github.com/v3/repos/contents/#get-archive-link
|
||||||
yield exec.exec(`curl -L --output tmp.tar.gz https://api.github.com/repos/${owner}/${repo}/tarball/${ref}`);
|
yield exec.exec(`curl -L --output tmp.tar.gz https://api.github.com/repos/${owner}/${repo}/tarball/${ref}`);
|
||||||
// create directory to match source file - name-version
|
// create directory to match source file - %{name}-{version}.tar.gz of spec file
|
||||||
yield exec.exec(`mkdir ${name}-${version}`);
|
yield exec.exec(`mkdir ${name}-${version}`);
|
||||||
// Extract source code to directory
|
// Extract source code
|
||||||
yield exec.exec(`tar xvf tmp.tar.gz -C ${name}-${version} --strip-components 1`);
|
yield exec.exec(`tar xvf tmp.tar.gz -C ${name}-${version} --strip-components 1`);
|
||||||
// Create Source tar.gz file
|
// Create Source tar.gz file
|
||||||
yield exec.exec(`tar -czvf ${name}-${version}.tar.gz ${name}-${version}`);
|
yield exec.exec(`tar -czvf ${name}-${version}.tar.gz ${name}-${version}`);
|
||||||
// Get repo files from /github/workspace/
|
// // list files in current directory /github/workspace/
|
||||||
yield exec.exec('ls -la ');
|
// await exec.exec('ls -la ');
|
||||||
// Copy tar.gz file to source
|
// Copy tar.gz file to source path
|
||||||
yield exec.exec(`cp ${name}-${version}.tar.gz /github/home/rpmbuild/SOURCES/`);
|
yield exec.exec(`cp ${name}-${version}.tar.gz /github/home/rpmbuild/SOURCES/`);
|
||||||
// Execute rpmbuild
|
// Execute rpmbuild , -ba generates both RPMS and SPRMS
|
||||||
try {
|
try {
|
||||||
yield exec.exec(`rpmbuild -ba /github/home/rpmbuild/SPECS/${specFile}`);
|
yield exec.exec(`rpmbuild -ba /github/home/rpmbuild/SPECS/${specFile}`);
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
core.setFailed(`action failed with error: ${err}`);
|
core.setFailed(`action failed with error: ${err}`);
|
||||||
}
|
}
|
||||||
// Verify RPM created
|
// Verify RPM is created
|
||||||
yield exec.exec('ls /github/home/rpmbuild/RPMS');
|
yield exec.exec('ls /github/home/rpmbuild/RPMS');
|
||||||
// setOutput rpm_path to /root/rpmbuild/RPMS , to be consumed by other actions like
|
// setOutput rpm_path to /root/rpmbuild/RPMS , to be consumed by other actions like
|
||||||
// actions/upload-release-asset
|
// actions/upload-release-asset
|
||||||
|
// Get source rpm name , to provide file name, path as output
|
||||||
let myOutput = '';
|
let myOutput = '';
|
||||||
yield cp.exec('ls /github/home/rpmbuild/SRPMS/', (err, stdout, stderr) => {
|
yield cp.exec('ls /github/home/rpmbuild/SRPMS/', (err, stdout, stderr) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
@ -81,14 +83,14 @@ function run() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
// only contents of workspace can be changed by actions and used by subsequent actions
|
// only contents of workspace can be changed by actions and used by subsequent actions
|
||||||
// So copy all generated rpms into workspace , and publish output path relative to workspace
|
// So copy all generated rpms into workspace , and publish output path relative to workspace (/github/workspace)
|
||||||
yield exec.exec(`mkdir -p rpmbuild/SRPMS`);
|
yield exec.exec(`mkdir -p rpmbuild/SRPMS`);
|
||||||
yield exec.exec(`mkdir -p rpmbuild/RPMS`);
|
yield exec.exec(`mkdir -p rpmbuild/RPMS`);
|
||||||
yield exec.exec(`cp /github/home/rpmbuild/SRPMS/${myOutput} rpmbuild/SRPMS`);
|
yield exec.exec(`cp /github/home/rpmbuild/SRPMS/${myOutput} rpmbuild/SRPMS`);
|
||||||
yield cp.exec(`cp -R /github/home/rpmbuild/RPMS/. rpmbuild/RPMS/`);
|
yield cp.exec(`cp -R /github/home/rpmbuild/RPMS/. rpmbuild/RPMS/`);
|
||||||
yield exec.exec(`ls -la rpmbuild/SRPMS`);
|
yield exec.exec(`ls -la rpmbuild/SRPMS`);
|
||||||
yield exec.exec(`ls -la rpmbuild/RPMS`);
|
yield exec.exec(`ls -la rpmbuild/RPMS`);
|
||||||
// set output to path relative to workspace ex ./rpm/
|
// set outputs to path relative to workspace ex ./rpmbuild/
|
||||||
core.setOutput("source_rpm_dir_path", `rpmbuild/SRPMS/`); // path to SRPMS directory
|
core.setOutput("source_rpm_dir_path", `rpmbuild/SRPMS/`); // path to SRPMS directory
|
||||||
core.setOutput("source_rpm_path", `rpmbuild/SRPMS/${myOutput}`); // path to Source RPM file
|
core.setOutput("source_rpm_path", `rpmbuild/SRPMS/${myOutput}`); // path to Source RPM file
|
||||||
core.setOutput("source_rpm_name", `${myOutput}`); // name of Source RPM file
|
core.setOutput("source_rpm_name", `${myOutput}`); // name of Source RPM file
|
||||||
|
@ -1,43 +0,0 @@
|
|||||||
const { Octokit } = require('@octokit/rest');
|
|
||||||
//const fs = require('fs');
|
|
||||||
const tc = require('@actions/tool-cache');
|
|
||||||
|
|
||||||
|
|
||||||
async function download_archive(owner, repo, ref ) {
|
|
||||||
try {
|
|
||||||
|
|
||||||
const octokit = new Octokit();
|
|
||||||
|
|
||||||
const archive_format = "tarball";
|
|
||||||
|
|
||||||
const tag = "v1.0.0"
|
|
||||||
|
|
||||||
const tarFile = `${repo}-1.0.tar.gz`;
|
|
||||||
|
|
||||||
console.log("Calling API ...");
|
|
||||||
await octokit.repos.getArchiveLink({
|
|
||||||
owner,
|
|
||||||
repo,
|
|
||||||
archive_format,
|
|
||||||
ref
|
|
||||||
}).then(( { data }) => {
|
|
||||||
fs.writeFile(tarFile, Buffer.from(data), function(err){
|
|
||||||
if(err) {
|
|
||||||
return console.log(err);
|
|
||||||
}
|
|
||||||
console.log("The Tar file was saved!");
|
|
||||||
console.log(`Tarball Location : ${tarFile}`);
|
|
||||||
return tarFile;
|
|
||||||
});
|
|
||||||
}).catch( function(error){
|
|
||||||
console.log(error);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
core.setFailed(error.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = download_archive;
|
|
25
src/main.ts
25
src/main.ts
@ -11,6 +11,7 @@ async function run() {
|
|||||||
// Get github context data
|
// Get github context data
|
||||||
const context = github.context;
|
const context = github.context;
|
||||||
|
|
||||||
|
// To be used to get contents of this git ref
|
||||||
const owner = context.repo.owner
|
const owner = context.repo.owner
|
||||||
const repo = context.repo.repo
|
const repo = context.repo.repo
|
||||||
const ref = context.ref
|
const ref = context.ref
|
||||||
@ -42,24 +43,25 @@ async function run() {
|
|||||||
// Copy spec file from path specFile to /root/rpmbuild/SPECS/
|
// Copy spec file from path specFile to /root/rpmbuild/SPECS/
|
||||||
await exec.exec(`cp /github/workspace/${specFile} /github/home/rpmbuild/SPECS/`);
|
await exec.exec(`cp /github/workspace/${specFile} /github/home/rpmbuild/SPECS/`);
|
||||||
|
|
||||||
// Dowload tar.gz file of source code
|
// Dowload tar.gz file of source code, Reference : https://developer.github.com/v3/repos/contents/#get-archive-link
|
||||||
await exec.exec(`curl -L --output tmp.tar.gz https://api.github.com/repos/${owner}/${repo}/tarball/${ref}`)
|
await exec.exec(`curl -L --output tmp.tar.gz https://api.github.com/repos/${owner}/${repo}/tarball/${ref}`)
|
||||||
|
|
||||||
// create directory to match source file - name-version
|
// create directory to match source file - %{name}-{version}.tar.gz of spec file
|
||||||
await exec.exec(`mkdir ${name}-${version}`);
|
await exec.exec(`mkdir ${name}-${version}`);
|
||||||
|
|
||||||
// Extract source code to directory
|
// Extract source code
|
||||||
await exec.exec(`tar xvf tmp.tar.gz -C ${name}-${version} --strip-components 1`);
|
await exec.exec(`tar xvf tmp.tar.gz -C ${name}-${version} --strip-components 1`);
|
||||||
|
|
||||||
// Create Source tar.gz file
|
// Create Source tar.gz file
|
||||||
await exec.exec(`tar -czvf ${name}-${version}.tar.gz ${name}-${version}`);
|
await exec.exec(`tar -czvf ${name}-${version}.tar.gz ${name}-${version}`);
|
||||||
|
|
||||||
// Get repo files from /github/workspace/
|
// // list files in current directory /github/workspace/
|
||||||
await exec.exec('ls -la ');
|
// await exec.exec('ls -la ');
|
||||||
// Copy tar.gz file to source
|
|
||||||
|
// Copy tar.gz file to source path
|
||||||
await exec.exec(`cp ${name}-${version}.tar.gz /github/home/rpmbuild/SOURCES/`);
|
await exec.exec(`cp ${name}-${version}.tar.gz /github/home/rpmbuild/SOURCES/`);
|
||||||
|
|
||||||
// Execute rpmbuild
|
// Execute rpmbuild , -ba generates both RPMS and SPRMS
|
||||||
try {
|
try {
|
||||||
await exec.exec(
|
await exec.exec(
|
||||||
`rpmbuild -ba /github/home/rpmbuild/SPECS/${specFile}`
|
`rpmbuild -ba /github/home/rpmbuild/SPECS/${specFile}`
|
||||||
@ -68,12 +70,13 @@ async function run() {
|
|||||||
core.setFailed(`action failed with error: ${err}`);
|
core.setFailed(`action failed with error: ${err}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify RPM created
|
// Verify RPM is created
|
||||||
await exec.exec('ls /github/home/rpmbuild/RPMS');
|
await exec.exec('ls /github/home/rpmbuild/RPMS');
|
||||||
|
|
||||||
// setOutput rpm_path to /root/rpmbuild/RPMS , to be consumed by other actions like
|
// setOutput rpm_path to /root/rpmbuild/RPMS , to be consumed by other actions like
|
||||||
// actions/upload-release-asset
|
// actions/upload-release-asset
|
||||||
|
|
||||||
|
// Get source rpm name , to provide file name, path as output
|
||||||
let myOutput = '';
|
let myOutput = '';
|
||||||
await cp.exec('ls /github/home/rpmbuild/SRPMS/', (err, stdout, stderr) => {
|
await cp.exec('ls /github/home/rpmbuild/SRPMS/', (err, stdout, stderr) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
@ -89,7 +92,7 @@ async function run() {
|
|||||||
|
|
||||||
|
|
||||||
// only contents of workspace can be changed by actions and used by subsequent actions
|
// only contents of workspace can be changed by actions and used by subsequent actions
|
||||||
// So copy all generated rpms into workspace , and publish output path relative to workspace
|
// So copy all generated rpms into workspace , and publish output path relative to workspace (/github/workspace)
|
||||||
await exec.exec(`mkdir -p rpmbuild/SRPMS`);
|
await exec.exec(`mkdir -p rpmbuild/SRPMS`);
|
||||||
await exec.exec(`mkdir -p rpmbuild/RPMS`);
|
await exec.exec(`mkdir -p rpmbuild/RPMS`);
|
||||||
|
|
||||||
@ -99,13 +102,11 @@ async function run() {
|
|||||||
await exec.exec(`ls -la rpmbuild/SRPMS`);
|
await exec.exec(`ls -la rpmbuild/SRPMS`);
|
||||||
await exec.exec(`ls -la rpmbuild/RPMS`);
|
await exec.exec(`ls -la rpmbuild/RPMS`);
|
||||||
|
|
||||||
// set output to path relative to workspace ex ./rpm/
|
// set outputs to path relative to workspace ex ./rpmbuild/
|
||||||
core.setOutput("source_rpm_dir_path", `rpmbuild/SRPMS/`); // path to SRPMS directory
|
core.setOutput("source_rpm_dir_path", `rpmbuild/SRPMS/`); // path to SRPMS directory
|
||||||
core.setOutput("source_rpm_path", `rpmbuild/SRPMS/${myOutput}`); // path to Source RPM file
|
core.setOutput("source_rpm_path", `rpmbuild/SRPMS/${myOutput}`); // path to Source RPM file
|
||||||
core.setOutput("source_rpm_name", `${myOutput}`); // name of Source RPM file
|
core.setOutput("source_rpm_name", `${myOutput}`); // name of Source RPM file
|
||||||
|
|
||||||
core.setOutput("rpm_dir_path", `rpmbuild/RPMS/`); // path to RPMS directory
|
core.setOutput("rpm_dir_path", `rpmbuild/RPMS/`); // path to RPMS directory
|
||||||
|
|
||||||
core.setOutput("rpm_content_type", "application/octet-stream"); // Content-type for Upload
|
core.setOutput("rpm_content_type", "application/octet-stream"); // Content-type for Upload
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user