From 97e3b047729ba89867bc338fcdac9267907c1ddf Mon Sep 17 00:00:00 2001 From: Paulo Viana Date: Wed, 13 Mar 2024 23:33:24 -0400 Subject: [PATCH 1/4] Update find-successful-workflow.ts --- find-successful-workflow.ts | 55 ++++--------------------------------- 1 file changed, 6 insertions(+), 49 deletions(-) diff --git a/find-successful-workflow.ts b/find-successful-workflow.ts index 1aff4d4..2dc0ee5 100644 --- a/find-successful-workflow.ts +++ b/find-successful-workflow.ts @@ -40,23 +40,12 @@ let BASE_SHA: string; }); const HEAD_SHA = headResult.stdout; - if ( - (['pull_request', 'pull_request_target'].includes(eventName) && - !github.context.payload.pull_request.merged) || - eventName == 'merge_group' - ) { - try { - const mergeBaseRef = await findMergeBaseRef(); - const baseResult = spawnSync( - 'git', - ['merge-base', `origin/${mainBranchName}`, mergeBaseRef], - { encoding: 'utf-8' }, - ); - BASE_SHA = baseResult.stdout; - } catch (e) { - core.setFailed(e.message); - return; - } + if (['pull_request', 'pull_request_target'].includes(eventName) && !github.context.payload.pull_request.merged) { + const baseResult = spawnSync('git', ['merge-base', `origin/${mainBranchName}`, 'HEAD'], { encoding: 'utf-8' }); + BASE_SHA = baseResult.stdout; + } else if (eventName == "merge_group") { + const baseResult = spawnSync('git', ['rev-parse', 'HEAD^1'], { encoding: 'utf-8' }); + BASE_SHA = baseResult.stdout; } else { try { BASE_SHA = await findSuccessfulCommit( @@ -204,38 +193,6 @@ async function findSuccessfulCommit( return await findExistingCommit(octokit, branch, shas); } -async function findMergeBaseRef(): Promise { - if (eventName == 'merge_group') { - const mergeQueueBranch = await findMergeQueueBranch(); - return `origin/${mergeQueueBranch}`; - } else { - return 'HEAD'; - } -} - -function findMergeQueuePr(): string { - const { head_ref, base_sha } = github.context.payload.merge_group; - const result = new RegExp( - `^refs/heads/gh-readonly-queue/${mainBranchName}/pr-(\\d+)-${base_sha}$`, - ).exec(head_ref); - return result ? result.at(1) : undefined; -} - -async function findMergeQueueBranch(): Promise { - const pull_number = findMergeQueuePr(); - if (!pull_number) { - throw new Error('Failed to determine PR number'); - } - process.stdout.write('\n'); - process.stdout.write(`Found PR #${pull_number} from merge queue branch\n`); - const octokit = new ProxifiedClient(); - const result = await octokit.request( - `GET /repos/${owner}/${repo}/pulls/${pull_number}`, - { owner, repo, pull_number: +pull_number }, - ); - return result.data.head.ref; -} - /** * Get first existing commit */ From 02cff2237442e7731532a9cb4df851e7ac4a34af Mon Sep 17 00:00:00 2001 From: Paulo Viana Date: Thu, 14 Mar 2024 00:05:51 -0400 Subject: [PATCH 2/4] Update test-integration.yml --- .github/workflows/test-integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-integration.yml b/.github/workflows/test-integration.yml index 602bf8b..4a83086 100644 --- a/.github/workflows/test-integration.yml +++ b/.github/workflows/test-integration.yml @@ -17,7 +17,7 @@ jobs: name: Test workflow integration strategy: matrix: - runs-on: [ubuntu-latest, macos-latest, windows-latest] + runs-on: [ubuntu-latest] fail-fast: false uses: ./.github/workflows/integration-test-workflow.yml with: From 69f108d1fb289174336aa311e51580b91f123afd Mon Sep 17 00:00:00 2001 From: Paulo Viana Date: Thu, 14 Mar 2024 00:06:36 -0400 Subject: [PATCH 3/4] Update test-integration.yml --- .github/workflows/test-integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-integration.yml b/.github/workflows/test-integration.yml index 4a83086..602bf8b 100644 --- a/.github/workflows/test-integration.yml +++ b/.github/workflows/test-integration.yml @@ -17,7 +17,7 @@ jobs: name: Test workflow integration strategy: matrix: - runs-on: [ubuntu-latest] + runs-on: [ubuntu-latest, macos-latest, windows-latest] fail-fast: false uses: ./.github/workflows/integration-test-workflow.yml with: From 419980f39c2d4da32e72b1fc869332f03ea8ca8b Mon Sep 17 00:00:00 2001 From: Jake Hiller Date: Wed, 8 Jan 2025 14:18:56 -0500 Subject: [PATCH 4/4] build --- dist/index.js | 51 ++++++++----------------------------- find-successful-workflow.ts | 17 ++++++++++--- 2 files changed, 23 insertions(+), 45 deletions(-) diff --git a/dist/index.js b/dist/index.js index 3690d71..6ab1ed6 100644 --- a/dist/index.js +++ b/dist/index.js @@ -64895,18 +64895,16 @@ let BASE_SHA; encoding: 'utf-8', }); const HEAD_SHA = headResult.stdout; - if ((['pull_request', 'pull_request_target'].includes(eventName) && - !github.context.payload.pull_request.merged) || - eventName == 'merge_group') { - try { - const mergeBaseRef = yield findMergeBaseRef(); - const baseResult = (0, child_process_1.spawnSync)('git', ['merge-base', `origin/${mainBranchName}`, mergeBaseRef], { encoding: 'utf-8' }); - BASE_SHA = baseResult.stdout; - } - catch (e) { - core.setFailed(e.message); - return; - } + if (['pull_request', 'pull_request_target'].includes(eventName) && + !github.context.payload.pull_request.merged) { + const baseResult = (0, child_process_1.spawnSync)('git', ['merge-base', `origin/${mainBranchName}`, 'HEAD'], { encoding: 'utf-8' }); + BASE_SHA = baseResult.stdout; + } + else if (eventName == 'merge_group') { + const baseResult = (0, child_process_1.spawnSync)('git', ['rev-parse', 'HEAD^1'], { + encoding: 'utf-8', + }); + BASE_SHA = baseResult.stdout; } else { try { @@ -65016,35 +65014,6 @@ function findSuccessfulCommit(workflow_id, run_id, owner, repo, branch, lastSucc return yield findExistingCommit(octokit, branch, shas); }); } -function findMergeBaseRef() { - return __awaiter(this, void 0, void 0, function* () { - if (eventName == 'merge_group') { - const mergeQueueBranch = yield findMergeQueueBranch(); - return `origin/${mergeQueueBranch}`; - } - else { - return 'HEAD'; - } - }); -} -function findMergeQueuePr() { - const { head_ref, base_sha } = github.context.payload.merge_group; - const result = new RegExp(`^refs/heads/gh-readonly-queue/${mainBranchName}/pr-(\\d+)-${base_sha}$`).exec(head_ref); - return result ? result.at(1) : undefined; -} -function findMergeQueueBranch() { - return __awaiter(this, void 0, void 0, function* () { - const pull_number = findMergeQueuePr(); - if (!pull_number) { - throw new Error('Failed to determine PR number'); - } - process.stdout.write('\n'); - process.stdout.write(`Found PR #${pull_number} from merge queue branch\n`); - const octokit = new ProxifiedClient(); - const result = yield octokit.request(`GET /repos/${owner}/${repo}/pulls/${pull_number}`, { owner, repo, pull_number: +pull_number }); - return result.data.head.ref; - }); -} /** * Get first existing commit */ diff --git a/find-successful-workflow.ts b/find-successful-workflow.ts index 2dc0ee5..fdfde6e 100644 --- a/find-successful-workflow.ts +++ b/find-successful-workflow.ts @@ -40,11 +40,20 @@ let BASE_SHA: string; }); const HEAD_SHA = headResult.stdout; - if (['pull_request', 'pull_request_target'].includes(eventName) && !github.context.payload.pull_request.merged) { - const baseResult = spawnSync('git', ['merge-base', `origin/${mainBranchName}`, 'HEAD'], { encoding: 'utf-8' }); + if ( + ['pull_request', 'pull_request_target'].includes(eventName) && + !github.context.payload.pull_request.merged + ) { + const baseResult = spawnSync( + 'git', + ['merge-base', `origin/${mainBranchName}`, 'HEAD'], + { encoding: 'utf-8' }, + ); BASE_SHA = baseResult.stdout; - } else if (eventName == "merge_group") { - const baseResult = spawnSync('git', ['rev-parse', 'HEAD^1'], { encoding: 'utf-8' }); + } else if (eventName == 'merge_group') { + const baseResult = spawnSync('git', ['rev-parse', 'HEAD^1'], { + encoding: 'utf-8', + }); BASE_SHA = baseResult.stdout; } else { try {