mirror of
https://github.com/naveenrajm7/rpmbuild.git
synced 2025-07-12 04:13:50 +00:00
Compare commits
35 Commits
Author | SHA1 | Date | |
---|---|---|---|
3a7282e96d | |||
181689c268 | |||
11f14d6914 | |||
339d22eb73 | |||
98e9d1fea5 | |||
17f89933c0 | |||
4a85a923b9 | |||
95f2400e99 | |||
5da3d22130 | |||
4c9aba2975 | |||
267f1778ec | |||
839c44710f | |||
c0ba5e8840 | |||
2857cd9b80 | |||
626822dc92 | |||
21d76af2f5 | |||
d99805552c | |||
bb22848287 | |||
82db9b57d1 | |||
7b5a254a87 | |||
7933177d50 | |||
4f9fc13352 | |||
76e457ad9f | |||
1ab6e71885 | |||
b7aecab58c | |||
b52f0e593e | |||
44f3322e47 | |||
b393c528e2 | |||
ca2383e80a | |||
0241680a99 | |||
b980813ffe | |||
2c036efa4b | |||
9ee1f018db | |||
13cf204bc3 | |||
0354642598 |
14
.gitignore
vendored
14
.gitignore
vendored
@ -1,2 +1,16 @@
|
||||
# See http://help.github.com/ignore-files/ for more about ignoring files.
|
||||
|
||||
# editor
|
||||
*.swp
|
||||
|
||||
# dependencies
|
||||
package-lock.json
|
||||
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
60
CONTRIBUTING.md
Normal 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)
|
21
Dockerfile
21
Dockerfile
@ -1,21 +1,16 @@
|
||||
# Using CentOS 7 with Node 12 as base image to support rpmbuild
|
||||
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 , depends on specfile
|
||||
RUN yum install -y rpm-build rpmdevtools gcc make coreutils
|
||||
# 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 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
|
||||
|
||||
# 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
|
||||
# Install dependecies and build main.js
|
||||
RUN npm install --production \
|
||||
&& npm run-script build
|
||||
|
||||
# All remaining logic goes inside main.js ,
|
||||
# where we have access to both tools of this container and
|
||||
|
111
README.md
111
README.md
@ -8,15 +8,13 @@ Integrates easily with GitHub actions to allow RPMS to be uploaded as Artifact (
|
||||
### Pre-requisites
|
||||
Create a workflow `.yml` file in your repositories `.github/workflows` directory. An [example workflow](#example-workflow---build-rpm) is available below. For more information, reference the GitHub Help Documentation for [Creating a workflow file](https://help.github.com/en/articles/configuring-a-workflow#creating-a-workflow-file).
|
||||
|
||||
This generated RPMS and SRPMS can be used in two ways.
|
||||
1. Upload as build artifact
|
||||
You can use GitHub Action [`@actions/upload-artifact`](https://www.github.com/actions/upload-artifact)
|
||||
2. Upload as Release assest
|
||||
If you want to upload as release asset ,You also will need to have a release to upload your asset to, which could be created programmatically by [`@actions/create-release`](https://www.github.com/actions/create-release) as show in the example workflow.
|
||||
**Note:** You need to have a spec file in order to build RPM.
|
||||
|
||||
|
||||
### Inputs
|
||||
|
||||
- `spec_file`: The path to the spec file in your repo. `**require**`
|
||||
- `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
|
||||
|
||||
@ -26,6 +24,11 @@ This generated RPMS and SRPMS can be used in two ways.
|
||||
- `source_rpm_name`: name of Source RPM file
|
||||
- `rpm_content_type`: Content-type for RPM Upload
|
||||
|
||||
This generated RPMS and SRPMS can be used in two ways.
|
||||
1. Upload as build artifact
|
||||
You can use GitHub Action [`@actions/upload-artifact`](https://www.github.com/actions/upload-artifact)
|
||||
2. Upload as Release assest
|
||||
If you want to upload as release asset ,You also will need to have a release to upload your asset to, which could be created programmatically by [`@actions/create-release`](https://www.github.com/actions/create-release) as show in the example workflow.
|
||||
|
||||
### Example workflow - build RPM
|
||||
|
||||
@ -45,14 +48,106 @@ 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
|
||||
with:
|
||||
name: Source RPM
|
||||
path: ${{ steps.rpm.outputs.source_rpm_path }}
|
||||
name: Binary RPM
|
||||
path: ${{ steps.rpm.outputs.rpm_dir_path }}
|
||||
```
|
||||
This workflow triggered on every `push` , builds RPM and Source RPM using cello.spec and contents of that git ref that triggered that action. Contents are retrived through [GitHub API](https://developer.github.com/v3/repos/contents/#get-archive-link) [downloaded through archive link].
|
||||
The generated RPMs or SRPMS can be uploaded as artifacts by using actions/upload-artifact. The [outputs](#outputs) given by rpmbuild action can be used to specify path for upload action.
|
||||
|
||||
#### Above workflow will create an artifact like :
|
||||
|
||||

|
||||
|
||||
Use with Release:
|
||||
```yaml
|
||||
on:
|
||||
push:
|
||||
# Sequence of patterns matched against refs/tags
|
||||
tags:
|
||||
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
|
||||
|
||||
name: Create RPM Release
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Create RPM Release
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@master
|
||||
|
||||
- name: Create Release
|
||||
id: create_release
|
||||
uses: actions/create-release@latest
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
|
||||
with:
|
||||
tag_name: ${{ github.ref }}
|
||||
release_name: Release ${{ github.ref }}
|
||||
body: |
|
||||
Changes in this Release
|
||||
- Create RPM
|
||||
- Upload Source RPM
|
||||
draft: false
|
||||
prerelease: false
|
||||
|
||||
- name: build RPM package
|
||||
id: rpm_build
|
||||
uses: naveenrajm7/rpmbuild@master
|
||||
with:
|
||||
spec_file: "cello.spec"
|
||||
|
||||
- name: Upload Release Asset
|
||||
id: upload-release-asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
|
||||
asset_path: ${{ steps.rpm_build.outputs.source_rpm_path }}
|
||||
asset_name: ${{ steps.rpm_build.outputs.source_rpm_name }}
|
||||
asset_content_type: ${{ steps.rpm_build.outputs.rpm_content_type }}
|
||||
```
|
||||
|
||||
#### The above release uploads SRPM like :
|
||||
|
||||

|
||||
|
||||
Example Repository which uses rpmbuild action https://github.com/naveenrajm7/cello
|
||||
|
||||
Note on distribution:
|
||||
If your RPMs are distribution specific like el7 or el8.
|
||||
- Use naveenrajm7/rpmbuild@master for Centos7 *[el7]*
|
||||
- Use naveenrajm7/rpmbuild@centos8 for Centos8 *[el8]*
|
||||
|
||||
```yaml
|
||||
- name: build RPM package
|
||||
id: rpm_build
|
||||
uses: naveenrajm7/rpmbuild@centos8
|
||||
with:
|
||||
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/)
|
||||
* [GitHub Learning Lab](https://lab.github.com/)
|
||||
* [Container Toolkit Action](https://github.com/actions/container-toolkit-action)
|
||||
|
||||
## License
|
||||
|
||||
The scripts and documentation in this project are released under the [GNU GPLv3](LICENSE)
|
||||
|
||||
*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:*
|
||||
|
@ -7,14 +7,19 @@ 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:
|
||||
description: 'path to Source RPM file'
|
||||
source_rpm_dir_path:
|
||||
description: 'path to Source RPM directory'
|
||||
description: 'path to SRPMS directory'
|
||||
source_rpm_name:
|
||||
description: 'name of Source RPM file'
|
||||
rpm_dir_path:
|
||||
description: 'path to RPMS directory'
|
||||
rpm_content_type:
|
||||
description: 'Content-type for Upload'
|
||||
|
||||
|
BIN
assets/upload_artifacts.png
Normal file
BIN
assets/upload_artifacts.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 28 KiB |
BIN
assets/upload_release_asset.png
Normal file
BIN
assets/upload_release_asset.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 123 KiB |
@ -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;
|
103
lib/main.js
103
lib/main.js
@ -1,103 +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;
|
||||
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
|
||||
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
|
||||
yield exec.exec(`mkdir ${name}-${version}`);
|
||||
// Extract source code to directory
|
||||
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}`);
|
||||
// Get repo files from /github/workspace/
|
||||
yield exec.exec('ls -la ');
|
||||
// Copy tar.gz file to source
|
||||
yield exec.exec(`cp ${name}-${version}.tar.gz /github/home/rpmbuild/SOURCES/`);
|
||||
// Execute rpmbuild
|
||||
try {
|
||||
yield exec.exec(`rpmbuild -ba /github/home/rpmbuild/SPECS/${specFile}`);
|
||||
}
|
||||
catch (err) {
|
||||
core.setFailed(`action failed with error: ${err}`);
|
||||
}
|
||||
// Verify RPM 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
|
||||
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
|
||||
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 output to path relative to workspace ex ./rpm/
|
||||
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();
|
18
package.json
18
package.json
@ -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"
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
59
src/main.ts
59
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 {
|
||||
@ -11,16 +12,22 @@ async function run() {
|
||||
// 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');
|
||||
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 = '';
|
||||
|
||||
@ -39,41 +46,45 @@ 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
|
||||
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
|
||||
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 to directory
|
||||
await exec.exec(`tar xvf tmp.tar.gz -C ${name}-${version} --strip-components 1`);
|
||||
// Installs build dependencies
|
||||
await exec.exec(`yum-builddep -y ${specFile.destFullPath}`);
|
||||
|
||||
// Create Source tar.gz file
|
||||
await exec.exec(`tar -czvf ${name}-${version}.tar.gz ${name}-${version}`);
|
||||
|
||||
// Get repo files from /github/workspace/
|
||||
await exec.exec('ls -la ');
|
||||
// Copy tar.gz file to source
|
||||
await exec.exec(`cp ${name}-${version}.tar.gz /github/home/rpmbuild/SOURCES/`);
|
||||
|
||||
// Execute rpmbuild
|
||||
// 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}`);
|
||||
}
|
||||
|
||||
// Verify RPM created
|
||||
// Verify RPM is created
|
||||
await 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 = '';
|
||||
await cp.exec('ls /github/home/rpmbuild/SRPMS/', (err, stdout, stderr) => {
|
||||
if (err) {
|
||||
@ -89,7 +100,7 @@ async function run() {
|
||||
|
||||
|
||||
// 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/RPMS`);
|
||||
|
||||
@ -99,13 +110,11 @@ async function run() {
|
||||
await exec.exec(`ls -la rpmbuild/SRPMS`);
|
||||
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_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
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user