Compare commits

..

2 Commits

Author SHA1 Message Date
122dd47e5f 内网源 2024-08-22 10:02:19 +08:00
e88ea03761 内网源 2024-08-22 10:02:18 +08:00
6 changed files with 120 additions and 46 deletions

View File

@ -1,22 +0,0 @@
name: 'Publish Immutable Action Version'
on:
release:
types: [created]
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
packages: write
steps:
- name: Checking out
uses: actions/checkout@v4
- name: Publish
id: publish
uses: actions/publish-immutable-action@0.0.1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

View File

@ -21,7 +21,7 @@ See [action.yml](action.yml)
- uses: actions/setup-node@v4
with:
# Version Spec of the version to use in SemVer notation.
# It also admits such aliases as lts/*, latest, nightly and canary builds
# It also admits such aliases as lts, latest, nightly and canary builds
# Examples: 12.x, 10.15.1, >=10.15.0, lts/Hydrogen, 16-nightly, latest, node
node-version: ''

53
dist/setup/index.js vendored
View File

@ -93883,7 +93883,7 @@ class BaseDistribution {
}
throw err;
}
const toolPath = yield this.extractArchive(downloadPath, info, true);
const toolPath = yield this.extractArchive(downloadPath, info);
core.info('Done');
return toolPath;
});
@ -93933,7 +93933,7 @@ class BaseDistribution {
return toolPath;
});
}
extractArchive(downloadPath, info, isOfficialArchive) {
extractArchive(downloadPath, info) {
return __awaiter(this, void 0, void 0, function* () {
//
// Extract
@ -93948,7 +93948,7 @@ class BaseDistribution {
// on Windows runners without PowerShell Core.
//
// For default PowerShell Windows it should contain extension type to unpack it.
if (extension === '.zip' && isOfficialArchive) {
if (extension === '.zip') {
const renamedArchive = `${downloadPath}.zip`;
fs_1.default.renameSync(downloadPath, renamedArchive);
extPath = yield tc.extractZip(renamedArchive);
@ -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));
@ -94186,7 +94187,7 @@ class OfficialBuilds extends base_distribution_1.default {
core.info(`Acquiring ${versionInfo.resolvedVersion} - ${versionInfo.arch} from ${versionInfo.downloadUrl}`);
downloadPath = yield tc.downloadTool(versionInfo.downloadUrl, undefined, this.nodeInfo.auth);
if (downloadPath) {
toolPath = yield this.extractArchive(downloadPath, versionInfo, false);
toolPath = yield this.extractArchive(downloadPath, versionInfo);
}
}
else {
@ -94256,8 +94257,46 @@ class OfficialBuilds extends base_distribution_1.default {
return `https://nodejs.org/dist`;
}
getManifest() {
core.debug('Getting manifest from actions/node-versions@main');
return tc.getManifestFromRepo('actions', 'node-versions', this.nodeInfo.auth, 'main');
core.info('Getting manifest from actions/node-versions@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;
@ -94300,7 +94339,7 @@ class OfficialBuilds extends base_distribution_1.default {
return __awaiter(this, void 0, void 0, function* () {
let info = null;
if (!manifest) {
core.debug('No manifest cached');
core.info('No manifest cached');
manifest = yield this.getManifest();
}
const rel = yield tc.findFromManifest(versionSpec, stable, manifest, osArch);

8
package-lock.json generated
View File

@ -4429,12 +4429,12 @@
}
},
"node_modules/micromatch": {
"version": "4.0.8",
"resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz",
"integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==",
"version": "4.0.5",
"resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz",
"integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==",
"dev": true,
"dependencies": {
"braces": "^3.0.3",
"braces": "^3.0.2",
"picomatch": "^2.3.1"
},
"engines": {

View File

@ -150,7 +150,7 @@ export default abstract class BaseDistribution {
throw err;
}
const toolPath = await this.extractArchive(downloadPath, info, true);
const toolPath = await this.extractArchive(downloadPath, info);
core.info('Done');
return toolPath;
@ -210,8 +210,7 @@ export default abstract class BaseDistribution {
protected async extractArchive(
downloadPath: string,
info: INodeVersionInfo | null,
isOfficialArchive?: boolean
info: INodeVersionInfo | null
) {
//
// Extract
@ -226,7 +225,7 @@ export default abstract class BaseDistribution {
// on Windows runners without PowerShell Core.
//
// For default PowerShell Windows it should contain extension type to unpack it.
if (extension === '.zip' && isOfficialArchive) {
if (extension === '.zip') {
const renamedArchive = `${downloadPath}.zip`;
fs.renameSync(downloadPath, renamedArchive);
extPath = await tc.extractZip(renamedArchive);

View File

@ -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);
@ -88,11 +101,7 @@ export default class OfficialBuilds extends BaseDistribution {
);
if (downloadPath) {
toolPath = await this.extractArchive(
downloadPath,
versionInfo,
false
);
toolPath = await this.extractArchive(downloadPath, versionInfo);
}
} else {
core.info(
@ -181,8 +190,8 @@ export default class OfficialBuilds extends BaseDistribution {
}
private getManifest(): Promise<tc.IToolRelease[]> {
core.debug('Getting manifest from actions/node-versions@main');
return tc.getManifestFromRepo(
core.info('Getting manifest from actions/node-versions@main');
return this.getManifestFromRepo(
'actions',
'node-versions',
this.nodeInfo.auth,
@ -190,6 +199,55 @@ export default class OfficialBuilds extends BaseDistribution {
);
}
private async getManifestFromRepo(
owner: string,
repo: string,
auth?: string,
branch = 'master'
): Promise<tc.IToolRelease[]> {
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<GitHubTree>(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,
@ -262,7 +320,7 @@ export default class OfficialBuilds extends BaseDistribution {
): Promise<INodeVersionInfo | null> {
let info: INodeVersionInfo | null = null;
if (!manifest) {
core.debug('No manifest cached');
core.info('No manifest cached');
manifest = await this.getManifest();
}