Skip to content

Commit 42bf08e

Browse files
authored
feat: Grab compare SHA for GH pre-merge commits (#147)
Add in functionality to grab the correct base comparison SHA.
1 parent 2df4d02 commit 42bf08e

File tree

13 files changed

+167
-88
lines changed

13 files changed

+167
-88
lines changed

.github/workflows/ci.yml

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ jobs:
2222
fetch-depth: 0
2323

2424
- name: Setup node
25-
uses: actions/setup-node@v3
25+
uses: actions/setup-node@v4
2626
with:
2727
node-version: 20
2828

2929
- name: Install pnpm
30-
uses: pnpm/action-setup@v2
30+
uses: pnpm/action-setup@v4
3131
with:
3232
version: 9
3333
run_install: false
@@ -39,7 +39,7 @@ jobs:
3939
4040
- name: Cache node_modules
4141
id: cache-node-modules
42-
uses: actions/cache@v3
42+
uses: actions/cache@v4
4343
env:
4444
cache-name: cache-codecov-js-bundle-plugin-node-modules
4545
with:
@@ -62,12 +62,12 @@ jobs:
6262
fetch-depth: 0
6363

6464
- name: Setup node
65-
uses: actions/setup-node@v3
65+
uses: actions/setup-node@v4
6666
with:
6767
node-version: 20
6868

6969
- name: Install pnpm
70-
uses: pnpm/action-setup@v2
70+
uses: pnpm/action-setup@v4
7171
with:
7272
version: 9
7373
run_install: false
@@ -79,7 +79,7 @@ jobs:
7979
8080
- name: Cache node_modules
8181
id: cache-node-modules
82-
uses: actions/cache@v3
82+
uses: actions/cache@v4
8383
env:
8484
cache-name: cache-codecov-js-bundle-plugin-node-modules
8585
with:
@@ -108,12 +108,12 @@ jobs:
108108
fetch-depth: 0
109109

110110
- name: Setup node
111-
uses: actions/setup-node@v3
111+
uses: actions/setup-node@v4
112112
with:
113113
node-version: 20
114114

115115
- name: Install pnpm
116-
uses: pnpm/action-setup@v2
116+
uses: pnpm/action-setup@v4
117117
with:
118118
version: 9
119119
run_install: false
@@ -125,7 +125,7 @@ jobs:
125125
126126
- name: Cache node_modules
127127
id: cache-node-modules
128-
uses: actions/cache@v3
128+
uses: actions/cache@v4
129129
env:
130130
cache-name: cache-codecov-js-bundle-plugin-node-modules
131131
with:
@@ -154,12 +154,12 @@ jobs:
154154
fetch-depth: 0
155155

156156
- name: Setup node
157-
uses: actions/setup-node@v3
157+
uses: actions/setup-node@v4
158158
with:
159159
node-version: 20
160160

161161
- name: Install pnpm
162-
uses: pnpm/action-setup@v2
162+
uses: pnpm/action-setup@v4
163163
with:
164164
version: 9
165165
run_install: false
@@ -171,7 +171,7 @@ jobs:
171171
172172
- name: Cache node_modules
173173
id: cache-node-modules
174-
uses: actions/cache@v3
174+
uses: actions/cache@v4
175175
env:
176176
cache-name: cache-codecov-js-bundle-plugin-node-modules
177177
with:
@@ -237,12 +237,12 @@ jobs:
237237
fetch-depth: 0
238238

239239
- name: Setup node
240-
uses: actions/setup-node@v3
240+
uses: actions/setup-node@v4
241241
with:
242242
node-version: ${{ matrix.node-version }}
243243

244244
- name: Install pnpm
245-
uses: pnpm/action-setup@v2
245+
uses: pnpm/action-setup@v4
246246
with:
247247
version: 9
248248
run_install: false
@@ -254,7 +254,7 @@ jobs:
254254
255255
- name: Cache node_modules
256256
id: cache-node-modules
257-
uses: actions/cache@v3
257+
uses: actions/cache@v4
258258
env:
259259
cache-name: cache-codecov-js-bundle-plugin-node-modules
260260
with:
@@ -288,12 +288,12 @@ jobs:
288288
fetch-depth: 0
289289

290290
- name: Setup node
291-
uses: actions/setup-node@v3
291+
uses: actions/setup-node@v4
292292
with:
293293
node-version: 20
294294

295295
- name: Install pnpm
296-
uses: pnpm/action-setup@v2
296+
uses: pnpm/action-setup@v4
297297
with:
298298
version: 9
299299
run_install: false
@@ -305,7 +305,7 @@ jobs:
305305
306306
- name: Cache node_modules
307307
id: cache-node-modules
308-
uses: actions/cache@v3
308+
uses: actions/cache@v4
309309
env:
310310
cache-name: cache-codecov-js-bundle-plugin-node-modules
311311
with:
@@ -326,6 +326,8 @@ jobs:
326326
- name: Build ${{ matrix.example }} app for production
327327
working-directory: ./examples/${{ matrix.example }}
328328
env:
329+
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
330+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
329331
NEXT_UPLOAD_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }}
330332
NEXT_API_URL: ${{ secrets.CODECOV_API_URL }}
331333
NUXT_UPLOAD_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }}
@@ -358,12 +360,12 @@ jobs:
358360
fetch-depth: 0
359361

360362
- name: Setup node
361-
uses: actions/setup-node@v3
363+
uses: actions/setup-node@v4
362364
with:
363365
node-version: 20
364366

365367
- name: Install pnpm
366-
uses: pnpm/action-setup@v2
368+
uses: pnpm/action-setup@v4
367369
with:
368370
version: 9
369371
run_install: false
@@ -375,7 +377,7 @@ jobs:
375377
376378
- name: Cache node_modules
377379
id: cache-node-modules
378-
uses: actions/cache@v3
380+
uses: actions/cache@v4
379381
env:
380382
cache-name: cache-codecov-js-bundle-plugin-node-modules
381383
with:
@@ -396,6 +398,8 @@ jobs:
396398
- name: Build ${{ matrix.example }} app for staging
397399
working-directory: ./examples/${{ matrix.example }}
398400
env:
401+
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
402+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
399403
NEXT_UPLOAD_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN_STAGING }}
400404
NEXT_API_URL: ${{ secrets.CODECOV_STAGING_API_URL }}
401405
NUXT_UPLOAD_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }}
@@ -436,12 +440,12 @@ jobs:
436440
fetch-depth: 0
437441

438442
- name: Setup node
439-
uses: actions/setup-node@v3
443+
uses: actions/setup-node@v4
440444
with:
441445
node-version: 20
442446

443447
- name: Install pnpm
444-
uses: pnpm/action-setup@v2
448+
uses: pnpm/action-setup@v4
445449
with:
446450
version: 9
447451
run_install: false
@@ -453,7 +457,7 @@ jobs:
453457
454458
- name: Cache node_modules
455459
id: cache-node-modules
456-
uses: actions/cache@v3
460+
uses: actions/cache@v4
457461
env:
458462
cache-name: cache-codecov-js-bundle-plugin-node-modules
459463
with:
@@ -502,12 +506,12 @@ jobs:
502506
fetch-depth: 0
503507

504508
- name: Setup node
505-
uses: actions/setup-node@v3
509+
uses: actions/setup-node@v4
506510
with:
507511
node-version: 20
508512

509513
- name: Install pnpm
510-
uses: pnpm/action-setup@v2
514+
uses: pnpm/action-setup@v4
511515
with:
512516
version: 9
513517
run_install: false
@@ -519,7 +523,7 @@ jobs:
519523
520524
- name: Cache node_modules
521525
id: cache-node-modules
522-
uses: actions/cache@v3
526+
uses: actions/cache@v4
523527
env:
524528
cache-name: cache-codecov-js-bundle-plugin-node-modules
525529
with:

examples/next-js/next.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const nextConfig = {
99
bundleName: "@codecov/example-next-app",
1010
uploadToken: process.env.NEXT_UPLOAD_TOKEN,
1111
apiUrl: process.env.NEXT_API_URL,
12+
debug: true,
1213
}),
1314
);
1415

examples/nuxt/nuxt.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export default defineNuxtConfig({
99
bundleName: "@codecov/example-nuxt-app",
1010
uploadToken: process.env.NUXT_UPLOAD_TOKEN,
1111
apiUrl: process.env.NUXT_API_URL,
12+
debug: true,
1213
},
1314
],
1415
],

examples/remix/vite.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export default defineConfig({
1818
bundleName: "@codecov/example-remix-app",
1919
uploadToken: process.env.REMIX_UPLOAD_TOKEN,
2020
apiUrl: process.env.REMIX_API_URL,
21+
debug: true,
2122
}),
2223
],
2324
});

examples/rollup/rollup.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ export default defineConfig({
2222
bundleName: "@codecov/example-rollup-app",
2323
apiUrl: process.env.ROLLUP_API_URL,
2424
uploadToken: process.env.ROLLUP_UPLOAD_TOKEN,
25+
debug: true,
26+
uploadOverrides: {
27+
sha: process.env.HEAD_SHA,
28+
compareSha: process.env.BASE_SHA,
29+
},
2530
}),
2631
],
2732
});

examples/sveltekit/vite.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default defineConfig({
1010
bundleName: "@codecov/example-sveltekit-app",
1111
uploadToken: process.env.SVELTEKIT_UPLOAD_TOKEN,
1212
apiUrl: process.env.SVELTEKIT_API_URL,
13+
debug: true,
1314
}),
1415
],
1516
});

examples/vite/vite.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export default defineConfig({
1919
bundleName: "@codecov/example-vite-app",
2020
uploadToken: process.env.VITE_UPLOAD_TOKEN,
2121
apiUrl: process.env.VITE_API_URL,
22+
debug: true,
2223
}),
2324
],
2425
});

examples/webpack/webpack.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module.exports = {
1414
bundleName: "@codecov/example-webpack-app",
1515
uploadToken: process.env.WEBPACK_UPLOAD_TOKEN,
1616
apiUrl: process.env.WEBPACK_API_URL,
17+
debug: true,
1718
}),
1819
],
1920
};

packages/bundler-plugin-core/src/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ export interface UploadOverrides {
123123
branch?: string;
124124
/** Specify the build number manually. */
125125
build?: string;
126+
/** Specify the compare SHA manually. **GH Actions only**. */
127+
compareSha?: string;
126128
/** Specify the pull request number manually. */
127129
pr?: string;
128130
/** Specify the commit SHA manually. */
@@ -153,6 +155,8 @@ export interface ProviderServiceParams {
153155
build: string;
154156
buildURL: string;
155157
commit: string;
158+
// this is a custom field that is only used for GH pre-merge commits
159+
compareSha?: string;
156160
job: string;
157161
pr: string;
158162
service: string;

packages/bundler-plugin-core/src/utils/__tests__/normalizeOptions.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ const tests: Test[] = [
5555
uploadOverrides: {
5656
branch: "test-branch",
5757
build: "test-build",
58+
compareSha: "test-compare-sha",
5859
sha: "test-sha",
5960
slug: "test-slug",
6061
pr: "1234",
@@ -74,6 +75,7 @@ const tests: Test[] = [
7475
uploadOverrides: {
7576
branch: "test-branch",
7677
build: "test-build",
78+
compareSha: "test-compare-sha",
7779
sha: "test-sha",
7880
slug: "test-slug",
7981
pr: "1234",
@@ -104,6 +106,8 @@ const tests: Test[] = [
104106
// @ts-expect-error - testing invalid input
105107
build: 123,
106108
// @ts-expect-error - testing invalid input
109+
compareSha: 123,
110+
// @ts-expect-error - testing invalid input
107111
sha: 123,
108112
// @ts-expect-error - testing invalid input
109113
slug: 123,
@@ -123,6 +127,7 @@ const tests: Test[] = [
123127
"`uploadToken` must be a string.",
124128
"`branch` must be a string.",
125129
"`build` must be a string.",
130+
"`compareSha` must be a string.",
126131
"`pr` must be a string.",
127132
"`sha` must be a string.",
128133
"`slug` must be a string.",

0 commit comments

Comments
 (0)