From 4c7c3f7073ea3e017039174a00b16841f01bce05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Thu, 13 Apr 2023 14:11:31 +0200 Subject: [PATCH] fix: use correct V8 tag for minor updates Refs: https://github.com/nodejs/node-core-utils/pull/675 --- lib/update-v8/majorUpdate.js | 8 ++++---- lib/update-v8/minorUpdate.js | 7 ++++--- lib/update-v8/util.js | 4 ++++ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/update-v8/majorUpdate.js b/lib/update-v8/majorUpdate.js index 736c4344..e29cae59 100644 --- a/lib/update-v8/majorUpdate.js +++ b/lib/update-v8/majorUpdate.js @@ -11,7 +11,8 @@ import { filterForVersion, addToGitignore, replaceGitignore, - removeDirectory + removeDirectory, + isVersionString } from './util.js'; import applyNodeChanges from './applyNodeChanges.js'; import { chromiumGit, v8Deps } from './constants.js'; @@ -38,14 +39,13 @@ export default function majorUpdate() { }; }; -const versionReg = /^\d+(\.\d+)+$/; function checkoutBranch() { return { title: 'Checkout V8 branch', task: async(ctx) => { let version = ctx.branch; await ctx.execGitV8('checkout', 'origin/main'); - if (!versionReg.test(version)) { + if (!isVersionString(version)) { // try to get the latest tag const res = await ctx.execGitV8( 'tag', @@ -54,7 +54,7 @@ function checkoutBranch() { '--sort', 'version:refname' ); - const tags = res.stdout.split('\n').filter(tag => versionReg.test(tag)); + const tags = res.stdout.split('\n').filter(isVersionString); const lastTag = tags[tags.length - 1]; if (lastTag) version = lastTag; if (version.split('.').length === 3) { diff --git a/lib/update-v8/minorUpdate.js b/lib/update-v8/minorUpdate.js index 0c50d0fb..bd1ba0a5 100644 --- a/lib/update-v8/minorUpdate.js +++ b/lib/update-v8/minorUpdate.js @@ -6,6 +6,7 @@ import { execa } from 'execa'; import { Listr } from 'listr2'; import { getCurrentV8Version } from './common.js'; +import { isVersionString } from './util.js'; export default function minorUpdate() { return { @@ -34,7 +35,7 @@ function getLatestV8Version() { cwd: ctx.v8Dir, encoding: 'utf8' }); - const tags = toSortedArray(result.stdout); + const tags = filterAndSortTags(result.stdout); ctx.latestVersion = tags[0]; } }; @@ -79,10 +80,10 @@ async function applyPatch(ctx, latestStr) { } } -function toSortedArray(tags) { +function filterAndSortTags(tags) { return tags .split(/[\r\n]+/) - .filter((tag) => tag !== '') + .filter(isVersionString) .map((tag) => tag.split('.')) .sort(sortVersions); } diff --git a/lib/update-v8/util.js b/lib/update-v8/util.js index 3f929ec2..b94a4356 100644 --- a/lib/update-v8/util.js +++ b/lib/update-v8/util.js @@ -56,3 +56,7 @@ export function removeDirectory(path) { return fs.rmdir(path, { recursive: true }); } } + +export function isVersionString(str) { + return /^\d+(\.\d+)+$/.test(str); +}