Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V dmshib/v8 canary factory #13

Open
wants to merge 53 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
9c158b3
Add support of v8 canary release
dsame Nov 9, 2022
588599b
Add v8 canary unit tests
dsame Nov 9, 2022
3e844cd
Add v8 canary tests to workflow
dsame Nov 9, 2022
21a3869
Change docs
dsame Nov 9, 2022
bced0ae
Build compiled js code
dsame Nov 9, 2022
f407277
Apply requested changes
dsame Nov 11, 2022
5f26e47
fixes after rebase
dsame Nov 22, 2022
0081915
refactor nightly and rc
dsame Nov 24, 2022
1536edb
Add tests
dsame Nov 24, 2022
d38528a
prettier
dsame Nov 24, 2022
a3c8983
dist
dsame Nov 24, 2022
6e2b26d
Fix windows test
dsame Nov 24, 2022
5056792
Fix nightly unit tests
dsame Nov 24, 2022
d2ef4bc
build dist
dsame Nov 24, 2022
4a961ae
Fix docs
dsame Nov 24, 2022
e542443
Fix versions.yml
dsame Nov 24, 2022
63e6b4a
change numbered list to bullet
dsame Nov 24, 2022
658b51b
requested changes
dsame Nov 24, 2022
d8923d1
remove v20.0.0 from workflow check
dsame Nov 25, 2022
c849fe6
convert logic initial
dmitry-shibanov Nov 29, 2022
e25fd13
comment code
dmitry-shibanov Nov 29, 2022
3533caf
remove case for Nightly
dmitry-shibanov Nov 29, 2022
b372056
remove unused code
dmitry-shibanov Nov 29, 2022
b717bf1
remove if
dmitry-shibanov Nov 30, 2022
40b42f0
initial changes
dmitry-shibanov Dec 13, 2022
360977c
minor fix
dmitry-shibanov Dec 13, 2022
2d741fb
minor fix
dmitry-shibanov Dec 13, 2022
292688b
minor fix
dmitry-shibanov Dec 13, 2022
7fc684f
minor fix
dmitry-shibanov Dec 13, 2022
0d35e2c
add possible improvement for canary
dmitry-shibanov Dec 13, 2022
9eba46a
change evaluateVersions
dmitry-shibanov Dec 13, 2022
05e1c35
add search in toolcache for canary
dmitry-shibanov Dec 13, 2022
15798ea
minor fix
dmitry-shibanov Dec 13, 2022
785620d
optimize code
dmitry-shibanov Dec 14, 2022
8dacd85
minor changes
dmitry-shibanov Dec 20, 2022
822a587
Merge branch 'main' into v-dmshib/v8-canary-factory
dmitry-shibanov Dec 20, 2022
2723204
restructure tests
dmitry-shibanov Dec 21, 2022
5af9d85
fixing main tests
dmitry-shibanov Dec 21, 2022
15e57b5
add mock
dmitry-shibanov Dec 21, 2022
f3c4889
minor polishing
dmitry-shibanov Dec 22, 2022
cd6d6a6
polish code
dmitry-shibanov Dec 22, 2022
df00183
minor changes
dmitry-shibanov Dec 22, 2022
e81c4f8
resolve comments
dmitry-shibanov Dec 27, 2022
f12d842
Merge branch 'main' into v-dmshib/v8-canary-factory
dmitry-shibanov Dec 27, 2022
7f2fa59
resolve comments
dmitry-shibanov Dec 27, 2022
363785e
remove changing prerelease
dmitry-shibanov Dec 27, 2022
68fd79d
minor fix
dmitry-shibanov Dec 27, 2022
a4584e0
regenerate dist
dmitry-shibanov Dec 27, 2022
8dfba60
fix dist
dmitry-shibanov Dec 27, 2022
166e53b
simplify code
dmitry-shibanov Dec 27, 2022
eec2a7e
minor changes
dmitry-shibanov Dec 28, 2022
0631b1d
revert some changes
dmitry-shibanov Dec 29, 2022
bcd8fae
npm audit
dmitry-shibanov Dec 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
requested changes
  • Loading branch information
dsame committed Nov 24, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 658b51b920c3c16aa0a14fe22636755c8b9ad38f
39 changes: 11 additions & 28 deletions __tests__/installer.test.ts
Original file line number Diff line number Diff line change
@@ -72,7 +72,6 @@ describe('setup-node', () => {
exSpy = jest.spyOn(tc, 'extractTar');
cacheSpy = jest.spyOn(tc, 'cacheDir');
getManifestSpy = jest.spyOn(tc, 'getManifestFromRepo');
// @ts-ignore
getDistSpy = jest.spyOn(im, 'getVersionsFromDist');
parseNodeVersionSpy = jest.spyOn(im, 'parseNodeVersionFile');

@@ -1302,37 +1301,25 @@ describe('setup-node', () => {

await main.run();

expect(dbgSpy.mock.calls[0][0]).toBe('requested v8 canary distribution');
expect(dbgSpy.mock.calls[1][0]).toBe('evaluating 17 versions');
expect(dbgSpy.mock.calls[2][0]).toBe(
'matched: v20.0.0-v8-canary20221103f7e2421e91'
);
expect(dbgSpy.mock.calls[0][0]).toBe('evaluating 0 versions');
expect(dbgSpy.mock.calls[1][0]).toBe('match not found');
expect(logSpy.mock.calls[0][0]).toBe(
'getting v8-canary node version v20.0.0-v8-canary20221103f7e2421e91...'
);
expect(logSpy.mock.calls[1][0]).toBe(
'Attempt to find existing version in cache...'
);
expect(dbgSpy.mock.calls[3][0]).toBe('evaluating 0 versions');
expect(dbgSpy.mock.calls[4][0]).toBe('match not found');
expect(logSpy.mock.calls[2][0]).toBe(
'Attempting to download v20.0.0-v8-canary20221103f7e2421e91...'
`Attempting to download ${versionSpec}...`
);
expect(dbgSpy.mock.calls[5][0]).toBe('No manifest cached');
expect(dbgSpy.mock.calls[6][0]).toBe(
expect(dbgSpy.mock.calls[2][0]).toBe('No manifest cached');
expect(dbgSpy.mock.calls[3][0]).toBe(
'Getting manifest from actions/node-versions@main'
);
expect(dbgSpy.mock.calls[7][0].slice(0, 6)).toBe('check ');
expect(dbgSpy.mock.calls[13][0].slice(0, 6)).toBe('check ');
expect(logSpy.mock.calls[3][0]).toBe(
expect(dbgSpy.mock.calls[4][0].slice(0, 6)).toBe('check ');
expect(dbgSpy.mock.calls[10][0].slice(0, 6)).toBe('check ');
expect(logSpy.mock.calls[1][0]).toBe(
'Not found in manifest. Falling back to download directly from Node'
);
expect(dbgSpy.mock.calls[14][0]).toBe('evaluating 17 versions');
expect(dbgSpy.mock.calls[15][0]).toBe(
expect(dbgSpy.mock.calls[12][0]).toBe('evaluating 17 versions');
expect(dbgSpy.mock.calls[13][0]).toBe(
'matched: v20.0.0-v8-canary20221103f7e2421e91'
);
expect(dbgSpy.mock.calls[16][0]).toBe('requested v8 canary distribution');
expect(logSpy.mock.calls[4][0]).toBe(
expect(logSpy.mock.calls[2][0]).toBe(
'Acquiring 20.0.0-v8-canary20221103f7e2421e91 - x64 from https://nodejs.org/download/v8-canary/v20.0.0-v8-canary20221103f7e2421e91/node-v20.0.0-v8-canary20221103f7e2421e91-linux-x64.tar.gz'
);

@@ -1373,29 +1360,25 @@ describe('setup-node', () => {
describe('helper methods', () => {
it('is not LTS alias', async () => {
const versionSpec = 'v99.0.0-v8-canary';
// @ts-ignore
const isLtsAlias = im.isLtsAlias(versionSpec);
expect(isLtsAlias).toBeFalsy();
});

it('is not isLatestSyntax', async () => {
const versionSpec = 'v99.0.0-v8-canary';
// @ts-ignore
const isLatestSyntax = im.isLatestSyntax(versionSpec);
expect(isLatestSyntax).toBeFalsy();
});

describe('getNodejsDistUrl', () => {
it('dist url to be https://nodejs.org/download/v8-canary for input versionSpec', () => {
const versionSpec = 'v99.0.0-v8-canary';
// @ts-ignore
const url = im.getNodejsDistUrl(versionSpec);
expect(url).toBe('https://nodejs.org/download/v8-canary');
});

it('dist url to be https://nodejs.org/download/v8-canary for full versionSpec', () => {
const versionSpec = 'v20.0.0-v8-canary20221103f7e2421e91';
// @ts-ignore
const url = im.getNodejsDistUrl(versionSpec);
expect(url).toBe('https://nodejs.org/download/v8-canary');
});
10 changes: 0 additions & 10 deletions __tests__/installer.unit.test.ts
Original file line number Diff line number Diff line change
@@ -41,16 +41,6 @@ describe('setup-node unit tests', () => {
Distributions.CANARY
);
});
it('1.1.1-canary should throw exception', () => {
expect(() => distributionOf('1.1.1-canary')).toThrow(
'Canary version must have "-v8-canary suffix"'
);
});
it('1.1.1-canary20221103f7e2421e91 should throw exception', () => {
expect(() => distributionOf('1.1.1-canary20221103f7e2421e91')).toThrow(
'Canary version must have "-v8-canary suffix"'
);
});
it('1.1.1-nightly should be NIGHTLY', () => {
expect(distributionOf('1.1.1-nightly')).toBe(Distributions.NIGHTLY);
});
51 changes: 24 additions & 27 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
@@ -73218,23 +73218,20 @@ const semver = __importStar(__nccwpck_require__(5911));
const fs_1 = __importDefault(__nccwpck_require__(7147));
var Distributions;
(function (Distributions) {
Distributions[Distributions["DEFAULT"] = 0] = "DEFAULT";
Distributions[Distributions["CANARY"] = 1] = "CANARY";
Distributions[Distributions["NIGHTLY"] = 2] = "NIGHTLY";
Distributions[Distributions["RC"] = 3] = "RC";
Distributions["DEFAULT"] = "default";
Distributions["CANARY"] = "v8-canary";
Distributions["NIGHTLY"] = "nightly";
Distributions["RC"] = "rc";
})(Distributions = exports.Distributions || (exports.Distributions = {}));
exports.distributionOf = (versionSpec) => versionSpec.includes('-v8-canary')
? Distributions.CANARY
: // TODO: i'd like to have this check, do you?
versionSpec.includes('-canary')
? (() => {
throw Error('Canary version must have "-v8-canary suffix"');
})()
: versionSpec.includes('nightly')
? Distributions.NIGHTLY
: semver.prerelease(versionSpec)
? Distributions.RC
: Distributions.DEFAULT;
exports.distributionOf = (versionSpec) => {
if (versionSpec.includes('-v8-canary'))
return Distributions.CANARY;
if (versionSpec.includes('nightly'))
return Distributions.NIGHTLY;
if (semver.prerelease(versionSpec))
return Distributions.RC;
return Distributions.DEFAULT;
};
exports.semverVersionMatcherFactory = (range) => {
const matcher = (potential) => semver.satisfies(potential, range);
matcher.factory = exports.semverVersionMatcherFactory;
@@ -73325,17 +73322,20 @@ function getNode(versionSpec, stable, checkLatest, auth, arch = os_1.default.arc
manifest = yield getManifest(auth);
versionSpec = resolveLtsAliasFromManifest(versionSpec, stable, manifest);
}
// TODO: 183-189 and 193-194 seems to be the same. Why do we need them?
if (isLatestSyntax(versionSpec) || distribution == Distributions.CANARY) {
if (isLatestSyntax(versionSpec)) {
nodeVersions = yield getVersionsFromDist(versionSpec);
versionSpec = yield queryDistForMatch(versionSpec, arch, nodeVersions);
core.info(`getting ${distribution == Distributions.CANARY ? 'v8-canary' : 'latest'} node version ${versionSpec}...`);
core.info(`getting latest node version ${versionSpec}...`);
}
if (distribution === Distributions.NIGHTLY && checkLatest) {
if ((distribution === Distributions.NIGHTLY ||
distribution === Distributions.CANARY) &&
checkLatest) {
nodeVersions = yield getVersionsFromDist(versionSpec);
versionSpec = yield queryDistForMatch(versionSpec, arch, nodeVersions);
}
if (checkLatest && distribution !== Distributions.NIGHTLY) {
if (checkLatest &&
distribution !== Distributions.NIGHTLY &&
distribution !== Distributions.CANARY) {
core.info('Attempt to resolve the latest version from manifest...');
const resolvedVersion = yield resolveVersionFromManifest(versionSpec, stable, auth, osArch, manifest);
if (resolvedVersion) {
@@ -73347,7 +73347,6 @@ function getNode(versionSpec, stable, checkLatest, auth, arch = os_1.default.arc
}
}
// check cache
core.info('Attempt to find existing version in cache...');
let toolPath;
if (distribution === Distributions.DEFAULT) {
toolPath = tc.find('node', versionSpec, osArch);
@@ -73562,13 +73561,10 @@ exports.evaluateVersions = evaluateVersions;
function getNodejsDistUrl(version) {
switch (exports.distributionOf(version)) {
case Distributions.CANARY:
core.debug('requested v8 canary distribution');
return 'https://nodejs.org/download/v8-canary';
case Distributions.NIGHTLY:
core.debug('requested nightly distribution');
return 'https://nodejs.org/download/nightly';
case Distributions.RC:
core.debug('requested release candidates distribution');
return 'https://nodejs.org/download/rc';
case Distributions.DEFAULT:
return 'https://nodejs.org/dist';
@@ -73602,15 +73598,16 @@ function queryDistForMatch(versionSpec, arch = os_1.default.arch(), nodeVersions
core.info(`getting latest node version...`);
return nodeVersions[0].version;
}
let versions = [];
const versions = [];
nodeVersions.forEach((nodeVersion) => {
// ensure this version supports your os and platform
if (nodeVersion.files.indexOf(dataFileName) >= 0) {
versions.push(nodeVersion.version);
}
});
// get the latest version that matches the version spec
return evaluateVersions(versions, versionSpec);
const version = evaluateVersions(versions, versionSpec);
return version;
});
}
exports.queryDistForMatch = queryDistForMatch;
57 changes: 25 additions & 32 deletions src/installer.ts
Original file line number Diff line number Diff line change
@@ -31,25 +31,18 @@ interface INodeRelease extends tc.IToolRelease {
}

export enum Distributions {
DEFAULT,
CANARY,
NIGHTLY,
RC
DEFAULT = 'default',
CANARY = 'v8-canary',
NIGHTLY = 'nightly',
RC = 'rc'
}

export const distributionOf = (versionSpec: string): Distributions =>
versionSpec.includes('-v8-canary')
? Distributions.CANARY
: // TODO: i'd like to have this check, do you?
versionSpec.includes('-canary')
? (() => {
throw Error('Canary version must have "-v8-canary suffix"');
})()
: versionSpec.includes('nightly')
? Distributions.NIGHTLY
: semver.prerelease(versionSpec)
? Distributions.RC
: Distributions.DEFAULT;
export const distributionOf = (versionSpec: string): Distributions => {
if (versionSpec.includes('-v8-canary')) return Distributions.CANARY;
if (versionSpec.includes('nightly')) return Distributions.NIGHTLY;
if (semver.prerelease(versionSpec)) return Distributions.RC;
return Distributions.DEFAULT;
};

interface VersionMatcher {
(potential: string): boolean;
@@ -190,23 +183,26 @@ export async function getNode(
versionSpec = resolveLtsAliasFromManifest(versionSpec, stable, manifest);
}

// TODO: 183-189 and 193-194 seems to be the same. Why do we need them?
if (isLatestSyntax(versionSpec) || distribution == Distributions.CANARY) {
if (isLatestSyntax(versionSpec)) {
nodeVersions = await getVersionsFromDist(versionSpec);
versionSpec = await queryDistForMatch(versionSpec, arch, nodeVersions);
core.info(
`getting ${
distribution == Distributions.CANARY ? 'v8-canary' : 'latest'
} node version ${versionSpec}...`
);
core.info(`getting latest node version ${versionSpec}...`);
}

if (distribution === Distributions.NIGHTLY && checkLatest) {
if (
(distribution === Distributions.NIGHTLY ||
distribution === Distributions.CANARY) &&
checkLatest
) {
nodeVersions = await getVersionsFromDist(versionSpec);
versionSpec = await queryDistForMatch(versionSpec, arch, nodeVersions);
}

if (checkLatest && distribution !== Distributions.NIGHTLY) {
if (
checkLatest &&
distribution !== Distributions.NIGHTLY &&
distribution !== Distributions.CANARY
) {
core.info('Attempt to resolve the latest version from manifest...');
const resolvedVersion = await resolveVersionFromManifest(
versionSpec,
@@ -224,7 +220,6 @@ export async function getNode(
}

// check cache
core.info('Attempt to find existing version in cache...');
let toolPath: string;
if (distribution === Distributions.DEFAULT) {
toolPath = tc.find('node', versionSpec, osArch);
@@ -521,13 +516,10 @@ export function evaluateVersions(
export function getNodejsDistUrl(version: string) {
switch (distributionOf(version)) {
case Distributions.CANARY:
core.debug('requested v8 canary distribution');
return 'https://nodejs.org/download/v8-canary';
case Distributions.NIGHTLY:
core.debug('requested nightly distribution');
return 'https://nodejs.org/download/nightly';
case Distributions.RC:
core.debug('requested release candidates distribution');
return 'https://nodejs.org/download/rc';
case Distributions.DEFAULT:
return 'https://nodejs.org/dist';
@@ -568,7 +560,7 @@ export async function queryDistForMatch(
return nodeVersions[0].version;
}

let versions: string[] = [];
const versions: string[] = [];
nodeVersions.forEach((nodeVersion: INodeVersion) => {
// ensure this version supports your os and platform
if (nodeVersion.files.indexOf(dataFileName) >= 0) {
@@ -577,7 +569,8 @@ export async function queryDistForMatch(
});

// get the latest version that matches the version spec
return evaluateVersions(versions, versionSpec);
const version = evaluateVersions(versions, versionSpec);
return version;
}

export async function getVersionsFromDist(