Skip to content

Commit

Permalink
feat: Grab compare SHA for GH pre-merge commits (#147)
Browse files Browse the repository at this point in the history
Add in functionality to grab the correct base comparison SHA.
  • Loading branch information
nicholas-codecov authored Jul 19, 2024
1 parent 2df4d02 commit 42bf08e
Show file tree
Hide file tree
Showing 13 changed files with 167 additions and 88 deletions.
58 changes: 31 additions & 27 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ jobs:
fetch-depth: 0

- name: Setup node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 20

- name: Install pnpm
uses: pnpm/action-setup@v2
uses: pnpm/action-setup@v4
with:
version: 9
run_install: false
Expand All @@ -39,7 +39,7 @@ jobs:
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v3
uses: actions/cache@v4
env:
cache-name: cache-codecov-js-bundle-plugin-node-modules
with:
Expand All @@ -62,12 +62,12 @@ jobs:
fetch-depth: 0

- name: Setup node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 20

- name: Install pnpm
uses: pnpm/action-setup@v2
uses: pnpm/action-setup@v4
with:
version: 9
run_install: false
Expand All @@ -79,7 +79,7 @@ jobs:
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v3
uses: actions/cache@v4
env:
cache-name: cache-codecov-js-bundle-plugin-node-modules
with:
Expand Down Expand Up @@ -108,12 +108,12 @@ jobs:
fetch-depth: 0

- name: Setup node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 20

- name: Install pnpm
uses: pnpm/action-setup@v2
uses: pnpm/action-setup@v4
with:
version: 9
run_install: false
Expand All @@ -125,7 +125,7 @@ jobs:
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v3
uses: actions/cache@v4
env:
cache-name: cache-codecov-js-bundle-plugin-node-modules
with:
Expand Down Expand Up @@ -154,12 +154,12 @@ jobs:
fetch-depth: 0

- name: Setup node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 20

- name: Install pnpm
uses: pnpm/action-setup@v2
uses: pnpm/action-setup@v4
with:
version: 9
run_install: false
Expand All @@ -171,7 +171,7 @@ jobs:
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v3
uses: actions/cache@v4
env:
cache-name: cache-codecov-js-bundle-plugin-node-modules
with:
Expand Down Expand Up @@ -237,12 +237,12 @@ jobs:
fetch-depth: 0

- name: Setup node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: Install pnpm
uses: pnpm/action-setup@v2
uses: pnpm/action-setup@v4
with:
version: 9
run_install: false
Expand All @@ -254,7 +254,7 @@ jobs:
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v3
uses: actions/cache@v4
env:
cache-name: cache-codecov-js-bundle-plugin-node-modules
with:
Expand Down Expand Up @@ -288,12 +288,12 @@ jobs:
fetch-depth: 0

- name: Setup node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 20

- name: Install pnpm
uses: pnpm/action-setup@v2
uses: pnpm/action-setup@v4
with:
version: 9
run_install: false
Expand All @@ -305,7 +305,7 @@ jobs:
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v3
uses: actions/cache@v4
env:
cache-name: cache-codecov-js-bundle-plugin-node-modules
with:
Expand All @@ -326,6 +326,8 @@ jobs:
- name: Build ${{ matrix.example }} app for production
working-directory: ./examples/${{ matrix.example }}
env:
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
NEXT_UPLOAD_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }}
NEXT_API_URL: ${{ secrets.CODECOV_API_URL }}
NUXT_UPLOAD_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }}
Expand Down Expand Up @@ -358,12 +360,12 @@ jobs:
fetch-depth: 0

- name: Setup node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 20

- name: Install pnpm
uses: pnpm/action-setup@v2
uses: pnpm/action-setup@v4
with:
version: 9
run_install: false
Expand All @@ -375,7 +377,7 @@ jobs:
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v3
uses: actions/cache@v4
env:
cache-name: cache-codecov-js-bundle-plugin-node-modules
with:
Expand All @@ -396,6 +398,8 @@ jobs:
- name: Build ${{ matrix.example }} app for staging
working-directory: ./examples/${{ matrix.example }}
env:
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
NEXT_UPLOAD_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN_STAGING }}
NEXT_API_URL: ${{ secrets.CODECOV_STAGING_API_URL }}
NUXT_UPLOAD_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }}
Expand Down Expand Up @@ -436,12 +440,12 @@ jobs:
fetch-depth: 0

- name: Setup node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 20

- name: Install pnpm
uses: pnpm/action-setup@v2
uses: pnpm/action-setup@v4
with:
version: 9
run_install: false
Expand All @@ -453,7 +457,7 @@ jobs:
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v3
uses: actions/cache@v4
env:
cache-name: cache-codecov-js-bundle-plugin-node-modules
with:
Expand Down Expand Up @@ -502,12 +506,12 @@ jobs:
fetch-depth: 0

- name: Setup node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 20

- name: Install pnpm
uses: pnpm/action-setup@v2
uses: pnpm/action-setup@v4
with:
version: 9
run_install: false
Expand All @@ -519,7 +523,7 @@ jobs:
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v3
uses: actions/cache@v4
env:
cache-name: cache-codecov-js-bundle-plugin-node-modules
with:
Expand Down
1 change: 1 addition & 0 deletions examples/next-js/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const nextConfig = {
bundleName: "@codecov/example-next-app",
uploadToken: process.env.NEXT_UPLOAD_TOKEN,
apiUrl: process.env.NEXT_API_URL,
debug: true,
}),
);

Expand Down
1 change: 1 addition & 0 deletions examples/nuxt/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default defineNuxtConfig({
bundleName: "@codecov/example-nuxt-app",
uploadToken: process.env.NUXT_UPLOAD_TOKEN,
apiUrl: process.env.NUXT_API_URL,
debug: true,
},
],
],
Expand Down
1 change: 1 addition & 0 deletions examples/remix/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default defineConfig({
bundleName: "@codecov/example-remix-app",
uploadToken: process.env.REMIX_UPLOAD_TOKEN,
apiUrl: process.env.REMIX_API_URL,
debug: true,
}),
],
});
5 changes: 5 additions & 0 deletions examples/rollup/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ export default defineConfig({
bundleName: "@codecov/example-rollup-app",
apiUrl: process.env.ROLLUP_API_URL,
uploadToken: process.env.ROLLUP_UPLOAD_TOKEN,
debug: true,
uploadOverrides: {
sha: process.env.HEAD_SHA,
compareSha: process.env.BASE_SHA,
},
}),
],
});
1 change: 1 addition & 0 deletions examples/sveltekit/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default defineConfig({
bundleName: "@codecov/example-sveltekit-app",
uploadToken: process.env.SVELTEKIT_UPLOAD_TOKEN,
apiUrl: process.env.SVELTEKIT_API_URL,
debug: true,
}),
],
});
1 change: 1 addition & 0 deletions examples/vite/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default defineConfig({
bundleName: "@codecov/example-vite-app",
uploadToken: process.env.VITE_UPLOAD_TOKEN,
apiUrl: process.env.VITE_API_URL,
debug: true,
}),
],
});
1 change: 1 addition & 0 deletions examples/webpack/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = {
bundleName: "@codecov/example-webpack-app",
uploadToken: process.env.WEBPACK_UPLOAD_TOKEN,
apiUrl: process.env.WEBPACK_API_URL,
debug: true,
}),
],
};
4 changes: 4 additions & 0 deletions packages/bundler-plugin-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ export interface UploadOverrides {
branch?: string;
/** Specify the build number manually. */
build?: string;
/** Specify the compare SHA manually. **GH Actions only**. */
compareSha?: string;
/** Specify the pull request number manually. */
pr?: string;
/** Specify the commit SHA manually. */
Expand Down Expand Up @@ -153,6 +155,8 @@ export interface ProviderServiceParams {
build: string;
buildURL: string;
commit: string;
// this is a custom field that is only used for GH pre-merge commits
compareSha?: string;
job: string;
pr: string;
service: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const tests: Test[] = [
uploadOverrides: {
branch: "test-branch",
build: "test-build",
compareSha: "test-compare-sha",
sha: "test-sha",
slug: "test-slug",
pr: "1234",
Expand All @@ -74,6 +75,7 @@ const tests: Test[] = [
uploadOverrides: {
branch: "test-branch",
build: "test-build",
compareSha: "test-compare-sha",
sha: "test-sha",
slug: "test-slug",
pr: "1234",
Expand Down Expand Up @@ -104,6 +106,8 @@ const tests: Test[] = [
// @ts-expect-error - testing invalid input
build: 123,
// @ts-expect-error - testing invalid input
compareSha: 123,
// @ts-expect-error - testing invalid input
sha: 123,
// @ts-expect-error - testing invalid input
slug: 123,
Expand All @@ -123,6 +127,7 @@ const tests: Test[] = [
"`uploadToken` must be a string.",
"`branch` must be a string.",
"`build` must be a string.",
"`compareSha` must be a string.",
"`pr` must be a string.",
"`sha` must be a string.",
"`slug` must be a string.",
Expand Down
5 changes: 5 additions & 0 deletions packages/bundler-plugin-core/src/utils/normalizeOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ const UploadOverridesSchema = z.object({
invalid_type_error: "`build` must be a string.",
})
.optional(),
compareSha: z
.string({
invalid_type_error: "`compareSha` must be a string.",
})
.optional(),
pr: z
.string({
invalid_type_error: "`pr` must be a string.",
Expand Down
Loading

0 comments on commit 42bf08e

Please sign in to comment.