Skip to content

Commit a14c9fc

Browse files
committed
Trying to fix
1 parent dae492b commit a14c9fc

File tree

2 files changed

+33
-40
lines changed

2 files changed

+33
-40
lines changed

.github/workflows/validate-release.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,23 @@ jobs:
2222
uses: MetaMask/action-checkout-and-setup@v1
2323
with:
2424
is-high-risk-environment: false
25-
# Fetch everything because we need to resolve commit refs
25+
# Fetch everything because if this is a pull request we need to
26+
# compare with the base branch
2627
fetch-depth: 0
2728
- name: Validate release
2829
id: validate-release
2930
run: |
3031
case "$GITHUB_EVENT_NAME" in
3132
push)
32-
yarn ts-node scripts/validate-release.ts "$GITHUB_EVENT_NAME" "$GITHUB_EVENT_BEFORE" "$GITHUB_SHA" "$GITHUB_EVENT_HEAD_COMMIT_MESSAGE" "$VALID_RELEASE_TITLE_PATTERNS"
33+
exec yarn ts-node scripts/validate-release.ts "$GITHUB_EVENT_NAME" "$GITHUB_EVENT_BEFORE" "$GITHUB_SHA" "$GITHUB_EVENT_HEAD_COMMIT_MESSAGE" "$VALID_RELEASE_TITLE_PATTERNS"
3334
;;
3435
pull_request)
35-
yarn ts-node scripts/validate-release.ts "$GITHUB_EVENT_NAME" "$GITHUB_BASE_REF" "$GITHUB_SHA" "$GITHUB_EVENT_PULL_REQUEST_TITLE" "$VALID_RELEASE_TITLE_PATTERNS"
36+
exec yarn ts-node scripts/validate-release.ts "$GITHUB_EVENT_NAME" "$GITHUB_BASE_REF" "$GITHUB_SHA" "$GITHUB_EVENT_PULL_REQUEST_TITLE" "$VALID_RELEASE_TITLE_PATTERNS"
3637
;;
3738
*)
3839
echo "Unknown GitHub event name: $GITHUB_EVENT_NAME"
3940
exit 1
41+
;;
4042
esac
4143
shell: bash
4244
env:

scripts/validate-release.ts

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,19 @@ main().catch((error) => {
4444
export async function main(): Promise<void> {
4545
const {
4646
githubEventName,
47-
baseCommitId,
48-
headCommitId,
47+
baseRef,
48+
headRef,
4949
possibleReleaseTitle,
5050
validReleaseTitlePatterns,
51-
} = await parseCommandLineArguments();
51+
} = parseCommandLineArguments();
5252

53-
console.log('\nRunning validations');
53+
console.log('Running validations');
5454
console.log('-------------------\n');
5555

5656
console.log('- Checking whether root version has been bumped...');
5757
const rootVersionBumpedResult = await validateRootVersionBumped(
58-
baseCommitId,
59-
headCommitId,
58+
baseRef,
59+
headRef,
6060
);
6161
console.log(` - ${rootVersionBumpedResult.message}`);
6262

@@ -73,7 +73,7 @@ export async function main(): Promise<void> {
7373

7474
console.log('- Checking whether any workspace packages have been bumped...');
7575
const anyWorkspacePackageVersionBumpedResult =
76-
await validateAnyPublicWorkspacePackageBumped(baseCommitId, headCommitId);
76+
await validateAnyPublicWorkspacePackageBumped(baseRef, headRef);
7777
console.log(` - ${anyWorkspacePackageVersionBumpedResult.message}`);
7878

7979
const releaseValidationResult = getReleaseValidationResult(
@@ -204,7 +204,7 @@ function failWithInvalidUsage(message: string) {
204204
*
205205
* @returns The previous commit ID and release title prefix.
206206
*/
207-
async function parseCommandLineArguments() {
207+
function parseCommandLineArguments() {
208208
const args = process.argv.slice(2);
209209

210210
if (args.length < 4) {
@@ -234,16 +234,10 @@ async function parseCommandLineArguments() {
234234
);
235235
}
236236

237-
const { stdout: baseCommitId } = await execa('git', ['rev-parse', baseRef]);
238-
const { stdout: headCommitId } = await execa('git', ['rev-parse', headRef]);
239-
240-
console.log(`Base commit: ${baseRef} -> ${baseCommitId}`);
241-
console.log(`Head commit: ${headRef} -> ${headCommitId}`);
242-
243237
return {
244238
githubEventName: githubEventName as GitHubEventName,
245-
baseCommitId,
246-
headCommitId,
239+
baseRef,
240+
headRef,
247241
possibleReleaseTitle,
248242
validReleaseTitlePatterns,
249243
};
@@ -271,24 +265,24 @@ async function getPublicWorkspaces(): Promise<WorkspaceInfo[]> {
271265
* Fetches the `package.json` in the directory from the base and head commits
272266
* and returns their version fields.
273267
*
274-
* @param baseCommitId - The ID of the first commit to fetch.
275-
* @param headCommitId - The ID of the second commit to fetch.
268+
* @param baseRef - The ref of the first commit to fetch.
269+
* @param headRef - The ref of the second commit to fetch.
276270
* @param directory - The directory where `package.json` is located (must end
277271
* with `/`).
278272
* @returns The output.
279273
*/
280274
async function getPreviousAndCurrentPackageVersions(
281-
baseCommitId: string,
282-
headCommitId: string,
275+
baseRef: string,
276+
headRef: string,
283277
directory: string,
284278
): Promise<{ previousVersion: string; currentVersion: string }> {
285279
const { stdout: rawPreviousManifest } = await execa('git', [
286280
'show',
287-
`${baseCommitId}:${directory}package.json`,
281+
`${baseRef}:${directory}package.json`,
288282
]);
289283
const { stdout: rawCurrentManifest } = await execa('git', [
290284
'show',
291-
`${headCommitId}:${directory}package.json`,
285+
`${headRef}:${directory}package.json`,
292286
]);
293287

294288
const previousManifest = JSON.parse(rawPreviousManifest) as {
@@ -342,6 +336,7 @@ function validateReleaseTitle({
342336
`^(?:${validReleaseTitleRegexpSource})$`,
343337
'u',
344338
);
339+
console.log('validReleaseTitleRegexp', validReleaseTitleRegexp);
345340
const match = possibleReleaseTitle.match(validReleaseTitleRegexp);
346341
const source =
347342
githubEventName === 'push' ? 'commit message' : 'pull request title';
@@ -363,20 +358,16 @@ function validateReleaseTitle({
363358
* Checks if the version in the the root package's `package.json` has been
364359
* bumped.
365360
*
366-
* @param baseCommitId - The base commit ID.
367-
* @param headCommitId - The head commit ID.
361+
* @param baseRef - The base commit ref.
362+
* @param headRef - The head commit ref.
368363
* @returns The result of the validation.
369364
*/
370365
async function validateRootVersionBumped(
371-
baseCommitId: string,
372-
headCommitId: string,
366+
baseRef: string,
367+
headRef: string,
373368
): Promise<RootVersionBumpedValidationResult> {
374369
const { previousVersion, currentVersion } =
375-
await getPreviousAndCurrentPackageVersions(
376-
baseCommitId,
377-
headCommitId,
378-
'./',
379-
);
370+
await getPreviousAndCurrentPackageVersions(baseRef, headRef, './');
380371

381372
if (currentVersion !== previousVersion) {
382373
return {
@@ -397,22 +388,22 @@ async function validateRootVersionBumped(
397388
/**
398389
* Checks if any of the versions among workspace package have been bumped.
399390
*
400-
* @param baseCommitId - The base commit ID.
401-
* @param headCommitId - The head commit ID.
391+
* @param baseRef - The base commit ref.
392+
* @param headRef - The head commit ref.
402393
* @returns The result of the validation.
403394
*/
404395
async function validateAnyPublicWorkspacePackageBumped(
405-
baseCommitId: string,
406-
headCommitId: string,
396+
baseRef: string,
397+
headRef: string,
407398
): Promise<AnyWorkspacePackageVersionBumpedValidationResult> {
408399
const publicWorkspaces = await getPublicWorkspaces();
409400

410401
const workspacesWithVersions = await Promise.all(
411402
publicWorkspaces.map(async (publicWorkspace) => {
412403
const { previousVersion, currentVersion } =
413404
await getPreviousAndCurrentPackageVersions(
414-
baseCommitId,
415-
headCommitId,
405+
baseRef,
406+
headRef,
416407
`${publicWorkspace.location}/`,
417408
);
418409

0 commit comments

Comments
 (0)