From 1cb7c397d2c7caa8d8071041976b6f2e4e2ead20 Mon Sep 17 00:00:00 2001 From: Sebastian Rath Date: Fri, 24 May 2024 22:00:01 -0400 Subject: [PATCH] Code cleanup and use zip for runner on every platform --- .../workflows/graphs/build-and-publish.yml | 99 ++++++++++++++++--- dist/index.js | 54 +++++++--- package-lock.json | 4 +- package.json | 2 +- src/bundled_package.json | 9 +- src/main.ts | 45 ++++++--- 6 files changed, 162 insertions(+), 51 deletions(-) diff --git a/.github/workflows/graphs/build-and-publish.yml b/.github/workflows/graphs/build-and-publish.yml index 250179b..0e335a8 100644 --- a/.github/workflows/graphs/build-and-publish.yml +++ b/.github/workflows/graphs/build-and-publish.yml @@ -1,5 +1,11 @@ entry: gh-start executions: + - src: + node: github-com-actions-setup-node-cherry-grape-banana + port: exec + dst: + node: run-v1-strawberry-cat-blueberry + port: exec - src: node: gh-start port: exec-on-push @@ -10,35 +16,59 @@ executions: node: github-com-actions-checkout-coconut-coconut-banana port: exec dst: - node: github-com-actions-setup-node-cherry-grape-banana + node: branch-v1-orange-giraffe-lion + port: exec + - src: + node: branch-v1-orange-giraffe-lion + port: exec-then + dst: + node: run-v1-brown-brown-panda port: exec - src: + node: run-v1-brown-brown-panda + port: exec-success + dst: node: github-com-actions-setup-node-cherry-grape-banana port: exec + - src: + node: branch-v1-orange-giraffe-lion + port: exec-otherwise dst: - node: run-v1-strawberry-cat-blueberry + node: github-com-actions-setup-node-cherry-grape-banana port: exec -connections: [] +connections: + - src: + node: env-get-v1-grape-tiger-cherry + port: env + dst: + node: string-match-v1-panda-orange-gold + port: str1 + - src: + node: string-match-v1-panda-orange-gold + port: result + dst: + node: branch-v1-orange-giraffe-lion + port: condition nodes: - id: gh-start type: gh-start@v1 position: - x: 100 - y: 100 + x: -380 + y: 150 settings: folded: false - id: github-com-actions-checkout-coconut-coconut-banana - type: github.com/actions/checkout + type: github.com/actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 position: - x: 670 - y: 230 + x: 130 + y: 50 settings: folded: false - id: github-com-actions-setup-node-cherry-grape-banana - type: github.com/actions/setup-node + type: github.com/actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 position: - x: 1300 - y: 360 + x: 1360 + y: 110 inputs: node-version: v20.10.0 settings: @@ -46,13 +76,56 @@ nodes: - id: run-v1-strawberry-cat-blueberry type: run@v1 position: - x: 1810 - y: 450 + x: 1920 + y: 90 inputs: script: |- npm install npm run lint settings: folded: false + - id: run-v1-brown-brown-panda + type: run@v1 + position: + x: 950 + y: -130 + inputs: + script: |- + # Ensure the version in package.json matches the current git tag + PACKAGE_VERSION=$(jq -r '.version' package.json) + TAG_VERSION=${GITHUB_REF_NAME#v} + + if [ "$PACKAGE_VERSION" != "$TAG_VERSION" ]; then + echo "Version mismatch: package.json version is $PACKAGE_VERSION, but tag is v$TAG_VERSION" + exit 1 + fi + settings: + folded: false + - id: env-get-v1-grape-tiger-cherry + type: env-get@v1 + position: + x: -70 + y: 1090 + inputs: + env: GITHUB_REF + settings: + folded: false + - id: string-match-v1-panda-orange-gold + type: string-match@v1 + position: + x: 270 + y: 930 + inputs: + op: startswith + str2: refs/tags/ + settings: + folded: false + - id: branch-v1-orange-giraffe-lion + type: branch@v1 + position: + x: 680 + y: 220 + settings: + folded: false registries: [] description: '' diff --git a/dist/index.js b/dist/index.js index d641cb5..55cc38f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -36934,12 +36934,15 @@ const util = __importStar(__nccwpck_require__(3837)); const crypto = __importStar(__nccwpck_require__(6113)); const tc = __importStar(__nccwpck_require__(7784)); const pjdata = __importStar(__nccwpck_require__(6055)); +const pjson = __importStar(__nccwpck_require__(4147)); const os_1 = __importDefault(__nccwpck_require__(2037)); const path_1 = __importDefault(__nccwpck_require__(1017)); const fs_1 = __importDefault(__nccwpck_require__(7147)); const got_1 = __importDefault(__nccwpck_require__(2401)); const child_process_1 = __importDefault(__nccwpck_require__(2081)); +const packageJson = pjson; const pj = pjdata; +const debugOutput = process.env.ACTIONS_STEP_DEBUG === 'true'; /** * Extracts the contents of an archive file to a directory. * @param archivePath The path to the archive file. @@ -36947,7 +36950,15 @@ const pj = pjdata; */ function extractArchive(archivePath) { return __awaiter(this, void 0, void 0, function* () { - return archivePath.endsWith(".zip") ? tc.extractZip(archivePath) : tc.extractTar(archivePath); + if (archivePath.endsWith(".tar.gz")) { + return tc.extractTar(archivePath); + } + else if (archivePath.endsWith(".zip")) { + return tc.extractZip(archivePath); + } + else { + throw new Error(`Unsupported archive format: ${archivePath}`); + } }); } exports.extractArchive = extractArchive; @@ -36976,29 +36987,35 @@ exports.calculateFileHash = calculateFileHash; function downloadRunner(info, token, hashCheck) { return __awaiter(this, void 0, void 0, function* () { const tempDir = process.env.RUNNER_TEMP || '.'; - const filename = path_1.default.join(tempDir, info.filename); + const zipPath = path_1.default.join(tempDir, info.filename + '.zip'); + if (debugOutput) { + console.log(`📥 Downloaded zip to ${zipPath} from ${info.downloadUrl} 🚀`); + } const pipeline = util.promisify(stream.pipeline); yield pipeline(got_1.default.stream(info.downloadUrl, { method: "GET", headers: Object.assign({ "Accept": "application/octet-stream", "User-Agent": "GitHub Actions" }, (token ? { "Authorization": `token ${token}` } : {})), - }), fs_1.default.createWriteStream(filename)); - const extPath = yield extractArchive(filename); - let execPath = path_1.default.join(extPath, info.filename); + }), fs_1.default.createWriteStream(zipPath)); + const zipDstPath = yield extractArchive(zipPath); + if (debugOutput) { + console.log(`📦 Extracted runner to ${zipDstPath}`); + } + let binPath = path_1.default.join(zipDstPath, info.filename); if (os_1.default.platform() === "linux" || os_1.default.platform() === "darwin") { - fs_1.default.chmodSync(execPath, 0o755); + fs_1.default.chmodSync(binPath, 0o755); } else { - execPath = execPath + ".exe"; + binPath = binPath + ".exe"; } if (hashCheck) { - const hash = yield calculateFileHash(execPath); + const hash = yield calculateFileHash(binPath); if (hash.length !== 64 || hash !== pj.binaries[`${os_1.default.platform()}-${os_1.default.arch()}`]) { - throw new Error(`Hash mismatch for ${execPath}`); + throw new Error(`Hash mismatch for ${binPath}`); } } - return execPath; + return binPath; }); } /** @@ -37068,15 +37085,14 @@ function run() { console.log("\u27a1 Custom runner path set:", runnerPath); } else { - const baseUrl = `https://github.com/actionforge/${pj.name}/releases/download/v${pj.version}`; - const archiveExt = os_1.default.platform() === "linux" ? "tar.gz" : "zip"; - const downloadUrl = `${runnerBaseUrl.replace(/\/$/, "") || baseUrl}/graph-runner-${os_1.default.platform()}-${os_1.default.arch()}.${archiveExt}`; + const baseUrl = `https://github.com/actionforge/${pj.name}/releases/download/v${packageJson.version}`; + const downloadUrl = `${runnerBaseUrl.replace(/\/$/, "") || baseUrl}/graph-runner-${os_1.default.platform()}-${os_1.default.arch()}.zip`; if (runnerBaseUrl) { console.log("\u27a1 Custom runner URL set:", downloadUrl); } const downloadInfo = { downloadUrl: downloadUrl, - filename: 'graph-runner', + filename: `graph-runner-${os_1.default.platform()}-${os_1.default.arch()}`, }; runnerPath = yield downloadRunner(downloadInfo, runnerBaseUrl ? null : token, runnerBaseUrl ? false : true); } @@ -46390,13 +46406,21 @@ const got = source_create(defaults); +/***/ }), + +/***/ 4147: +/***/ ((module) => { + +"use strict"; +module.exports = JSON.parse('{"name":"action","version":"0.9.58","description":"","main":"dist/index.js","scripts":{"build":"tsc && ncc build src/main.ts -o dist","test":"echo \\"Error: no test specified\\" && exit 1","lint":"eslint src"},"keywords":["github","actions","workflows","node","graph"],"repository":{"type":"git","url":"git+https://github.com/actionforge/action.git"},"author":"Actionforge","license":"Actionforge Community License","bugs":{"url":"https://github.com/actionforge/action/issues"},"homepage":"https://github.com/actionforge/action#readme","dependencies":{"@actions/core":"^1.10.1","@actions/github":"^6.0.0","@actions/tool-cache":"^2.0.1","@octokit/action":"^7.0.0","got":"^14.3.0"},"devDependencies":{"@types/got":"^9.6.12","@types/node":"^20.12.12","@typescript-eslint/eslint-plugin":"^7.10.0","@typescript-eslint/parser":"^7.10.0","@vercel/ncc":"^0.38.1","eslint":"^8.56.0","typescript":"^5.4.5"}}'); + /***/ }), /***/ 6055: /***/ ((module) => { "use strict"; -module.exports = JSON.parse('{"name":"action","version":"0.9.54","binaries":{"linux-x64":"d3e23023f42c093728c50334d0399e5e8924956b547fb6836fa77f757d05c11d","darwin-x64":"1ab7953542edfb38cbeb1cb963f1f5c8dfaccf5eeb4188d42f49c05ca1037e90","darwin-arm64":"cccfd3a010c4382d5f05db7d2ec08e5ed75e6fc7c676af9540e580613291c481","win32-x64":"5cbbab0244ab109b5f443efabf9486accdf6c8e287f11309b014ca9107b289db"}}'); +module.exports = JSON.parse('{"name":"action","binaries":{"linux-x64":"6bf6dc96a334b2f7a975ad6a8f06a67e49401d476088f618b7d9dafb07a390e1","darwin-x64":"e60013321145db2365fe1bddbe6ba7f712de49d8af50936ba4877964617cb8c2","darwin-arm64":"7bcf44be4979c154fd7f06905b6b6fe0e0f39272d1c44d981cbff2a71eedfce1","win32-x64":"87db763ce2252fbb6e63f24ddadc2b4183f0bdfa39adbf1f1686d20b931c5247"}}'); /***/ }) diff --git a/package-lock.json b/package-lock.json index 49d8644..bacc75a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "action", - "version": "0.9.54", + "version": "0.9.58", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "action", - "version": "0.9.54", + "version": "0.9.58", "license": "Actionforge Community License", "dependencies": { "@actions/core": "^1.10.1", diff --git a/package.json b/package.json index 49f3ed3..d951738 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "action", - "version": "0.9.54", + "version": "0.9.58", "description": "", "main": "dist/index.js", "scripts": { diff --git a/src/bundled_package.json b/src/bundled_package.json index c9741fd..4e268e1 100644 --- a/src/bundled_package.json +++ b/src/bundled_package.json @@ -1,10 +1,9 @@ { "name": "action", - "version": "0.9.54", "binaries": { - "linux-x64": "d3e23023f42c093728c50334d0399e5e8924956b547fb6836fa77f757d05c11d", - "darwin-x64": "1ab7953542edfb38cbeb1cb963f1f5c8dfaccf5eeb4188d42f49c05ca1037e90", - "darwin-arm64": "cccfd3a010c4382d5f05db7d2ec08e5ed75e6fc7c676af9540e580613291c481", - "win32-x64": "5cbbab0244ab109b5f443efabf9486accdf6c8e287f11309b014ca9107b289db" + "linux-x64": "6bf6dc96a334b2f7a975ad6a8f06a67e49401d476088f618b7d9dafb07a390e1", + "darwin-x64": "e60013321145db2365fe1bddbe6ba7f712de49d8af50936ba4877964617cb8c2", + "darwin-arm64": "7bcf44be4979c154fd7f06905b6b6fe0e0f39272d1c44d981cbff2a71eedfce1", + "win32-x64": "87db763ce2252fbb6e63f24ddadc2b4183f0bdfa39adbf1f1686d20b931c5247" } } diff --git a/src/main.ts b/src/main.ts index 4efe25a..5694ed9 100644 --- a/src/main.ts +++ b/src/main.ts @@ -5,6 +5,7 @@ import * as util from "util"; import * as crypto from "crypto"; import * as tc from "@actions/tool-cache"; import * as pjdata from './bundled_package.json'; +import * as pjson from './../package.json'; import os from "os"; import path from "path"; @@ -12,14 +13,16 @@ import fs from "fs"; import got from "got"; import cp from "child_process"; +const packageJson: Record = pjson as unknown as Record; const pj: BundledPackage = pjdata as unknown as BundledPackage; type BundledPackage = { name: string; - version: string; binaries: Record; }; +const debugOutput = process.env.ACTIONS_STEP_DEBUG === 'true'; + /** * Represents information about a runner version, * including its download URL, resolved version, and file name. @@ -35,7 +38,13 @@ export interface IRunnerVersionInfo { * @returns A Promise that resolves to the path of the extracted directory. */ export async function extractArchive(archivePath: string): Promise { - return archivePath.endsWith(".zip") ? tc.extractZip(archivePath) : tc.extractTar(archivePath); + if (archivePath.endsWith(".tar.gz")) { + return tc.extractTar(archivePath); + } else if (archivePath.endsWith(".zip")) { + return tc.extractZip(archivePath); + } else { + throw new Error(`Unsupported archive format: ${archivePath}`); + } } /** @@ -61,7 +70,10 @@ export async function calculateFileHash(filePath: string): Promise { */ async function downloadRunner(info: IRunnerVersionInfo, token: string | null, hashCheck: boolean): Promise { const tempDir = process.env.RUNNER_TEMP || '.'; - const filename = path.join(tempDir, info.filename); + const zipPath = path.join(tempDir, info.filename + '.zip'); + if (debugOutput) { + console.log(`📥 Downloaded zip to ${zipPath} from ${info.downloadUrl} 🚀`); + } const pipeline = util.promisify(stream.pipeline); await pipeline( @@ -75,25 +87,29 @@ async function downloadRunner(info: IRunnerVersionInfo, token: string | null, ha ), }, }), - fs.createWriteStream(filename) + fs.createWriteStream(zipPath) ); - const extPath = await extractArchive(filename); - let execPath = path.join(extPath, info.filename); + const zipDstPath = await extractArchive(zipPath); + if (debugOutput) { + console.log(`📦 Extracted runner to ${zipDstPath}`); + } + + let binPath = path.join(zipDstPath, info.filename); if (os.platform() === "linux" || os.platform() === "darwin") { - fs.chmodSync(execPath, 0o755); + fs.chmodSync(binPath, 0o755); } else { - execPath = execPath + ".exe"; + binPath = binPath + ".exe"; } if (hashCheck) { - const hash = await calculateFileHash(execPath); + const hash = await calculateFileHash(binPath); if (hash.length !== 64 || hash !== pj.binaries[`${os.platform()}-${os.arch()}`]) { - throw new Error(`Hash mismatch for ${execPath}`); + throw new Error(`Hash mismatch for ${binPath}`); } } - return execPath; + return binPath; } /** @@ -184,16 +200,15 @@ async function run(): Promise { if (runnerPath) { console.log("\u27a1 Custom runner path set:", runnerPath); } else { - const baseUrl = `https://github.com/actionforge/${pj.name}/releases/download/v${pj.version}`; - const archiveExt = os.platform() === "linux" ? "tar.gz" : "zip"; - const downloadUrl = `${runnerBaseUrl.replace(/\/$/, "") || baseUrl}/graph-runner-${os.platform()}-${os.arch()}.${archiveExt}`; + const baseUrl = `https://github.com/actionforge/${pj.name}/releases/download/v${packageJson.version}`; + const downloadUrl = `${runnerBaseUrl.replace(/\/$/, "") || baseUrl}/graph-runner-${os.platform()}-${os.arch()}.zip`; if (runnerBaseUrl) { console.log("\u27a1 Custom runner URL set:", downloadUrl); } const downloadInfo = { downloadUrl: downloadUrl, - filename: 'graph-runner', + filename: `graph-runner-${os.platform()}-${os.arch()}`, }; runnerPath = await downloadRunner(downloadInfo, runnerBaseUrl ? null : token, runnerBaseUrl ? false : true);