diff --git a/dist/setup/index.js b/dist/setup/index.js index 2e3e552..e6d14d8 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -94136,6 +94136,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", ({ value: true })); const core = __importStar(__nccwpck_require__(2186)); +const httpm = __importStar(__nccwpck_require__(6255)); const tc = __importStar(__nccwpck_require__(7784)); const path_1 = __importDefault(__nccwpck_require__(1017)); const base_distribution_1 = __importDefault(__nccwpck_require__(7)); @@ -94257,7 +94258,45 @@ class OfficialBuilds extends base_distribution_1.default { } getManifest() { core.debug('Getting manifest from actions/node-versions@main'); - return tc.getManifestFromRepo('actions', 'node-versions', this.nodeInfo.auth, 'main'); + return this.getManifestFromRepo('actions', 'node-versions', this.nodeInfo.auth, 'main'); + } + getManifestFromRepo(owner, repo, auth, branch = 'master') { + return __awaiter(this, void 0, void 0, function* () { + let releases = []; + const treeUrl = `https://gitea.icodef.com/api/v1/repos/${owner}/${repo}/git/trees/${branch}`; + const http = new httpm.HttpClient('tool-cache'); + const headers = {}; + if (auth) { + core.debug('set auth'); + headers.authorization = auth; + } + const response = yield http.getJson(treeUrl, headers); + if (!response.result) { + return releases; + } + let manifestUrl = ''; + for (const item of response.result.tree) { + if (item.path === 'versions-manifest.json') { + manifestUrl = item.url; + break; + } + } + headers['accept'] = 'application/vnd.github.VERSION.raw'; + const versionsRaw = yield (yield http.get(manifestUrl, headers)).readBody(); + const base64 = JSON.parse(versionsRaw); + let tmp = Buffer.from(base64['content'], 'base64').toString('ascii'); + if (tmp) { + // shouldn't be needed but protects against invalid json saved with BOM + tmp = tmp.replace(/^\uFEFF/, ''); + try { + releases = JSON.parse(tmp); + } + catch (_a) { + core.debug('Invalid json'); + } + } + return releases; + }); } resolveLtsAliasFromManifest(versionSpec, stable, manifest) { var _a; diff --git a/src/distributions/official_builds/official_builds.ts b/src/distributions/official_builds/official_builds.ts index 4e368b0..3ab31d2 100644 --- a/src/distributions/official_builds/official_builds.ts +++ b/src/distributions/official_builds/official_builds.ts @@ -1,14 +1,27 @@ import * as core from '@actions/core'; +import * as httpm from '@actions/http-client'; import * as tc from '@actions/tool-cache'; import path from 'path'; import BaseDistribution from '../base-distribution'; import {NodeInputs, INodeVersion, INodeVersionInfo} from '../base-models'; +import {OutgoingHttpHeaders} from 'http'; interface INodeRelease extends tc.IToolRelease { lts?: string; } +interface GitHubTreeItem { + path: string; + size: string; + url: string; +} + +interface GitHubTree { + tree: GitHubTreeItem[]; + truncated: boolean; +} + export default class OfficialBuilds extends BaseDistribution { constructor(nodeInfo: NodeInputs) { super(nodeInfo); @@ -178,7 +191,7 @@ export default class OfficialBuilds extends BaseDistribution { private getManifest(): Promise { core.debug('Getting manifest from actions/node-versions@main'); - return tc.getManifestFromRepo( + return this.getManifestFromRepo( 'actions', 'node-versions', this.nodeInfo.auth, @@ -186,6 +199,55 @@ export default class OfficialBuilds extends BaseDistribution { ); } + private async getManifestFromRepo( + owner: string, + repo: string, + auth?: string, + branch = 'master' + ): Promise { + let releases: tc.IToolRelease[] = []; + const treeUrl = `https://gitea.icodef.com/api/v1/repos/${owner}/${repo}/git/trees/${branch}`; + + const http: httpm.HttpClient = new httpm.HttpClient('tool-cache'); + const headers: OutgoingHttpHeaders = {}; + if (auth) { + core.debug('set auth'); + headers.authorization = auth; + } + + const response = await http.getJson(treeUrl, headers); + if (!response.result) { + return releases; + } + + let manifestUrl = ''; + for (const item of response.result.tree) { + if (item.path === 'versions-manifest.json') { + manifestUrl = item.url; + break; + } + } + + headers['accept'] = 'application/vnd.github.VERSION.raw'; + const versionsRaw = await (await http.get(manifestUrl, headers)).readBody(); + + const base64 = JSON.parse(versionsRaw); + + let tmp = Buffer.from(base64['content'], 'base64').toString('ascii'); + + if (tmp) { + // shouldn't be needed but protects against invalid json saved with BOM + tmp = tmp.replace(/^\uFEFF/, ''); + try { + releases = JSON.parse(tmp); + } catch { + core.debug('Invalid json'); + } + } + + return releases; + } + private resolveLtsAliasFromManifest( versionSpec: string, stable: boolean,