diff --git a/packages/bundler-plugin-core/package.json b/packages/bundler-plugin-core/package.json index 8e62d87d..bbd1b9f8 100644 --- a/packages/bundler-plugin-core/package.json +++ b/packages/bundler-plugin-core/package.json @@ -47,7 +47,7 @@ "zod": "^3.22.4" }, "devDependencies": { - "@octokit/webhooks-definitions": "^3.67.3", + "@octokit/webhooks-types": "^7.6.1", "@sentry/core": "^8.42.0", "@types/node": "^20.11.15", "@types/semver": "^7.5.6", diff --git a/packages/bundler-plugin-core/src/utils/providers/GitHubActions.ts b/packages/bundler-plugin-core/src/utils/providers/GitHubActions.ts index feec65ed..5a57332f 100644 --- a/packages/bundler-plugin-core/src/utils/providers/GitHubActions.ts +++ b/packages/bundler-plugin-core/src/utils/providers/GitHubActions.ts @@ -7,7 +7,10 @@ import { } from "../../types.ts"; import { type Output } from "../Output.ts"; import { debug } from "../logging.ts"; -import { type PullRequestEvent } from "@octokit/webhooks-definitions/schema"; +import { + type PullRequestEvent, + type MergeGroupEvent, +} from "@octokit/webhooks-types"; export function detect(envs: ProviderEnvs): boolean { return Boolean(envs?.GITHUB_ACTIONS); @@ -184,9 +187,12 @@ function _getSHA( const context = GitHub.context; let commit = envs?.GITHUB_SHA; - if (["pull_request", " pull_request_target"].includes(context.eventName)) { + if (["pull_request", "pull_request_target"].includes(context.eventName)) { const payload = context.payload as PullRequestEvent; commit = payload.pull_request.head.sha; + } else if ("merge_group" === context.eventName) { + const payload = context.payload as MergeGroupEvent; + commit = payload.merge_group.head_sha; } debug(`Using commit: ${commit ?? null}`, { enabled: output.debug }); @@ -205,9 +211,12 @@ function _getCompareSHA( let compareSha = null; const context = GitHub.context; - if (["pull_request", " pull_request_target"].includes(context.eventName)) { + if (["pull_request", "pull_request_target"].includes(context.eventName)) { const payload = context.payload as PullRequestEvent; compareSha = payload.pull_request.base.sha; + } else if ("merge_group" === context.eventName) { + const payload = context.payload as MergeGroupEvent; + compareSha = payload.merge_group.base_sha; } debug(`Using compareSha: ${compareSha}`, { enabled: output.debug }); diff --git a/packages/bundler-plugin-core/src/utils/providers/__tests__/GitHubActions.test.ts b/packages/bundler-plugin-core/src/utils/providers/__tests__/GitHubActions.test.ts index 98216944..2fe3efd9 100644 --- a/packages/bundler-plugin-core/src/utils/providers/__tests__/GitHubActions.test.ts +++ b/packages/bundler-plugin-core/src/utils/providers/__tests__/GitHubActions.test.ts @@ -54,7 +54,7 @@ describe("GitHub Actions Params", () => { headLabel = "", }: { data?: object; - eventName?: "" | "pull_request" | "pull_request_target"; + eventName?: "" | "pull_request" | "pull_request_target" | "merge_group"; baseLabel?: string; headLabel?: string; } = { data: {}, eventName: "" }, @@ -63,22 +63,38 @@ describe("GitHub Actions Params", () => { mocks.baseLabel.mockReturnValue(baseLabel); mocks.headLabel.mockReturnValue(headLabel); - vi.mocked(GitHub).context = { - eventName, - payload: { - // @ts-expect-error - forcing the payload to be a PullRequestEvent - pull_request: { - head: { - sha: "test-head-sha", - label: headLabel, + // not sure if empty string is correct here but for parity with previous tests + // TODO: verify that empty string belongs here, from a glance it seems PushEvent does not + // include a pull_request key + if (["pull_request", "pull_request_target", ""].includes(eventName)) { + vi.mocked(GitHub).context = { + eventName, + payload: { + // @ts-expect-error - forcing the payload to be a PullRequestEvent + pull_request: { + head: { + sha: "test-head-sha", + label: headLabel, + }, + base: { + sha: "test-base-sha", + label: baseLabel, + }, }, - base: { - sha: "test-base-sha", - label: baseLabel, + }, + }; + } else if (eventName === "merge_group") { + // @ts-expect-error - forcing the payload to be a MergeGroupEvent + vi.mocked(GitHub).context = { + eventName, + payload: { + merge_group: { + base_sha: "test-base-sha", + head_sha: "test-head-sha", }, }, - }, - }; + }; + } server.use( http.get( @@ -324,7 +340,66 @@ describe("GitHub Actions Params", () => { build: "2", buildURL: "https://github.com/testOrg/testRepo/actions/runs/2", commit: "test-head-sha", - compareSha: null, + compareSha: "test-base-sha", + job: "testWorkflow", + pr: "1", + service: "github-actions", + slug: "testOrg/testRepo", + }; + expect(params).toMatchObject(expected); + }); + + it("gets the correct branch from a merge group CI run", async () => { + setup({ + data: { + jobs: [ + { + id: 1, + name: "fakeJob", + html_url: "https://fake.com", + }, + ], + }, + eventName: "merge_group", + baseLabel: "codecov:baseBranch", + headLabel: "testOrg:headBranch", + }); + + const inputs: ProviderUtilInputs = { + args: { ...createEmptyArgs() }, + envs: { + GITHUB_ACTIONS: "true", + GITHUB_HEAD_REF: "branch", + GITHUB_JOB: "testJob", + GITHUB_REF: "refs/pull/1/merge", + GITHUB_REPOSITORY: "testOrg/testRepo", + GITHUB_RUN_ID: "2", + GITHUB_SERVER_URL: "https://github.com", + GITHUB_SHA: "test-head-sha", + GITHUB_WORKFLOW: "testWorkflow", + }, + }; + + const output = new Output( + { + apiUrl: "http://localhost", + bundleName: "GHA-test", + debug: false, + dryRun: true, + enableBundleAnalysis: true, + retryCount: 0, + telemetry: false, + }, + { metaFramework: "vite" }, + ); + const params = await GitHubActions.getServiceParams(inputs, output); + + const expected: ProviderServiceParams = { + branch: "branch", + build: "2", + buildURL: "https://github.com/testOrg/testRepo/actions/runs/2", + commit: "test-head-sha", + compareSha: "test-base-sha", job: "testWorkflow", pr: "1", service: "github-actions", @@ -383,7 +458,7 @@ describe("GitHub Actions Params", () => { build: "2", buildURL: "https://github.com/testOrg/testRepo/actions/runs/2", commit: "test-head-sha", - compareSha: null, + compareSha: "test-base-sha", job: "testWorkflow", pr: "1", service: "github-actions", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1bcfad95..39b6e451 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -339,7 +339,7 @@ importers: version: 8.56.0 eslint-import-resolver-typescript: specifier: ^3.6.1 - version: 3.6.1(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.4.5))(eslint-plugin-import@2.29.1)(eslint@8.56.0) + version: 3.6.1(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.4.5))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.4.5))(eslint@8.56.0))(eslint@8.56.0) eslint-plugin-import: specifier: ^2.28.1 version: 2.29.1(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.4.5))(eslint-import-resolver-typescript@3.6.1)(eslint@8.56.0) @@ -831,7 +831,7 @@ importers: version: 8.56.0 eslint-import-resolver-typescript: specifier: ^3.6.1 - version: 3.6.1(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.4.5))(eslint-plugin-import@2.29.1)(eslint@8.56.0) + version: 3.6.1(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.4.5))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.4.5))(eslint@8.56.0))(eslint@8.56.0) eslint-plugin-import: specifier: ^2.28.1 version: 2.29.1(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.4.5))(eslint-import-resolver-typescript@3.6.1)(eslint@8.56.0) @@ -1027,9 +1027,9 @@ importers: specifier: ^3.22.4 version: 3.22.4 devDependencies: - '@octokit/webhooks-definitions': - specifier: ^3.67.3 - version: 3.67.3 + '@octokit/webhooks-types': + specifier: ^7.6.1 + version: 7.6.1 '@sentry/core': specifier: ^8.42.0 version: 8.42.0 @@ -1120,7 +1120,7 @@ importers: version: 2.1.9(@types/node@20.12.12)(msw@2.7.0(@types/node@20.12.12)(typescript@5.4.5))(terser@5.27.0) webpack: specifier: ^5.96.1 - version: 5.96.1 + version: 5.96.1(webpack-cli@5.1.4) packages/nuxt-plugin: dependencies: @@ -1457,7 +1457,7 @@ importers: version: 2.1.9(@types/node@20.10.0)(msw@2.7.0(@types/node@20.10.0)(typescript@5.3.3))(terser@5.27.0) webpack: specifier: ^5.96.1 - version: 5.96.1 + version: 5.96.1(webpack-cli@5.1.4) packages: @@ -3522,9 +3522,8 @@ packages: '@octokit/types@13.5.0': resolution: {integrity: sha512-HdqWTf5Z3qwDVlzCrP8UJquMwunpDiMPt5er+QjGzL4hqr/vBVY/MauQgS1xWxCDT1oMx1EULyqxncdCY/NVSQ==} - '@octokit/webhooks-definitions@3.67.3': - resolution: {integrity: sha512-do4Z1r2OVhuI0ihJhQ8Hg+yPWnBYEBNuFNCrvtPKoYT1w81jD7pBXgGe86lYuuNirkDHb0Nxt+zt4O5GiFJfgA==} - deprecated: Use @octokit/webhooks-types, @octokit/webhooks-schemas, or @octokit/webhooks-examples instead. See https://github.com/octokit/webhooks/issues/447 + '@octokit/webhooks-types@7.6.1': + resolution: {integrity: sha512-S8u2cJzklBC0FgTwWVLaM8tMrDuDMVE4xiTK4EYXM9GntyvrdbSoxqDQa+Fh57CCNApyIpyeqPhhFEmHPfrXgw==} '@open-draft/deferred-promise@2.2.0': resolution: {integrity: sha512-CecwLWx3rhxVQF6V4bAgPS5t+So2sTbPgAzafKkVizyi7tlwpcFpdFqq+wqF2OwNBmqFuu6tOyouTuxgpMfzmA==} @@ -14182,7 +14181,7 @@ snapshots: dependencies: '@octokit/openapi-types': 22.2.0 - '@octokit/webhooks-definitions@3.67.3': {} + '@octokit/webhooks-types@7.6.1': {} '@open-draft/deferred-promise@2.2.0': {} @@ -15638,7 +15637,7 @@ snapshots: dependencies: '@types/node': 20.12.12 tapable: 2.2.1 - webpack: 5.96.1 + webpack: 5.96.1(webpack-cli@5.1.4) transitivePeerDependencies: - '@swc/core' - esbuild @@ -16729,17 +16728,17 @@ snapshots: '@webassemblyjs/ast': 1.12.1 '@xtuc/long': 4.2.2 - '@webpack-cli/configtest@2.1.1(webpack-cli@5.1.4(webpack@5.96.1))(webpack@5.96.1(webpack-cli@5.1.4))': + '@webpack-cli/configtest@2.1.1(webpack-cli@5.1.4)(webpack@5.96.1)': dependencies: webpack: 5.96.1(webpack-cli@5.1.4) webpack-cli: 5.1.4(webpack@5.96.1) - '@webpack-cli/info@2.0.2(webpack-cli@5.1.4(webpack@5.96.1))(webpack@5.96.1(webpack-cli@5.1.4))': + '@webpack-cli/info@2.0.2(webpack-cli@5.1.4)(webpack@5.96.1)': dependencies: webpack: 5.96.1(webpack-cli@5.1.4) webpack-cli: 5.1.4(webpack@5.96.1) - '@webpack-cli/serve@2.0.5(webpack-cli@5.1.4(webpack@5.96.1))(webpack@5.96.1(webpack-cli@5.1.4))': + '@webpack-cli/serve@2.0.5(webpack-cli@5.1.4)(webpack@5.96.1)': dependencies: webpack: 5.96.1(webpack-cli@5.1.4) webpack-cli: 5.1.4(webpack@5.96.1) @@ -18602,24 +18601,7 @@ snapshots: debug: 4.3.4 enhanced-resolve: 5.16.0 eslint: 8.56.0 - eslint-module-utils: 2.8.0(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.4.5))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.4.5))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.4.5))(eslint@8.56.0))(eslint@8.56.0))(eslint@8.56.0) - eslint-plugin-import: 2.29.1(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.4.5))(eslint-import-resolver-typescript@3.6.1)(eslint@8.56.0) - fast-glob: 3.3.2 - get-tsconfig: 4.7.2 - is-core-module: 2.13.1 - is-glob: 4.0.3 - transitivePeerDependencies: - - '@typescript-eslint/parser' - - eslint-import-resolver-node - - eslint-import-resolver-webpack - - supports-color - - eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.4.5))(eslint-plugin-import@2.29.1)(eslint@8.56.0): - dependencies: - debug: 4.3.4 - enhanced-resolve: 5.16.0 - eslint: 8.56.0 - eslint-module-utils: 2.8.0(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.4.5))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.4.5))(eslint-plugin-import@2.29.1)(eslint@8.56.0))(eslint@8.56.0) + eslint-module-utils: 2.8.0(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.4.5))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1)(eslint@8.56.0) eslint-plugin-import: 2.29.1(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.4.5))(eslint-import-resolver-typescript@3.6.1)(eslint@8.56.0) fast-glob: 3.3.2 get-tsconfig: 4.7.2 @@ -18641,7 +18623,7 @@ snapshots: transitivePeerDependencies: - supports-color - eslint-module-utils@2.8.0(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.4.5))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.4.5))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.4.5))(eslint@8.56.0))(eslint@8.56.0))(eslint@8.56.0): + eslint-module-utils@2.8.0(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.4.5))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1)(eslint@8.56.0): dependencies: debug: 3.2.7 optionalDependencies: @@ -18652,17 +18634,6 @@ snapshots: transitivePeerDependencies: - supports-color - eslint-module-utils@2.8.0(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.4.5))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.4.5))(eslint-plugin-import@2.29.1)(eslint@8.56.0))(eslint@8.56.0): - dependencies: - debug: 3.2.7 - optionalDependencies: - '@typescript-eslint/parser': 6.20.0(eslint@8.56.0)(typescript@5.4.5) - eslint: 8.56.0 - eslint-import-resolver-node: 0.3.9 - eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.4.5))(eslint-plugin-import@2.29.1)(eslint@8.56.0) - transitivePeerDependencies: - - supports-color - eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.3.3))(eslint@8.56.0): dependencies: array-includes: 3.1.7 @@ -18700,7 +18671,7 @@ snapshots: doctrine: 2.1.0 eslint: 8.56.0 eslint-import-resolver-node: 0.3.9 - eslint-module-utils: 2.8.0(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.4.5))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.4.5))(eslint-plugin-import@2.29.1)(eslint@8.56.0))(eslint@8.56.0) + eslint-module-utils: 2.8.0(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.4.5))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1)(eslint@8.56.0) hasown: 2.0.0 is-core-module: 2.13.1 is-glob: 4.0.3 @@ -24426,15 +24397,6 @@ snapshots: solid-js: 1.8.19 solid-use: 0.8.0(solid-js@1.8.19) - terser-webpack-plugin@5.3.10(webpack@5.96.1(webpack-cli@5.1.4)): - dependencies: - '@jridgewell/trace-mapping': 0.3.25 - jest-worker: 27.5.1 - schema-utils: 3.3.0 - serialize-javascript: 6.0.1 - terser: 5.27.0 - webpack: 5.96.1(webpack-cli@5.1.4) - terser-webpack-plugin@5.3.10(webpack@5.96.1): dependencies: '@jridgewell/trace-mapping': 0.3.25 @@ -24442,7 +24404,7 @@ snapshots: schema-utils: 3.3.0 serialize-javascript: 6.0.1 terser: 5.27.0 - webpack: 5.96.1 + webpack: 5.96.1(webpack-cli@5.1.4) terser@5.27.0: dependencies: @@ -26277,9 +26239,9 @@ snapshots: webpack-cli@5.1.4(webpack@5.96.1): dependencies: '@discoveryjs/json-ext': 0.5.7 - '@webpack-cli/configtest': 2.1.1(webpack-cli@5.1.4(webpack@5.96.1))(webpack@5.96.1(webpack-cli@5.1.4)) - '@webpack-cli/info': 2.0.2(webpack-cli@5.1.4(webpack@5.96.1))(webpack@5.96.1(webpack-cli@5.1.4)) - '@webpack-cli/serve': 2.0.5(webpack-cli@5.1.4(webpack@5.96.1))(webpack@5.96.1(webpack-cli@5.1.4)) + '@webpack-cli/configtest': 2.1.1(webpack-cli@5.1.4)(webpack@5.96.1) + '@webpack-cli/info': 2.0.2(webpack-cli@5.1.4)(webpack@5.96.1) + '@webpack-cli/serve': 2.0.5(webpack-cli@5.1.4)(webpack@5.96.1) colorette: 2.0.20 commander: 10.0.1 cross-spawn: 7.0.3 @@ -26334,36 +26296,6 @@ snapshots: - esbuild - uglify-js - webpack@5.96.1: - dependencies: - '@types/eslint-scope': 3.7.7 - '@types/estree': 1.0.6 - '@webassemblyjs/ast': 1.12.1 - '@webassemblyjs/wasm-edit': 1.12.1 - '@webassemblyjs/wasm-parser': 1.12.1 - acorn: 8.14.0 - browserslist: 4.24.2 - chrome-trace-event: 1.0.3 - enhanced-resolve: 5.17.1 - es-module-lexer: 1.3.1 - eslint-scope: 5.1.1 - events: 3.3.0 - glob-to-regexp: 0.4.1 - graceful-fs: 4.2.11 - json-parse-even-better-errors: 2.3.1 - loader-runner: 4.3.0 - mime-types: 2.1.35 - neo-async: 2.6.2 - schema-utils: 3.3.0 - tapable: 2.2.1 - terser-webpack-plugin: 5.3.10(webpack@5.96.1) - watchpack: 2.4.1 - webpack-sources: 3.2.3 - transitivePeerDependencies: - - '@swc/core' - - esbuild - - uglify-js - webpack@5.96.1(webpack-cli@5.1.4): dependencies: '@types/eslint-scope': 3.7.7 @@ -26386,7 +26318,7 @@ snapshots: neo-async: 2.6.2 schema-utils: 3.3.0 tapable: 2.2.1 - terser-webpack-plugin: 5.3.10(webpack@5.96.1(webpack-cli@5.1.4)) + terser-webpack-plugin: 5.3.10(webpack@5.96.1) watchpack: 2.4.1 webpack-sources: 3.2.3 optionalDependencies: