Skip to content

Commit b1967b1

Browse files
authored
ref: GHA provider to use @actions/github (#152)
Update GHA provider utils to use @actions/github to access the correct commit SHA's.
1 parent 090c7ba commit b1967b1

File tree

5 files changed

+288
-198
lines changed

5 files changed

+288
-198
lines changed

.changeset/warm-moles-float.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
"@codecov/bundler-plugin-core": patch
3+
"@codecov/solidstart-plugin": patch
4+
"@codecov/remix-vite-plugin": patch
5+
"@codecov/sveltekit-plugin": patch
6+
"@codecov/webpack-plugin": patch
7+
"@codecov/rollup-plugin": patch
8+
"@codecov/nuxt-plugin": patch
9+
"@codecov/vite-plugin": patch
10+
---
11+
12+
Swap over to using @actions/github to grab head and base commit sha's in GHA

packages/bundler-plugin-core/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,14 @@
3939
"generate:typedoc": "typedoc --options ./typedoc.json"
4040
},
4141
"dependencies": {
42+
"@actions/github": "^6.0.0",
4243
"chalk": "4.1.2",
4344
"semver": "^7.5.4",
4445
"unplugin": "^1.10.1",
4546
"zod": "^3.22.4"
4647
},
4748
"devDependencies": {
49+
"@octokit/webhooks-definitions": "^3.67.3",
4850
"@types/node": "^20.11.15",
4951
"@types/semver": "^7.5.6",
5052
"@vitest/coverage-v8": "^1.5.0",

packages/bundler-plugin-core/src/utils/providers/GitHubActions.ts

Lines changed: 10 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as GitHub from "@actions/github";
12
import { jsonSchema } from "../../schemas.ts";
23
import {
34
type ProviderEnvs,
@@ -6,7 +7,7 @@ import {
67
} from "../../types.ts";
78
import { type Output } from "../Output.ts";
89
import { debug } from "../logging.ts";
9-
import { runExternalProgram } from "../runExternalProgram.ts";
10+
import { type PullRequestEvent } from "@octokit/webhooks-definitions/schema";
1011

1112
export function detect(envs: ProviderEnvs): boolean {
1213
return Boolean(envs?.GITHUB_ACTIONS);
@@ -136,30 +137,12 @@ function _getSHA(
136137
return args.sha;
137138
}
138139

139-
const pr = _getPR(inputs);
140+
const context = GitHub.context;
140141

141142
let commit = envs?.GITHUB_SHA;
142-
if (pr) {
143-
const mergeCommitRegex = /^[a-z0-9]{40} [a-z0-9]{40}$/;
144-
const mergeCommitMessage = runExternalProgram("git", [
145-
"show",
146-
"--no-patch",
147-
"--format=%P",
148-
]);
149-
150-
debug(`Merge commit message: ${mergeCommitMessage}`, {
151-
enabled: output.debug,
152-
});
153-
154-
if (mergeCommitRegex.exec(mergeCommitMessage)) {
155-
const splitMergeCommit = mergeCommitMessage.split(" ");
156-
157-
debug(`Split commit message: ${splitMergeCommit}`, {
158-
enabled: output.debug,
159-
});
160-
161-
commit = splitMergeCommit[1];
162-
}
143+
if (["pull_request", " pull_request_target"].includes(context.eventName)) {
144+
const payload = context.payload as PullRequestEvent;
145+
commit = payload.pull_request.head.sha;
163146
}
164147

165148
debug(`Using commit: ${commit ?? null}`, { enabled: output.debug });
@@ -178,28 +161,10 @@ function _getCompareSHA(
178161
}
179162

180163
let compareSha = null;
181-
const pr = _getPR(inputs);
182-
if (pr) {
183-
const mergeCommitRegex = /^[a-z0-9]{40} [a-z0-9]{40}$/;
184-
const mergeCommitMessage = runExternalProgram("git", [
185-
"show",
186-
"--no-patch",
187-
"--format=%P",
188-
]);
189-
190-
debug(`Merge commit message: ${mergeCommitMessage}`, {
191-
enabled: output.debug,
192-
});
193-
194-
if (mergeCommitRegex.exec(mergeCommitMessage)) {
195-
const splitMergeCommit = mergeCommitMessage.split(" ");
196-
197-
debug(`Split commit message: ${splitMergeCommit}`, {
198-
enabled: output.debug,
199-
});
200-
201-
compareSha = splitMergeCommit?.[0] ? splitMergeCommit[0] : null;
202-
}
164+
const context = GitHub.context;
165+
if (["pull_request", " pull_request_target"].includes(context.eventName)) {
166+
const payload = context.payload as PullRequestEvent;
167+
compareSha = payload.pull_request.base.sha;
203168
}
204169

205170
debug(`Using compareSha: ${compareSha ?? null}`, { enabled: output.debug });

0 commit comments

Comments
 (0)