diff --git a/action-src/main.ts b/action-src/main.ts index 36baf79f7..2f92bbd3a 100755 --- a/action-src/main.ts +++ b/action-src/main.ts @@ -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, @@ -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), diff --git a/node-src/git/getBranchFromMergeQueuePullRequestNumber.ts b/node-src/git/getBranchFromMergeQueuePullRequestNumber.ts deleted file mode 100644 index bfd40b5d3..000000000 --- a/node-src/git/getBranchFromMergeQueuePullRequestNumber.ts +++ /dev/null @@ -1,43 +0,0 @@ -import gql from 'fake-tag'; - -import { Context } from '../types'; - -const MergeQueueOriginalBranchQuery = gql` - query MergeQueueOriginalBranchQuery($number: Int!) { - app { - pullRequest(number: $number) { - branch: headRefName - } - } - } -`; -interface MergeQueueOriginalBranchQueryResult { - app: { - pullRequest: { - branch: string; - }; - }; -} - -/** - * Get branch name from a pull request number via the Index service. - * - * @param ctx The context set when executing the CLI. - * @param options Options to pass to the Index query. - * @param options.number The pull request number. - * - * @returns The branch name, if available. - */ -export async function getBranchFromMergeQueuePullRequestNumber( - ctx: Pick, - { number }: { number: number } -) { - const { app } = await ctx.client.runQuery( - MergeQueueOriginalBranchQuery, - { - number, - } - ); - - return app?.pullRequest?.branch; -} diff --git a/node-src/git/getCommitAndBranch.test.ts b/node-src/git/getCommitAndBranch.test.ts index f07e0d721..505d0e90b 100644 --- a/node-src/git/getCommitAndBranch.test.ts +++ b/node-src/git/getCommitAndBranch.test.ts @@ -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; @@ -58,7 +54,6 @@ beforeEach(() => { committerEmail: 'noreply@github.com', }); hasPreviousCommit.mockResolvedValue(true); - mergeQueueBranchMatch.mockResolvedValue(undefined); }); afterEach(() => { @@ -66,7 +61,6 @@ afterEach(() => { envCi.mockReset(); getBranch.mockReset(); getCommit.mockReset(); - getBranchFromMergeQueue.mockReset(); }); const commitInfo = { @@ -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 }); }); }); }); diff --git a/node-src/git/getCommitAndBranch.ts b/node-src/git/getCommitAndBranch.ts index 2286b3870..2500661f0 100644 --- a/node-src/git/getCommitAndBranch.ts +++ b/node-src/git/getCommitAndBranch.ts @@ -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); @@ -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, diff --git a/node-src/git/git.test.ts b/node-src/git/git.test.ts index b30bd30c8..884dc7795 100644 --- a/node-src/git/git.test.ts +++ b/node-src/git/git.test.ts @@ -16,7 +16,6 @@ import { getUserEmail, getVersion, hasPreviousCommit, - mergeQueueBranchMatch, NULL_BYTE, } from './git'; @@ -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']; diff --git a/node-src/git/git.ts b/node-src/git/git.ts index e284ff2e9..5060e9926 100644 --- a/node-src/git/git.ts +++ b/node-src/git/git.ts @@ -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, 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 * diff --git a/node-src/index.test.ts b/node-src/index.test.ts index dfc4a905e..32f5580fb 100644 --- a/node-src/index.test.ts +++ b/node-src/index.test.ts @@ -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), diff --git a/package.json b/package.json index b10b0e4e2..21509e3f6 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/yarn.lock b/yarn.lock index 650f755c1..5791d1147 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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