From bb22848287f002f423bfcc108bec19887a062822 Mon Sep 17 00:00:00 2001 From: Belden Lyman Date: Fri, 17 Sep 2021 16:48:09 -0700 Subject: [PATCH 1/2] 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. --- lib/download-release-archive.js | 45 --------------------------------- 1 file changed, 45 deletions(-) delete mode 100644 lib/download-release-archive.js diff --git a/lib/download-release-archive.js b/lib/download-release-archive.js deleted file mode 100644 index 348a884..0000000 --- a/lib/download-release-archive.js +++ /dev/null @@ -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; From d99805552cbab481198349d7697cfb63081da263 Mon Sep 17 00:00:00 2001 From: Belden Lyman Date: Fri, 17 Sep 2021 16:44:17 -0700 Subject: [PATCH 2/2] 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. --- .gitignore | 6 +++- Dockerfile | 5 +-- lib/main.js | 98 ---------------------------------------------------- package.json | 8 ++--- 4 files changed, 12 insertions(+), 105 deletions(-) delete mode 100644 lib/main.js diff --git a/.gitignore b/.gitignore index aed448f..f83d13b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,8 @@ node_modules # System Files .DS_Store -Thumbs.db \ No newline at end of file +Thumbs.db + +# typescript gets compiled to js and placed under lib/ +# if you build locally, don't let you commit it +lib/ diff --git a/Dockerfile b/Dockerfile index 3a77ace..04e36e2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,8 +15,9 @@ 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 diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index e302b3e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,98 +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/`); - // 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'; - yield exec.exec(`git archive --output=/github/home/rpmbuild/SOURCES/${name}-${version}.tar.gz --prefix=${name}-${version}/ HEAD`); - process.env.GIT_DIR = oldGitDir; - // 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(); diff --git a/package.json b/package.json index 618d13a..7e9075c 100644 --- a/package.json +++ b/package.json @@ -30,15 +30,15 @@ "@actions/github": "^1.0.0", "@actions/io": "^1.0.0", "@actions/tool-cache": "^1.3.3", - "@octokit/rest": "^17.1.4" + "@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" } }