Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 7 additions & 1 deletion action-src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ async function run() {

process.chdir(path.join(process.cwd(), workingDir || ''));

if (context.eventName === 'merge_group' && exitZeroOnChanges === 'true') {
warning(
'`exitZeroOnChanges` is set to `true`, but you are running in a GitHub merge queue. Changes will not cause this build to fail. Consider removing this flag for merge queue runs to catch unexpected changes.'
);
}

const output = await runNode({
options: {
inAction: true,
Expand All @@ -169,7 +175,7 @@ async function run() {
diagnosticsFile: maybe(diagnosticsFile),
dryRun: maybe(dryRun),
exitOnceUploaded: maybe(exitOnceUploaded),
exitZeroOnChanges: maybe(exitZeroOnChanges, true),
exitZeroOnChanges: maybe(exitZeroOnChanges, context.eventName !== 'merge_group'),
externals: maybe(externals),
fileHashing: maybe(fileHashing, true),
forceRebuild: maybe(forceRebuild),
Expand Down
43 changes: 0 additions & 43 deletions node-src/git/getBranchFromMergeQueuePullRequestNumber.ts

This file was deleted.

19 changes: 5 additions & 14 deletions node-src/git/getCommitAndBranch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,15 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

import TestLogger from '../lib/testLogger';
import type { Context } from '../types';
import * as mergeQueue from './getBranchFromMergeQueuePullRequestNumber';
import getCommitAndBranch from './getCommitAndBranch';
import * as git from './git';

vi.mock('env-ci');
vi.mock('./git');
vi.mock('./getBranchFromMergeQueuePullRequestNumber');

const getBranch = vi.mocked(git.getBranch);
const getCommit = vi.mocked(git.getCommit);
const hasPreviousCommit = vi.mocked(git.hasPreviousCommit);
const getBranchFromMergeQueue = vi.mocked(mergeQueue.getBranchFromMergeQueuePullRequestNumber);
const mergeQueueBranchMatch = vi.mocked(git.mergeQueueBranchMatch);

const log = new TestLogger();
const ctx = { log } as unknown as Context;
Expand Down Expand Up @@ -58,15 +54,13 @@ beforeEach(() => {
committerEmail: 'noreply@github.com',
});
hasPreviousCommit.mockResolvedValue(true);
mergeQueueBranchMatch.mockResolvedValue(undefined);
});

afterEach(() => {
vi.unstubAllEnvs();
envCi.mockReset();
getBranch.mockReset();
getCommit.mockReset();
getBranchFromMergeQueue.mockReset();
});

const commitInfo = {
Expand Down Expand Up @@ -298,14 +292,11 @@ describe('getCommitAndBranch', () => {
});

describe('with mergeQueue branch', () => {
it('uses PRs branchName as branch instead of temporary mergeQueue branch', async () => {
mergeQueueBranchMatch.mockResolvedValue(4);
getBranchFromMergeQueue.mockResolvedValue('branch-before-merge-queue');
const info = await getCommitAndBranch(ctx, {
branchName:
'this-is-merge-queue-branch-format/main/pr-4-48e0c83fadbf504c191bc868040b7a969a4f1feb',
});
expect(info).toMatchObject({ branch: 'branch-before-merge-queue' });
it('passes the merge queue branch name through unchanged', async () => {
const mergeQueueBranch =
'gh-readonly-queue/main/pr-4-48e0c83fadbf504c191bc868040b7a969a4f1feb';
const info = await getCommitAndBranch(ctx, { branchName: mergeQueueBranch });
expect(info).toMatchObject({ branch: mergeQueueBranch });
});
});
});
20 changes: 1 addition & 19 deletions node-src/git/getCommitAndBranch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import missingTravisInfo from '../ui/messages/errors/missingTravisInfo';
import customGitHubAction from '../ui/messages/info/customGitHubAction';
import noCommitDetails from '../ui/messages/warnings/noCommitDetails';
import travisInternalBuild from '../ui/messages/warnings/travisInternalBuild';
import { getBranchFromMergeQueuePullRequestNumber } from './getBranchFromMergeQueuePullRequestNumber';
import { getBranch, getCommit, hasPreviousCommit, mergeQueueBranchMatch } from './git';
import { getBranch, getCommit, hasPreviousCommit } from './git';

const ORIGIN_PREFIX_REGEXP = /^origin\//;
const notHead = (branch) => (branch && branch !== 'HEAD' ? branch : false);
Expand Down Expand Up @@ -190,23 +189,6 @@ export default async function getCommitAndBranch(
branch = branch.replace(ORIGIN_PREFIX_REGEXP, '');
}

// When a PR is put into a merge queue, and prior PR is merged, the PR is retested against the latest on main.
// To do this, GitHub creates a new commit and does a CI run with the branch changed to e.g. gh-readonly-queue/main/pr-4-da07417adc889156224d03a7466ac712c647cd36
// If you configure merge queues to rebase in this circumstance,
// we lose track of baselines as the branch name has changed so our usual rebase detection (based on branch name) doesn't work.
const mergeQueueBranchPrNumber = await mergeQueueBranchMatch(ctx, branch);
if (mergeQueueBranchPrNumber) {
// This is why we extract the PR number from the branch name and use it to find the branch name of the PR that was merged.
const branchFromMergeQueuePullRequestNumber = await getBranchFromMergeQueuePullRequestNumber(
ctx,
{ number: mergeQueueBranchPrNumber }
);

if (branchFromMergeQueuePullRequestNumber) {
branch = branchFromMergeQueuePullRequestNumber;
}
}

log.debug(
`git info: ${JSON.stringify({
commit,
Expand Down
13 changes: 0 additions & 13 deletions node-src/git/git.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
getUserEmail,
getVersion,
hasPreviousCommit,
mergeQueueBranchMatch,
NULL_BYTE,
} from './git';

Expand Down Expand Up @@ -157,18 +156,6 @@ describe('commitExists', () => {
});
});

describe('mergeQueueBranchMatch', () => {
it('returns pr number if it is a merge queue branch', async () => {
const branch = 'gh-readonly-queue/main/pr-4-da07417adc889156224d03a7466ac712c647cd36';
expect(await mergeQueueBranchMatch(ctx, branch)).toEqual(4);
});

it('returns null if it is not a merge queue branch', async () => {
const branch = 'develop';
expect(await mergeQueueBranchMatch(ctx, branch)).toBeUndefined();
});
});

describe('findFilesFromRepositoryRoot', () => {
it('finds files relative to the repository root', async () => {
const filesFound = ['package.json', 'another/package/package.json'];
Expand Down
15 changes: 0 additions & 15 deletions node-src/git/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,21 +425,6 @@ export async function findFilesFromRepositoryRoot(
return files?.split(NULL_BYTE).filter(Boolean);
}

/**
* Determine if the branch is from a GitHub merge queue.
*
* @param _ctx Standard context object.
* @param branch The branch name in question.
*
* @returns The pull request number associated for the branch.
*/
export async function mergeQueueBranchMatch(_ctx: Pick<Context, 'log'>, branch: string) {
const mergeQueuePattern = new RegExp(/gh-readonly-queue\/.*\/pr-(\d+)-[\da-f]{30}/);
const match = branch.match(mergeQueuePattern);

return match ? Number(match[1]) : undefined;
}

/**
* Determine the date the repository was created
*
Expand Down
1 change: 0 additions & 1 deletion node-src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@ vi.mock('./git/git', () => ({
getRepositoryRoot: () => Promise.resolve(process.cwd()),
getUncommittedHash: () => Promise.resolve('abc123'),
getUserEmail: () => Promise.resolve('test@test.com'),
mergeQueueBranchMatch: () => Promise.resolve(undefined),
getRepositoryCreationDate: () => Promise.resolve(new Date('2024-11-01')),
getStorybookCreationDate: () => Promise.resolve(new Date('2025-11-01')),
getNumberOfComitters: () => Promise.resolve(17),
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@
"clean:sourcemaps": "rm -f dist/*.map && rm -f action/*.map"
},
"resolutions": {
"any-observable": "^0.5.1"
"any-observable": "^0.5.1",
"lodash": "4.17.21"
},
"devDependencies": {
"@actions/core": "^1.10.0",
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14302,7 +14302,7 @@ __metadata:
languageName: node
linkType: hard

"lodash@npm:^4.17.15, lodash@npm:^4.17.20, lodash@npm:^4.17.21":
"lodash@npm:4.17.21":
version: 4.17.21
resolution: "lodash@npm:4.17.21"
checksum: 10c0/d8cbea072bb08655bb4c989da418994b073a608dffa608b09ac04b43a791b12aeae7cd7ad919aa4c925f33b48490b5cfe6c1f71d827956071dae2e7bb3a6b74c
Expand Down
Loading