Skip to content

Commit

Permalink
fix: use correct V8 tag for minor updates (#695)
Browse files Browse the repository at this point in the history
Refs: #675
  • Loading branch information
targos authored Apr 16, 2023
1 parent 0d01f9a commit cf03df4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
8 changes: 4 additions & 4 deletions lib/update-v8/majorUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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',
Expand All @@ -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) {
Expand Down
7 changes: 4 additions & 3 deletions lib/update-v8/minorUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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];
}
};
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 4 additions & 0 deletions lib/update-v8/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,7 @@ export function removeDirectory(path) {
return fs.rmdir(path, { recursive: true });
}
}

export function isVersionString(str) {
return /^\d+(\.\d+)+$/.test(str);
}

0 comments on commit cf03df4

Please sign in to comment.