25 Commits

Author SHA1 Message Date
3a7282e96d Merge pull request #23 from grindsa/alma9
use almalinux as base image
2025-01-30 14:14:46 +05:30
181689c268 use almalinux as base image 2023-12-16 08:05:29 +01:00
11f14d6914 Use spaces instead of tabs 2022-11-11 07:36:17 +05:30
339d22eb73 Fix yaml example 2022-11-11 07:35:27 +05:30
98e9d1fea5 Update README.md 2022-11-11 07:31:33 +05:30
17f89933c0 Merge pull request #18 from StCyr/fix_17
Supports new user input: 'additional_repos'
2022-11-10 18:59:17 -07:00
4a85a923b9 Fixes yum-builddep blocks action
Signed-off-by: Cyrille Bollu <cyrille@debian-BULLSEYE-live-builder-AMD64>
2022-11-10 11:42:22 +01:00
95f2400e99 Supports new user input: 'additional_repos'
Allows the user to specify additional repositories to enable before building the rpm

Signed-off-by: Cyrille Bollu <cyrille@debian-BULLSEYE-live-builder-AMD64>
2022-11-10 11:22:28 +01:00
5da3d22130 Merge pull request #16 from StCyr/fix_15
update the gihub action dependencies
2022-11-09 14:52:27 -07:00
4c9aba2975 Adds an action to install build dependencies before running rpmbuild
Signed-off-by: Cyrille Bollu <cyrille@debian-BULLSEYE-live-builder-AMD64>
2022-11-09 15:53:56 +01:00
267f1778ec Try and fix:
name: roadmap
version: 3.0.2
/usr/bin/rpmdev-setuptree
/usr/bin/cp /github/workspace/roadmap.spec /github/home/rpmbuild/SPECS/roadmap.spec
/usr/bin/git archive --output=/github/home/rpmbuild/SOURCES/roadmap-3.0.2.tar.gz --prefix=roadmap-3.0.2/ HEAD
/usr/bin/rpmbuild -ba /github/home/rpmbuild/SPECS/roadmap.spec
error: File /github/home/rpmbuild/SOURCES/roadmap.tar.gz: No such file or directory
Error: action failed with error: Error: The process '/usr/bin/rpmbuild' failed with exit code 1

Signed-off-by: Cyrille Bollu <cyrille@debian-BULLSEYE-live-builder-AMD64>
2022-11-09 15:39:32 +01:00
839c44710f update the gihub action dependencies
Signed-off-by: Cyrille Bollu <cyrille@debian-BULLSEYE-live-builder-AMD64>
2022-11-09 15:27:32 +01:00
c0ba5e8840 Merge pull request #8 from belden/issue-7-specfile-below-root
Correctly operate on specfiles located below root
2021-11-09 14:12:44 +05:30
2857cd9b80 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.
2021-09-25 14:52:47 -07:00
626822dc92 Fix comment
Drive-by:
  * Ignore vim swapfiles
2021-09-25 14:52:31 -07:00
21d76af2f5 Merge pull request #11 from belden/issue-2-compile-tsc-in-container
Build lib/main.js in the container
2021-09-25 23:09:42 +05:30
d99805552c Build lib/main.js in the container
Resolves https://github.com/naveenrajm7/rpmbuild/issues/2

We don't need `lib/main.js` any more, so I've removed it.

Some previou devDependencies from `package.json` are now
production dependencies.
2021-09-24 10:36:12 -07:00
bb22848287 Remove lib/download-release-archive.js
* Introduced in 281f2b8
* Replaced with `curl` in ab399dd
* Typescript removed in 2c036ef
* Import removed in 2ff761f
* Compiled js finally removed in whatever sha this is

Tracking down the history of this file was kind of fun because I could
see how @naveenrajm7's thinking evolved for getting the repo source
into the rpmbuild SOURCES directory.
2021-09-24 10:35:59 -07:00
82db9b57d1 Merge pull request #10 from belden/issue-9-private-repo
Make rpmbuild work work with private repos
2021-09-24 19:40:40 +05:30
7b5a254a87 Make rpmbuild work with private repos
Previously, in order to create /github/home/rpmbuild/SOURCES/foo-1.2.0.tar.gz,
rpmbuild did the following:

1. use curl to download a tarball of the project source
2. unpack it into a local directory
3. repack it with the correct desired directory structure
4. move the repacked tarball to /github/home/rpmbuild/SOURCES

This failed for me at step 1 because the repo I'm trying to use rpmbuild on
is a private repo. There's no means of plumbing a github auth token into the
`curl` command, so the tarball fails to download and everything else fails.

----

Since we have the current repo tree in /github/workspace, we can coerce `git`
to make the archive for us. Now, we:

1. ask git to make the archive

and everything works with a private repo. In order to make this approach work,
I've added `git` into the build container.
2021-09-17 16:37:25 -07:00
7933177d50 Merge branch 'master' of https://github.com/naveenrajm7/rpmbuild 2020-05-18 02:20:21 +05:30
4f9fc13352 update images link in README 2020-05-18 02:17:11 +05:30
76e457ad9f update winning status , open to contribution. 2020-05-18 02:13:56 +05:30
1ab6e71885 added Contributing guide 2020-05-18 01:48:48 +05:30
b7aecab58c added MacOS system file to gitignore 2020-05-18 00:42:08 +05:30
9 changed files with 132 additions and 197 deletions

16
.gitignore vendored
View File

@ -1,2 +1,16 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.
# editor
*.swp
# dependencies
package-lock.json
node_modules
node_modules
# System Files
.DS_Store
Thumbs.db
# typescript gets compiled to js and placed under lib/
# if you build locally, don't let you commit it
lib/

60
CONTRIBUTING.md Normal file
View File

@ -0,0 +1,60 @@
# Contributing to RPM Build GitHub Action
:+1::tada: First off, thanks for taking the time to contribute! :tada::+1:
The following is a set of guidelines for contributing to rpm-build GitHub Action, which is listed in the [GitHub Marketplace](https://github.com/marketplace/actions/rpm-build) . These are mostly guidelines, not rules. Use your best judgment, and feel free to propose changes to this document in a pull request.
#### Table Of Contents
[What should I know before I get started?](#what-should-i-know-before-i-get-started)
* [rpmbuild](#rpmbuild)
* [GitHub Actions](#github-actions)
[How Can I Contribute?](#how-can-i-contribute)
* [Reporting Bugs](#reporting-bugs)
* [Suggesting Enhancements](#suggesting-enhancements)
* [Pull Requests](#pull-requests)
[Resources](#resources)
## What should I know before I get started?
### rpmbuild
rpmbuild is a command line utility to build RPM packages.
* [RPM Packaging Guide](https://rpm-packaging-guide.github.io/)
### GitHub Actions
GitHub Action is github's CICD platform , to automate your software lifecyle
* [GitHub Actions Documentation](https://help.github.com/en/actions)
## How Can I Contribute?
### Reporting Bugs
Report bugs using Github's issues
We use GitHub issues to track public bugs. Report a bug by opening a new issue; it's that easy!
### Suggesting Enhancements
If you think you have an idea which will make this project more useful to the community, add your suggestion as an issue.
### Submitting a pull request
1. Fork and clone the repository
2. Configure and install the dependencies: ```npm install```
3. Make sure the tests pass on your machine: ```npm run test```
4. Create a new branch: ```git checkout -b my-branch-name```
5. Make your change, add tests, and make sure the tests still pass
6. Push to your fork and submit a pull request
7. Pat your self on the back and wait for your pull request to be reviewed and merged.
## Resources
* [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/)
* [Using Pull Requests](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests)

View File

@ -1,24 +1,18 @@
# Using CentOS 7 as base image to support rpmbuild (packages will be Dist el7)
FROM centos:7
# Using almalinux:latest as base image for this container
FROM almalinux:latest
# Copying all contents of rpmbuild repo inside container
COPY . .
# Installing tools needed for rpmbuild ,
# 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 python git nodejs yum-utils
# Setting up node to run our JS file
# Download Node Linux binary
RUN curl -O https://nodejs.org/dist/v12.16.1/node-v12.16.1-linux-x64.tar.xz
# Install dependecies and build main.js
RUN npm install --production \
&& npm run-script build
# Extract and install
RUN tar --strip-components 1 -xvf node-v* -C /usr/local
# Install all dependecies to execute main.js
RUN npm install --production
# All remaining logic goes inside main.js ,
# where we have access to both tools of this container and
# All remaining logic goes inside main.js ,
# where we have access to both tools of this container and
# contents of git repo at /github/workspace
ENTRYPOINT ["node", "/lib/main.js"]

View File

@ -14,6 +14,7 @@ Create a workflow `.yml` file in your repositories `.github/workflows` directory
### Inputs
- `spec_file`: The path to the spec file in your repo. [**required**]
- `additional_repos`: A list of additional repositories (in JSON-array format) that you want enabled to build your rpm. [**optional**]
### Outputs
@ -47,6 +48,7 @@ jobs:
uses: naveenrajm7/rpmbuild@master
with:
spec_file: "cello.spec"
additional_repos: "['centos-release-scl', 'http://www.percona.com/downloads/percona-release/redhat/0.1-3/percona-release-0.1-3.noarch.rpm']"
- name: Upload artifact
uses: actions/upload-artifact@v1.0.0
@ -61,7 +63,6 @@ The generated RPMs or SRPMS can be uploaded as artifacts by using actions/upload
![artifact_image](assets/upload_artifacts.png)
Use with Release:
```yaml
on:
@ -134,6 +135,10 @@ If your RPMs are distribution specific like el7 or el8.
spec_file: "cello.spec"
```
## Contribute
Feel free to contribute to this project. Read [CONTRIBUTING Guide](CONTRIBUTING.md) for more details.
## References
* [RPM Packaging Guide](https://rpm-packaging-guide.github.io/)
@ -144,4 +149,5 @@ If your RPMs are distribution specific like el7 or el8.
The scripts and documentation in this project are released under the [GNU GPLv3](LICENSE)
*Created during the GitHub Actions Hackathon 2020 :octocat: :computer: .*
*Created during the GitHub Actions Hackathon 2020 :octocat: :computer: .*
*Made it to the [winner's list](https://docs.google.com/spreadsheets/d/1YL6mjJXGt3-75GejQCubsOvWwtYcGaqbJA7msnsh7Tg/edit?usp=sharing) (See Row no. 291!) :trophy: :medal_sports:*

View File

@ -7,6 +7,9 @@ inputs:
description: 'path to the spec file'
required: true
default: '*.spec' #Any spec file in top
additional_repos:
description: 'A list of additional repositories to enable'
required: false
outputs:
source_rpm_path:

View File

@ -1,45 +0,0 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
const { Octokit } = require('@octokit/rest');
//const fs = require('fs');
const tc = require('@actions/tool-cache');
function download_archive(owner, repo, ref) {
return __awaiter(this, void 0, void 0, function* () {
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 ...");
yield 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;

View File

@ -1,105 +0,0 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
const core = require('@actions/core');
const github = require('@actions/github');
const exec = require('@actions/exec');
const io = require('@actions/io');
const cp = require('child_process');
const fs = require('fs');
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
// Get github context data
const context = github.context;
// To be used to get contents of this git ref
const owner = context.repo.owner;
const repo = context.repo.repo;
const ref = context.ref;
// get inputs from workflow
// specFile name
const specFile = core.getInput('spec_file');
// Read spec file and get values
var data = fs.readFileSync(specFile, '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, 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}`);
// create directory to match source file - %{name}-{version}.tar.gz of spec file
yield exec.exec(`mkdir ${name}-${version}`);
// Extract source code
yield exec.exec(`tar xvf tmp.tar.gz -C ${name}-${version} --strip-components 1`);
// Create Source tar.gz file
yield exec.exec(`tar -czvf ${name}-${version}.tar.gz ${name}-${version}`);
// // list files in current directory /github/workspace/
// await exec.exec('ls -la ');
// Copy tar.gz file to source path
yield exec.exec(`cp ${name}-${version}.tar.gz /github/home/rpmbuild/SOURCES/`);
// Execute rpmbuild , -ba generates both RPMS and SPRMS
try {
yield exec.exec(`rpmbuild -ba /github/home/rpmbuild/SPECS/${specFile}`);
}
catch (err) {
core.setFailed(`action failed with error: ${err}`);
}
// Verify RPM is created
yield exec.exec('ls /github/home/rpmbuild/RPMS');
// setOutput rpm_path to /root/rpmbuild/RPMS , to be consumed by other actions like
// actions/upload-release-asset
// Get source rpm name , to provide file name, path as output
let myOutput = '';
yield cp.exec('ls /github/home/rpmbuild/SRPMS/', (err, stdout, stderr) => {
if (err) {
//some err occurred
console.error(err);
}
else {
// the *entire* stdout and stderr (buffered)
console.log(`stdout: ${stdout}`);
myOutput = myOutput + `${stdout}`.trim();
console.log(`stderr: ${stderr}`);
}
});
// 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 (/github/workspace)
yield exec.exec(`mkdir -p rpmbuild/SRPMS`);
yield exec.exec(`mkdir -p rpmbuild/RPMS`);
yield exec.exec(`cp /github/home/rpmbuild/SRPMS/${myOutput} rpmbuild/SRPMS`);
yield cp.exec(`cp -R /github/home/rpmbuild/RPMS/. rpmbuild/RPMS/`);
yield exec.exec(`ls -la rpmbuild/SRPMS`);
yield exec.exec(`ls -la rpmbuild/RPMS`);
// 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_path", `rpmbuild/SRPMS/${myOutput}`); // path to 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_content_type", "application/octet-stream"); // Content-type for Upload
}
catch (error) {
core.setFailed(error.message);
}
});
}
run();

View File

@ -25,20 +25,20 @@
},
"homepage": "https://github.com/actions/container-toolkit-template#readme",
"dependencies": {
"@actions/core": "^1.0.0",
"@actions/exec": "^1.0.0",
"@actions/github": "^1.0.0",
"@actions/io": "^1.0.0",
"@actions/tool-cache": "^1.3.3",
"@octokit/rest": "^17.1.4"
"@actions/core": "^1.10.0",
"@actions/exec": "^1.1.1",
"@actions/github": "^5.1.1",
"@actions/io": "^1.1.2",
"@actions/tool-cache": "^2.0.1",
"@octokit/rest": "^17.1.4",
"@types/node": "^12.0.4",
"typescript": "^3.5.1"
},
"devDependencies": {
"@types/jest": "^24.0.13",
"@types/node": "^12.0.4",
"jest": "^24.8.0",
"jest-circus": "^24.7.1",
"prettier": "^1.17.1",
"ts-jest": "^24.0.2",
"typescript": "^3.5.1"
"ts-jest": "^24.0.2"
}
}

View File

@ -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,31 +46,33 @@ 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}`);
// 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}`)
// Make the code in /github/workspace/ into a tar.gz, located in /github/home/rpmbuild/SOURCES/
const oldGitDir = process.env.GIT_DIR;
process.env.GIT_DIR = '/github/workspace/.git';
await exec.exec(`git archive --output=/github/home/rpmbuild/SOURCES/${name}-${version}.tar.gz --prefix=${name}-${version}/ HEAD`);
await exec.exec(`ln -s /github/home/rpmbuild/SOURCES/${name}-${version}.tar.gz /github/home/rpmbuild/SOURCES/${name}.tar.gz`);
process.env.GIT_DIR = oldGitDir;
// create directory to match source file - %{name}-{version}.tar.gz of spec file
await exec.exec(`mkdir ${name}-${version}`);
// Installs additional repositories
const additionalRepos = core.getInput('additional_repos'); // user input, eg: '["centos-release-scl"]'
if (additionalRepos) {
const arr = JSON.parse(additionalRepos);
for (let i = 0; i < arr.length; i++) {
console.log(`Installing repo': ${arr[i]}`);
await exec.exec(`yum install -y ${arr[i]}`);
};
}
// Extract source code
await exec.exec(`tar xvf tmp.tar.gz -C ${name}-${version} --strip-components 1`);
// Create Source tar.gz file
await exec.exec(`tar -czvf ${name}-${version}.tar.gz ${name}-${version}`);
// // list files in current directory /github/workspace/
// await exec.exec('ls -la ');
// Copy tar.gz file to source path
await exec.exec(`cp ${name}-${version}.tar.gz /github/home/rpmbuild/SOURCES/`);
// Installs build dependencies
await exec.exec(`yum-builddep -y ${specFile.destFullPath}`);
// 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}`);