moved node version section in README to advanced usage

added link to README
* migrated contents of version-file-workflow.yml to versions.yml
* further refactored parseNodeVersionFile() & tests
* removed type annotations in catch ()
This commit is contained in:
La'Kaleigh Harris 2021-10-05 15:01:26 +00:00 committed by GitHub
parent e471f47826
commit b1ed0c36e7
8 changed files with 113 additions and 17531 deletions

View file

@ -8,7 +8,10 @@ import * as path from 'path';
import * as semver from 'semver';
import fs = require('fs');
//
// Node versions interface
// see https://nodejs.org/dist/index.json
//
export interface INodeVersion {
version: string;
@ -97,7 +100,7 @@ export async function getNode(
'Not found in manifest. Falling back to download directly from Node'
);
}
} catch (err : any) {
} catch (err) {
// Rate limit?
if (
err instanceof tc.HTTPError &&
@ -311,7 +314,7 @@ async function resolveVersionFromManifest(
manifest
);
return info?.resolvedVersion;
} catch (err : any) {
} catch (err) {
core.info('Unable to resolve version from manifest...');
core.debug(err.message);
}
@ -464,30 +467,13 @@ function translateArchToDistUrl(arch: string): string {
}
export async function parseNodeVersionFile(contents: string): Promise<string> {
contents = contents.trim();
let nodeVersion = contents.trim();
if (/^v\d/.test(contents)) {
contents = contents.substring(1);
if (/^v\d/.test(nodeVersion)) {
nodeVersion = nodeVersion.substring(1);
}
const nodeVersions = await getVersionsFromDist();
let nodeVersion: string;
if (semver.valid(contents) || isPartialMatch(contents)) {
nodeVersion = contents;
} else {
throw new Error(`Couldn't resolve node version: '${contents}'`);
}
return stripVPrefix(nodeVersion);
return nodeVersion;
}
function isPartialMatch(version: string): boolean {
return /^\d+(\.\d+(\.\d+)?)?$/.test(version);
}
function stripVPrefix(version: string): string {
return /^v\d/.test(version) ? version.substring(1) : version;
}

View file

@ -80,11 +80,9 @@ export async function run() {
}
}
function isGhes(): boolean {
const ghUrl = new URL(
process.env['GITHUB_SERVER_URL'] || 'https://github.com'
);
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
}
}