From f857b9603bb46455c252a5d4df435d964f1a06df Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Thu, 8 Aug 2024 10:51:35 -0300 Subject: [PATCH 01/39] remove NoUploadTokenError --- .../bundler-plugin-core/src/errors/NoUploadTokenError.ts | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 packages/bundler-plugin-core/src/errors/NoUploadTokenError.ts diff --git a/packages/bundler-plugin-core/src/errors/NoUploadTokenError.ts b/packages/bundler-plugin-core/src/errors/NoUploadTokenError.ts deleted file mode 100644 index 4b342015..00000000 --- a/packages/bundler-plugin-core/src/errors/NoUploadTokenError.ts +++ /dev/null @@ -1,5 +0,0 @@ -export class NoUploadTokenError extends Error { - constructor(msg: string) { - super(msg); - } -} From fce4c394671035b169418408879aed90636b09e2 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Thu, 8 Aug 2024 10:52:16 -0300 Subject: [PATCH 02/39] update getPreSignedURL to remove requirement for uploadToken --- .../src/utils/__tests__/getPreSignedURL.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/bundler-plugin-core/src/utils/__tests__/getPreSignedURL.test.ts b/packages/bundler-plugin-core/src/utils/__tests__/getPreSignedURL.test.ts index 0cae4a12..4a26602d 100644 --- a/packages/bundler-plugin-core/src/utils/__tests__/getPreSignedURL.test.ts +++ b/packages/bundler-plugin-core/src/utils/__tests__/getPreSignedURL.test.ts @@ -16,7 +16,6 @@ import childProcess from "child_process"; import { SPAWN_PROCESS_BUFFER_SIZE } from "../constants.ts"; import { getPreSignedURL } from "../getPreSignedURL.ts"; import { FailedFetchError } from "../../errors/FailedFetchError.ts"; -import { NoUploadTokenError } from "../../errors/NoUploadTokenError.ts"; import { UploadLimitReachedError } from "../../errors/UploadLimitReachedError.ts"; import { UndefinedGitServiceError } from "../../errors/UndefinedGitServiceError.ts"; From 2dcffd2658f81397f962d5d57cd4e485466e9cea Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Fri, 9 Aug 2024 09:58:17 -0300 Subject: [PATCH 03/39] add back no upload token error and new undefined git service error --- .../bundler-plugin-core/src/errors/NoUploadTokenError.ts | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 packages/bundler-plugin-core/src/errors/NoUploadTokenError.ts diff --git a/packages/bundler-plugin-core/src/errors/NoUploadTokenError.ts b/packages/bundler-plugin-core/src/errors/NoUploadTokenError.ts new file mode 100644 index 00000000..4b342015 --- /dev/null +++ b/packages/bundler-plugin-core/src/errors/NoUploadTokenError.ts @@ -0,0 +1,5 @@ +export class NoUploadTokenError extends Error { + constructor(msg: string) { + super(msg); + } +} From e41ab7a168b37d76e4b5d84bcae38ba23e3e97c0 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Fri, 9 Aug 2024 10:00:04 -0300 Subject: [PATCH 04/39] update getPreSignedURL to support tokenless uploads --- .../src/utils/__tests__/getPreSignedURL.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/bundler-plugin-core/src/utils/__tests__/getPreSignedURL.test.ts b/packages/bundler-plugin-core/src/utils/__tests__/getPreSignedURL.test.ts index 4a26602d..0cae4a12 100644 --- a/packages/bundler-plugin-core/src/utils/__tests__/getPreSignedURL.test.ts +++ b/packages/bundler-plugin-core/src/utils/__tests__/getPreSignedURL.test.ts @@ -16,6 +16,7 @@ import childProcess from "child_process"; import { SPAWN_PROCESS_BUFFER_SIZE } from "../constants.ts"; import { getPreSignedURL } from "../getPreSignedURL.ts"; import { FailedFetchError } from "../../errors/FailedFetchError.ts"; +import { NoUploadTokenError } from "../../errors/NoUploadTokenError.ts"; import { UploadLimitReachedError } from "../../errors/UploadLimitReachedError.ts"; import { UndefinedGitServiceError } from "../../errors/UndefinedGitServiceError.ts"; From 72fa17b00e8d13ec5c97d15612a6ace187405cf9 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Mon, 19 Aug 2024 13:38:30 -0300 Subject: [PATCH 05/39] add tokenless examples to readme's --- packages/nuxt-plugin/README.md | 24 ++++++++++++++++++++++++ packages/remix-vite-plugin/README.md | 23 +++++++++++++++++++++++ packages/rollup-plugin/README.md | 19 +++++++++++++++++++ packages/solidstart-plugin/README.md | 23 +++++++++++++++++++++++ packages/sveltekit-plugin/README.md | 21 +++++++++++++++++++++ packages/vite-plugin/README.md | 17 +++++++++++++++++ packages/webpack-plugin/README.md | 25 +++++++++++++++++++++++++ 7 files changed, 152 insertions(+) diff --git a/packages/nuxt-plugin/README.md b/packages/nuxt-plugin/README.md index 908b4111..1901fb83 100644 --- a/packages/nuxt-plugin/README.md +++ b/packages/nuxt-plugin/README.md @@ -119,6 +119,30 @@ export default defineNuxtConfig({ }); ``` +## Tokenless Example + +```js +// nuxt.config.ts +import { defineNuxtConfig } from "nuxt/config"; + +export default defineNuxtConfig({ + devtools: { enabled: true }, + // Ensure that the builder is set to "vite" + builder: "vite", + // Ensure that the plugin is added to the modules array + modules: [ + [ + "@codecov/nuxt-plugin", + { + enableBundleAnalysis: true, + bundleName: "nuxt-bundle-analysis", + gitService: "github", + }, + ], + ], +}); +``` + ## More information - [Codecov Documentation](https://docs.codecov.com/docs) diff --git a/packages/remix-vite-plugin/README.md b/packages/remix-vite-plugin/README.md index f4b5f791..4368b4c3 100644 --- a/packages/remix-vite-plugin/README.md +++ b/packages/remix-vite-plugin/README.md @@ -116,6 +116,29 @@ export default defineConfig({ }); ``` +## Tokenless Example + +```ts +// vite.config.ts +import { vitePlugin as remix } from "@remix-run/dev"; +import { defineConfig } from "vite"; +import tsconfigPaths from "vite-tsconfig-paths"; +import { codecovRemixPlugin } from "@codecov/remix-vite-plugin"; + +export default defineConfig({ + plugins: [ + remix(), + tsconfigPaths() + // Put the Codecov Remix plugin after all other plugins + codecovRemixPlugin({ + enableBundleAnalysis: true, + bundleName: "example-remix-bundle", + gitService: "github", + }), + ], +}); +``` + ## More information - [Codecov Documentation](https://docs.codecov.com/docs) diff --git a/packages/rollup-plugin/README.md b/packages/rollup-plugin/README.md index d709299f..33b88c15 100644 --- a/packages/rollup-plugin/README.md +++ b/packages/rollup-plugin/README.md @@ -101,6 +101,25 @@ export default defineConfig({ }); ``` +## Tokenless Example + +```js +// rollup.config.js +import { defineConfig } from "rollup"; +import { codecovRollupPlugin } from "@codecov/rollup-plugin"; + +export default defineConfig({ + plugins: [ + // Put the Codecov rollup plugin after all other plugins + codecovRollupPlugin({ + enableBundleAnalysis: true, + bundleName: "example-rollup-bundle", + gitService: "github", + }), + ], +}); +``` + ## More information - [Rollup Config Docs](https://codecov.github.io/codecov-javascript-bundler-plugins/modules/_codecov_rollup_plugin.html) diff --git a/packages/solidstart-plugin/README.md b/packages/solidstart-plugin/README.md index 2549ea32..bd04cd46 100644 --- a/packages/solidstart-plugin/README.md +++ b/packages/solidstart-plugin/README.md @@ -116,6 +116,29 @@ export default defineConfig({ }); ``` +## Tokenless Example + +```ts +// app.config.ts +import { defineConfig } from "@solidjs/start/config"; +import solidPlugin from "vite-plugin-solid"; +import { codecovSolidStartPlugin } from "@codecov/solidstart-plugin"; + +export default defineConfig({ + vite: { + plugins: [ + // Put the Codecov SolidStart plugin after all other plugins + solidPlugin(), + codecovSolidStartPlugin({ + enableBundleAnalysis: true, + bundleName: "example-solidstart-bundle", + gitService: "github", + }), + ], + }, +}); +``` + ## More information - [Codecov Documentation](https://docs.codecov.com/docs) diff --git a/packages/sveltekit-plugin/README.md b/packages/sveltekit-plugin/README.md index 21a616bd..a667d794 100644 --- a/packages/sveltekit-plugin/README.md +++ b/packages/sveltekit-plugin/README.md @@ -110,6 +110,27 @@ export default defineConfig({ }); ``` +## Tokenless Example + +```ts +// vite.config.ts +import { sveltekit } from "@sveltejs/kit/vite"; +import { defineConfig } from "vite"; +import { codecovSvelteKitPlugin } from "@codecov/sveltekit-plugin"; + +export default defineConfig({ + plugins: [ + sveltekit(), + // Put the Codecov SvelteKit plugin after all other plugins + codecovSvelteKitPlugin({ + enableBundleAnalysis: true, + bundleName: "example-sveltekit-bundle", + gitService: "github", + }), + ], +}); +``` + ## More information - [Codecov Documentation](https://docs.codecov.com/docs) diff --git a/packages/vite-plugin/README.md b/packages/vite-plugin/README.md index 2d8df00d..64a91456 100644 --- a/packages/vite-plugin/README.md +++ b/packages/vite-plugin/README.md @@ -101,6 +101,23 @@ export default defineConfig({ }); ``` +```js +// vite.config.js +import { defineConfig } from "vite"; +import { codecovVitePlugin } from "@codecov/vite-plugin"; + +export default defineConfig({ + plugins: [ + // Put the Codecov vite plugin after all other plugins + codecovVitePlugin({ + enableBundleAnalysis: true, + bundleName: "example-vite-bundle", + gitService: "github", + }), + ], +}); +``` + ## More information - [Vite Config Docs](https://codecov.github.io/codecov-javascript-bundler-plugins/modules/_codecov_vite_plugin.html) diff --git a/packages/webpack-plugin/README.md b/packages/webpack-plugin/README.md index 7998994f..3db7d65b 100644 --- a/packages/webpack-plugin/README.md +++ b/packages/webpack-plugin/README.md @@ -119,6 +119,31 @@ module.exports = { }; ``` +## Tokenless Example + +```js +// webpack.config.js +const path = require("path"); +const { codecovWebpackPlugin } = require("@codecov/webpack-plugin"); + +module.exports = { + entry: "./src/index.js", + mode: "production", + output: { + filename: "main.js", + path: path.resolve(__dirname, "dist"), + }, + plugins: [ + // Put the Codecov vite plugin after all other plugins + codecovWebpackPlugin({ + enableBundleAnalysis: true, + bundleName: "example-webpack-bundle", + gitService: "github", + }), + ], +}; +``` + ## More information - [Webpack Config Docs](https://codecov.github.io/codecov-javascript-bundler-plugins/modules/_codecov_webpack_plugin.html) From 5852a14944ac278770d71416a1390346d5b386d2 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Wed, 21 Aug 2024 10:26:59 -0300 Subject: [PATCH 06/39] update readme examples --- packages/nuxt-plugin/README.md | 28 +++++++++++++++++++++++++++ packages/remix-vite-plugin/README.md | 27 ++++++++++++++++++++++++++ packages/rollup-plugin/README.md | 23 ++++++++++++++++++++++ packages/solidstart-plugin/README.md | 27 ++++++++++++++++++++++++++ packages/sveltekit-plugin/README.md | 25 ++++++++++++++++++++++++ packages/vite-plugin/README.md | 10 ++++++++-- packages/webpack-plugin/README.md | 29 ++++++++++++++++++++++++++++ 7 files changed, 167 insertions(+), 2 deletions(-) diff --git a/packages/nuxt-plugin/README.md b/packages/nuxt-plugin/README.md index 1901fb83..58a95cc6 100644 --- a/packages/nuxt-plugin/README.md +++ b/packages/nuxt-plugin/README.md @@ -121,6 +121,8 @@ export default defineNuxtConfig({ ## Tokenless Example +This is the recommended way to use the plugin. This configuration will automatically upload the bundle analysis to Codecov. + ```js // nuxt.config.ts import { defineNuxtConfig } from "nuxt/config"; @@ -143,6 +145,32 @@ export default defineNuxtConfig({ }); ``` +## Upload Token Example - Required for Private Repositories + +This is the required way to use the plugin for private repositories. This configuration will automatically upload the bundle analysis to Codecov. + +```js +// nuxt.config.ts +import { defineNuxtConfig } from "nuxt/config"; + +export default defineNuxtConfig({ + devtools: { enabled: true }, + // Ensure that the builder is set to "vite" + builder: "vite", + // Ensure that the plugin is added to the modules array + modules: [ + [ + "@codecov/nuxt-plugin", + { + enableBundleAnalysis: true, + bundleName: "nuxt-bundle-analysis", + uploadToken: process.env.CODECOV_UPLOAD_TOKEN, + }, + ], + ], +}); +``` + ## More information - [Codecov Documentation](https://docs.codecov.com/docs) diff --git a/packages/remix-vite-plugin/README.md b/packages/remix-vite-plugin/README.md index 4368b4c3..638d1ba9 100644 --- a/packages/remix-vite-plugin/README.md +++ b/packages/remix-vite-plugin/README.md @@ -118,6 +118,8 @@ export default defineConfig({ ## Tokenless Example +This is the recommended way to use the plugin. This configuration will automatically upload the bundle analysis to Codecov. + ```ts // vite.config.ts import { vitePlugin as remix } from "@remix-run/dev"; @@ -139,6 +141,31 @@ export default defineConfig({ }); ``` +## Upload Token Example - Required for Private Repositories + +This is the required way to use the plugin for private repositories. This configuration will automatically upload the bundle analysis to Codecov. + +```ts +// vite.config.ts +import { vitePlugin as remix } from "@remix-run/dev"; +import { defineConfig } from "vite"; +import tsconfigPaths from "vite-tsconfig-paths"; +import { codecovRemixPlugin } from "@codecov/remix-vite-plugin"; + +export default defineConfig({ + plugins: [ + remix(), + tsconfigPaths() + // Put the Codecov Remix plugin after all other plugins + codecovRemixPlugin({ + enableBundleAnalysis: true, + bundleName: "example-remix-bundle", + uploadToken: process.env.CODECOV_TOKEN, + }), + ], +}); +``` + ## More information - [Codecov Documentation](https://docs.codecov.com/docs) diff --git a/packages/rollup-plugin/README.md b/packages/rollup-plugin/README.md index 33b88c15..81bd68b4 100644 --- a/packages/rollup-plugin/README.md +++ b/packages/rollup-plugin/README.md @@ -103,6 +103,8 @@ export default defineConfig({ ## Tokenless Example +This is the recommended way to use the plugin. This configuration will automatically upload the bundle analysis to Codecov. + ```js // rollup.config.js import { defineConfig } from "rollup"; @@ -120,6 +122,27 @@ export default defineConfig({ }); ``` +## Upload Token Example - Required for Private Repositories + +This is the required way to use the plugin for private repositories. This configuration will automatically upload the bundle analysis to Codecov. + +```js +// rollup.config.js +import { defineConfig } from "rollup"; +import { codecovRollupPlugin } from "@codecov/rollup-plugin"; + +export default defineConfig({ + plugins: [ + // Put the Codecov rollup plugin after all other plugins + codecovRollupPlugin({ + enableBundleAnalysis: true, + bundleName: "example-rollup-bundle", + uploadToken: process.env.CODECOV_TOKEN, + }), + ], +}); +``` + ## More information - [Rollup Config Docs](https://codecov.github.io/codecov-javascript-bundler-plugins/modules/_codecov_rollup_plugin.html) diff --git a/packages/solidstart-plugin/README.md b/packages/solidstart-plugin/README.md index bd04cd46..4675f65b 100644 --- a/packages/solidstart-plugin/README.md +++ b/packages/solidstart-plugin/README.md @@ -118,6 +118,8 @@ export default defineConfig({ ## Tokenless Example +This is the recommended way to use the plugin. This configuration will automatically upload the bundle analysis to Codecov. + ```ts // app.config.ts import { defineConfig } from "@solidjs/start/config"; @@ -139,6 +141,31 @@ export default defineConfig({ }); ``` +## Upload Example - Required for Private Repositories + +This is the required way to use the plugin for private repositories. This configuration will automatically upload the bundle analysis to Codecov. + +```ts +// app.config.ts +import { defineConfig } from "@solidjs/start/config"; +import solidPlugin from "vite-plugin-solid"; +import { codecovSolidStartPlugin } from "@codecov/solidstart-plugin"; + +export default defineConfig({ + vite: { + plugins: [ + // Put the Codecov SolidStart plugin after all other plugins + solidPlugin(), + codecovSolidStartPlugin({ + enableBundleAnalysis: true, + bundleName: "example-solidstart-bundle", + uploadToken: process.env.CODECOV_TOKEN, + }), + ], + }, +}); +``` + ## More information - [Codecov Documentation](https://docs.codecov.com/docs) diff --git a/packages/sveltekit-plugin/README.md b/packages/sveltekit-plugin/README.md index a667d794..beff1dd8 100644 --- a/packages/sveltekit-plugin/README.md +++ b/packages/sveltekit-plugin/README.md @@ -112,6 +112,8 @@ export default defineConfig({ ## Tokenless Example +This is the recommended way to use the plugin. This configuration will automatically upload the bundle analysis to Codecov. + ```ts // vite.config.ts import { sveltekit } from "@sveltejs/kit/vite"; @@ -131,6 +133,29 @@ export default defineConfig({ }); ``` +## Upload Token Example - Required for Private Repositories + +This is the required way to use the plugin for private repositories. This configuration will automatically upload the bundle analysis to Codecov. + +```ts +// vite.config.ts +import { sveltekit } from "@sveltejs/kit/vite"; +import { defineConfig } from "vite"; +import { codecovSvelteKitPlugin } from "@codecov/sveltekit-plugin"; + +export default defineConfig({ + plugins: [ + sveltekit(), + // Put the Codecov SvelteKit plugin after all other plugins + codecovSvelteKitPlugin({ + enableBundleAnalysis: true, + bundleName: "example-sveltekit-bundle", + uploadToken: process.env.CODECOV_TOKEN, + }), + ], +}); +``` + ## More information - [Codecov Documentation](https://docs.codecov.com/docs) diff --git a/packages/vite-plugin/README.md b/packages/vite-plugin/README.md index 64a91456..74124bb6 100644 --- a/packages/vite-plugin/README.md +++ b/packages/vite-plugin/README.md @@ -84,6 +84,8 @@ export default defineConfig({ This is the required way to use the plugin for private repositories. This configuration will automatically upload the bundle analysis to Codecov. +This is the recommended way to use the plugin. This configuration will automatically upload the bundle analysis to Codecov. + ```js // vite.config.js import { defineConfig } from "vite"; @@ -95,12 +97,16 @@ export default defineConfig({ codecovVitePlugin({ enableBundleAnalysis: true, bundleName: "example-vite-bundle", - uploadToken: process.env.CODECOV_TOKEN, + gitService: "github", }), ], }); ``` +## Upload Token Example - Required for Private Repositories + +This is the required way to use the plugin for private repositories. This configuration will automatically upload the bundle analysis to Codecov. + ```js // vite.config.js import { defineConfig } from "vite"; @@ -112,7 +118,7 @@ export default defineConfig({ codecovVitePlugin({ enableBundleAnalysis: true, bundleName: "example-vite-bundle", - gitService: "github", + uploadToken: process.env.CODECOV_TOKEN, }), ], }); diff --git a/packages/webpack-plugin/README.md b/packages/webpack-plugin/README.md index 3db7d65b..adf82347 100644 --- a/packages/webpack-plugin/README.md +++ b/packages/webpack-plugin/README.md @@ -121,6 +121,8 @@ module.exports = { ## Tokenless Example +This is the recommended way to use the plugin. This configuration will automatically upload the bundle analysis to Codecov. + ```js // webpack.config.js const path = require("path"); @@ -144,6 +146,33 @@ module.exports = { }; ``` +## Upload Token Example - Required for Private Repositories + +This is the required way to use the plugin for private repositories. This configuration will automatically upload the bundle analysis to Codecov. + +```js +// webpack.config.js +const path = require("path"); +const { codecovWebpackPlugin } = require("@codecov/webpack-plugin"); + +module.exports = { + entry: "./src/index.js", + mode: "production", + output: { + filename: "main.js", + path: path.resolve(__dirname, "dist"), + }, + plugins: [ + // Put the Codecov vite plugin after all other plugins + codecovWebpackPlugin({ + enableBundleAnalysis: true, + bundleName: "example-webpack-bundle", + uploadToken: process.env.CODECOV_TOKEN, + }), + ], +}; +``` + ## More information - [Webpack Config Docs](https://codecov.github.io/codecov-javascript-bundler-plugins/modules/_codecov_webpack_plugin.html) From 15e62a1aadcceb1fdeb74827af256bad5c8c7a7c Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Mon, 26 Aug 2024 10:24:18 -0300 Subject: [PATCH 07/39] update readme copy --- packages/nuxt-plugin/README.md | 2 +- packages/remix-vite-plugin/README.md | 2 +- packages/rollup-plugin/README.md | 2 +- packages/solidstart-plugin/README.md | 4 ++-- packages/sveltekit-plugin/README.md | 2 +- packages/vite-plugin/README.md | 2 +- packages/webpack-plugin/README.md | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/nuxt-plugin/README.md b/packages/nuxt-plugin/README.md index 58a95cc6..320e9eeb 100644 --- a/packages/nuxt-plugin/README.md +++ b/packages/nuxt-plugin/README.md @@ -121,7 +121,7 @@ export default defineNuxtConfig({ ## Tokenless Example -This is the recommended way to use the plugin. This configuration will automatically upload the bundle analysis to Codecov. +This configuration will automatically upload the bundle analysis to Codecov. See the [below configuration](#upload-token-example---required-for-private-repositories) for private repositories. ```js // nuxt.config.ts diff --git a/packages/remix-vite-plugin/README.md b/packages/remix-vite-plugin/README.md index 638d1ba9..bd7d6c89 100644 --- a/packages/remix-vite-plugin/README.md +++ b/packages/remix-vite-plugin/README.md @@ -118,7 +118,7 @@ export default defineConfig({ ## Tokenless Example -This is the recommended way to use the plugin. This configuration will automatically upload the bundle analysis to Codecov. +This configuration will automatically upload the bundle analysis to Codecov. See the [below configuration](#upload-token-example---required-for-private-repositories) for private repositories. ```ts // vite.config.ts diff --git a/packages/rollup-plugin/README.md b/packages/rollup-plugin/README.md index 81bd68b4..95c38af6 100644 --- a/packages/rollup-plugin/README.md +++ b/packages/rollup-plugin/README.md @@ -103,7 +103,7 @@ export default defineConfig({ ## Tokenless Example -This is the recommended way to use the plugin. This configuration will automatically upload the bundle analysis to Codecov. +This configuration will automatically upload the bundle analysis to Codecov. See the [below configuration](#upload-token-example---required-for-private-repositories) for private repositories. ```js // rollup.config.js diff --git a/packages/solidstart-plugin/README.md b/packages/solidstart-plugin/README.md index 4675f65b..25c0da33 100644 --- a/packages/solidstart-plugin/README.md +++ b/packages/solidstart-plugin/README.md @@ -118,7 +118,7 @@ export default defineConfig({ ## Tokenless Example -This is the recommended way to use the plugin. This configuration will automatically upload the bundle analysis to Codecov. +This configuration will automatically upload the bundle analysis to Codecov. See the [below configuration](#upload-token-example---required-for-private-repositories) for private repositories. ```ts // app.config.ts @@ -141,7 +141,7 @@ export default defineConfig({ }); ``` -## Upload Example - Required for Private Repositories +## Upload Token Example - Required for Private Repositories This is the required way to use the plugin for private repositories. This configuration will automatically upload the bundle analysis to Codecov. diff --git a/packages/sveltekit-plugin/README.md b/packages/sveltekit-plugin/README.md index beff1dd8..62a1d336 100644 --- a/packages/sveltekit-plugin/README.md +++ b/packages/sveltekit-plugin/README.md @@ -112,7 +112,7 @@ export default defineConfig({ ## Tokenless Example -This is the recommended way to use the plugin. This configuration will automatically upload the bundle analysis to Codecov. +This configuration will automatically upload the bundle analysis to Codecov. See the [below configuration](#upload-token-example---required-for-private-repositories) for private repositories. ```ts // vite.config.ts diff --git a/packages/vite-plugin/README.md b/packages/vite-plugin/README.md index 74124bb6..b4335569 100644 --- a/packages/vite-plugin/README.md +++ b/packages/vite-plugin/README.md @@ -84,7 +84,7 @@ export default defineConfig({ This is the required way to use the plugin for private repositories. This configuration will automatically upload the bundle analysis to Codecov. -This is the recommended way to use the plugin. This configuration will automatically upload the bundle analysis to Codecov. +This configuration will automatically upload the bundle analysis to Codecov. See the [below configuration](#upload-token-example---required-for-private-repositories) for private repositories. ```js // vite.config.js diff --git a/packages/webpack-plugin/README.md b/packages/webpack-plugin/README.md index adf82347..776f493f 100644 --- a/packages/webpack-plugin/README.md +++ b/packages/webpack-plugin/README.md @@ -121,7 +121,7 @@ module.exports = { ## Tokenless Example -This is the recommended way to use the plugin. This configuration will automatically upload the bundle analysis to Codecov. +This configuration will automatically upload the bundle analysis to Codecov. See the [below configuration](#upload-token-example---required-for-private-repositories) for private repositories. ```js // webpack.config.js From d6b01ea5af0411fd825ce733ae884711b5405fe6 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Tue, 27 Aug 2024 07:52:54 -0300 Subject: [PATCH 08/39] remove tokenless example, as it only works with forks --- .github/workflows/ci.yml | 2 - examples/tokenless/.eslintrc.cjs | 18 ----- examples/tokenless/.gitignore | 24 ------- examples/tokenless/README.md | 27 -------- examples/tokenless/index.html | 13 ---- examples/tokenless/package.json | 36 ---------- examples/tokenless/public/vite.svg | 1 - examples/tokenless/src/App.css | 42 ----------- examples/tokenless/src/App.tsx | 44 ------------ .../IndexedLazyComponent.tsx | 7 -- .../src/IndexedLazyComponent/index.ts | 1 - .../src/LazyComponent/LazyComponent.tsx | 14 ---- examples/tokenless/src/assets/react.svg | 1 - examples/tokenless/src/index.css | 69 ------------------- examples/tokenless/src/main.tsx | 10 --- examples/tokenless/src/vite-env.d.ts | 1 - examples/tokenless/tsconfig.json | 25 ------- examples/tokenless/tsconfig.node.json | 10 --- examples/tokenless/vite.config.ts | 26 ------- 19 files changed, 371 deletions(-) delete mode 100644 examples/tokenless/.eslintrc.cjs delete mode 100644 examples/tokenless/.gitignore delete mode 100644 examples/tokenless/README.md delete mode 100644 examples/tokenless/index.html delete mode 100644 examples/tokenless/package.json delete mode 100644 examples/tokenless/public/vite.svg delete mode 100644 examples/tokenless/src/App.css delete mode 100644 examples/tokenless/src/App.tsx delete mode 100644 examples/tokenless/src/IndexedLazyComponent/IndexedLazyComponent.tsx delete mode 100644 examples/tokenless/src/IndexedLazyComponent/index.ts delete mode 100644 examples/tokenless/src/LazyComponent/LazyComponent.tsx delete mode 100644 examples/tokenless/src/assets/react.svg delete mode 100644 examples/tokenless/src/index.css delete mode 100644 examples/tokenless/src/main.tsx delete mode 100644 examples/tokenless/src/vite-env.d.ts delete mode 100644 examples/tokenless/tsconfig.json delete mode 100644 examples/tokenless/tsconfig.node.json delete mode 100644 examples/tokenless/vite.config.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f21fc3b4..1ff9c37e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -290,7 +290,6 @@ jobs: "vite", "webpack", "solidstart", - "tokenless", ] steps: - name: Checkout @@ -377,7 +376,6 @@ jobs: "vite", "webpack", "solidstart", - "tokenless", ] steps: - name: Checkout diff --git a/examples/tokenless/.eslintrc.cjs b/examples/tokenless/.eslintrc.cjs deleted file mode 100644 index d6c95379..00000000 --- a/examples/tokenless/.eslintrc.cjs +++ /dev/null @@ -1,18 +0,0 @@ -module.exports = { - root: true, - env: { browser: true, es2020: true }, - extends: [ - 'eslint:recommended', - 'plugin:@typescript-eslint/recommended', - 'plugin:react-hooks/recommended', - ], - ignorePatterns: ['dist', '.eslintrc.cjs'], - parser: '@typescript-eslint/parser', - plugins: ['react-refresh'], - rules: { - 'react-refresh/only-export-components': [ - 'warn', - { allowConstantExport: true }, - ], - }, -} diff --git a/examples/tokenless/.gitignore b/examples/tokenless/.gitignore deleted file mode 100644 index a547bf36..00000000 --- a/examples/tokenless/.gitignore +++ /dev/null @@ -1,24 +0,0 @@ -# Logs -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* -pnpm-debug.log* -lerna-debug.log* - -node_modules -dist -dist-ssr -*.local - -# Editor directories and files -.vscode/* -!.vscode/extensions.json -.idea -.DS_Store -*.suo -*.ntvs* -*.njsproj -*.sln -*.sw? diff --git a/examples/tokenless/README.md b/examples/tokenless/README.md deleted file mode 100644 index 1ebe379f..00000000 --- a/examples/tokenless/README.md +++ /dev/null @@ -1,27 +0,0 @@ -# React + TypeScript + Vite - -This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. - -Currently, two official plugins are available: - -- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh -- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh - -## Expanding the ESLint configuration - -If you are developing a production application, we recommend updating the configuration to enable type aware lint rules: - -- Configure the top-level `parserOptions` property like this: - -```js - parserOptions: { - ecmaVersion: 'latest', - sourceType: 'module', - project: ['./tsconfig.json', './tsconfig.node.json'], - tsconfigRootDir: __dirname, - }, -``` - -- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked` -- Optionally add `plugin:@typescript-eslint/stylistic-type-checked` -- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list diff --git a/examples/tokenless/index.html b/examples/tokenless/index.html deleted file mode 100644 index e4b78eae..00000000 --- a/examples/tokenless/index.html +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - Vite + React + TS - - -
- - - diff --git a/examples/tokenless/package.json b/examples/tokenless/package.json deleted file mode 100644 index 0a59cd07..00000000 --- a/examples/tokenless/package.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "name": "@codecov/example-tokenless-app", - "private": true, - "version": "0.0.0", - "type": "module", - "scripts": { - "dev": "vite", - "build": "tsc && vite build", - "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", - "preview": "vite preview" - }, - "dependencies": { - "react": "^18.2.0", - "react-dom": "^18.2.0" - }, - "devDependencies": { - "@codecov/vite-plugin": "workspace:^", - "@types/react": "^18.2.51", - "@types/react-dom": "^18.2.18", - "@typescript-eslint/eslint-plugin": "^6.20.0", - "@typescript-eslint/parser": "^6.20.0", - "@vitejs/plugin-react": "^4.2.1", - "eslint": "^8.56.0", - "eslint-plugin-react-hooks": "^4.6.0", - "eslint-plugin-react-refresh": "^0.4.5", - "rollup": "^4.9.6", - "typescript": "^5.3.3", - "vite": "^5.2.10" - }, - "volta": { - "extends": "../../package.json" - }, - "engines": { - "node": ">=18.0.0" - } -} diff --git a/examples/tokenless/public/vite.svg b/examples/tokenless/public/vite.svg deleted file mode 100644 index e7b8dfb1..00000000 --- a/examples/tokenless/public/vite.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/examples/tokenless/src/App.css b/examples/tokenless/src/App.css deleted file mode 100644 index b9d355df..00000000 --- a/examples/tokenless/src/App.css +++ /dev/null @@ -1,42 +0,0 @@ -#root { - max-width: 1280px; - margin: 0 auto; - padding: 2rem; - text-align: center; -} - -.logo { - height: 6em; - padding: 1.5em; - will-change: filter; - transition: filter 300ms; -} -.logo:hover { - filter: drop-shadow(0 0 2em #646cffaa); -} -.logo.react:hover { - filter: drop-shadow(0 0 2em #61dafbaa); -} - -@keyframes logo-spin { - from { - transform: rotate(0deg); - } - to { - transform: rotate(360deg); - } -} - -@media (prefers-reduced-motion: no-preference) { - a:nth-of-type(2) .logo { - animation: logo-spin infinite 20s linear; - } -} - -.card { - padding: 2em; -} - -.read-the-docs { - color: #888; -} diff --git a/examples/tokenless/src/App.tsx b/examples/tokenless/src/App.tsx deleted file mode 100644 index 345e0828..00000000 --- a/examples/tokenless/src/App.tsx +++ /dev/null @@ -1,44 +0,0 @@ -import { useState, lazy, Suspense } from "react"; -import reactLogo from "./assets/react.svg"; -import viteLogo from "/vite.svg"; -import "./App.css"; - -const IndexedLazyComponent = lazy(() => import("./IndexedLazyComponent")); -const LazyComponent = lazy(() => import("./LazyComponent/LazyComponent")); - -function App() { - const [count, setCount] = useState(0); - - return ( - <> - -

Vite + React

-
- -

- Edit src/App.tsx and save to test HMR -

-
-

- Click on the Vite and React logos to learn more -

- - - - - - - - ); -} - -export default App; diff --git a/examples/tokenless/src/IndexedLazyComponent/IndexedLazyComponent.tsx b/examples/tokenless/src/IndexedLazyComponent/IndexedLazyComponent.tsx deleted file mode 100644 index 6686dc58..00000000 --- a/examples/tokenless/src/IndexedLazyComponent/IndexedLazyComponent.tsx +++ /dev/null @@ -1,7 +0,0 @@ -export default function IndexedLazyComponent() { - return ( -
-

Indexed Lazy Component

-
- ); -} diff --git a/examples/tokenless/src/IndexedLazyComponent/index.ts b/examples/tokenless/src/IndexedLazyComponent/index.ts deleted file mode 100644 index 1dd706b5..00000000 --- a/examples/tokenless/src/IndexedLazyComponent/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { default } from "./IndexedLazyComponent"; diff --git a/examples/tokenless/src/LazyComponent/LazyComponent.tsx b/examples/tokenless/src/LazyComponent/LazyComponent.tsx deleted file mode 100644 index 2a56c928..00000000 --- a/examples/tokenless/src/LazyComponent/LazyComponent.tsx +++ /dev/null @@ -1,14 +0,0 @@ -import { lazy, Suspense } from "react"; - -const IndexedLazyComponent = lazy(() => import("../IndexedLazyComponent")); - -export default function LazyComponent() { - return ( -
-

Lazy Component

- - - -
- ); -} diff --git a/examples/tokenless/src/assets/react.svg b/examples/tokenless/src/assets/react.svg deleted file mode 100644 index 6c87de9b..00000000 --- a/examples/tokenless/src/assets/react.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/examples/tokenless/src/index.css b/examples/tokenless/src/index.css deleted file mode 100644 index 2c3fac68..00000000 --- a/examples/tokenless/src/index.css +++ /dev/null @@ -1,69 +0,0 @@ -:root { - font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; - line-height: 1.5; - font-weight: 400; - - color-scheme: light dark; - color: rgba(255, 255, 255, 0.87); - background-color: #242424; - - font-synthesis: none; - text-rendering: optimizeLegibility; - -webkit-font-smoothing: antialiased; - -moz-osx-font-smoothing: grayscale; - -webkit-text-size-adjust: 100%; -} - -a { - font-weight: 500; - color: #646cff; - text-decoration: inherit; -} -a:hover { - color: #535bf2; -} - -body { - margin: 0; - display: flex; - place-items: center; - min-width: 320px; - min-height: 100vh; -} - -h1 { - font-size: 3.2em; - line-height: 1.1; -} - -button { - border-radius: 8px; - border: 1px solid transparent; - padding: 0.6em 1.2em; - font-size: 1em; - font-weight: 500; - font-family: inherit; - background-color: #1a1a1a; - cursor: pointer; - transition: border-color 0.25s; -} -button:hover { - border-color: #646cff; -} -button:focus, -button:focus-visible { - outline: 4px auto -webkit-focus-ring-color; -} - -@media (prefers-color-scheme: light) { - :root { - color: #213547; - background-color: #ffffff; - } - a:hover { - color: #747bff; - } - button { - background-color: #f9f9f9; - } -} diff --git a/examples/tokenless/src/main.tsx b/examples/tokenless/src/main.tsx deleted file mode 100644 index f25366e5..00000000 --- a/examples/tokenless/src/main.tsx +++ /dev/null @@ -1,10 +0,0 @@ -import React from "react"; -import ReactDOM from "react-dom/client"; -import App from "./App.tsx"; -import "./index.css"; - -ReactDOM.createRoot(document.getElementById("root")!).render( - - - , -); diff --git a/examples/tokenless/src/vite-env.d.ts b/examples/tokenless/src/vite-env.d.ts deleted file mode 100644 index 11f02fe2..00000000 --- a/examples/tokenless/src/vite-env.d.ts +++ /dev/null @@ -1 +0,0 @@ -/// diff --git a/examples/tokenless/tsconfig.json b/examples/tokenless/tsconfig.json deleted file mode 100644 index de3bc503..00000000 --- a/examples/tokenless/tsconfig.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "compilerOptions": { - "target": "ES2020", - "useDefineForClassFields": true, - "lib": ["ES2020", "DOM", "DOM.Iterable"], - "module": "ESNext", - "skipLibCheck": true, - - /* Bundler mode */ - "moduleResolution": "bundler", - "allowImportingTsExtensions": true, - "resolveJsonModule": true, - "isolatedModules": true, - "noEmit": true, - "jsx": "react-jsx", - - /* Linting */ - "strict": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "noFallthroughCasesInSwitch": true, - }, - "include": ["src"], - "references": [{ "path": "./tsconfig.node.json" }], -} diff --git a/examples/tokenless/tsconfig.node.json b/examples/tokenless/tsconfig.node.json deleted file mode 100644 index 42872c59..00000000 --- a/examples/tokenless/tsconfig.node.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "compilerOptions": { - "composite": true, - "skipLibCheck": true, - "module": "ESNext", - "moduleResolution": "bundler", - "allowSyntheticDefaultImports": true - }, - "include": ["vite.config.ts"] -} diff --git a/examples/tokenless/vite.config.ts b/examples/tokenless/vite.config.ts deleted file mode 100644 index 2b1345b9..00000000 --- a/examples/tokenless/vite.config.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { defineConfig } from "vite"; -import react from "@vitejs/plugin-react"; -import { codecovVitePlugin } from "@codecov/vite-plugin"; - -// https://vitejs.dev/config/ -export default defineConfig({ - build: { - rollupOptions: { - output: { - assetFileNames: "[name].[hash].js", - chunkFileNames: "[name]-[hash].js", - }, - }, - }, - plugins: [ - react(), - codecovVitePlugin({ - enableBundleAnalysis: true, - bundleName: "@codecov/example-tokenless-app", - uploadToken: process.env.TOKENLESS_UPLOAD_TOKEN, - apiUrl: process.env.TOKENLESS_API_URL, - gitService: "github", - debug: true, - }), - ], -}); From 61444746d9a3c574481dd493db1ea9da20e9846d Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Tue, 27 Aug 2024 09:12:10 -0300 Subject: [PATCH 09/39] update readme with new examples --- packages/nuxt-plugin/README.md | 39 +++++++++++++++++++++++++--- packages/remix-vite-plugin/README.md | 34 ++++++++++++++++++++++-- packages/rollup-plugin/README.md | 30 +++++++++++++++++++-- packages/solidstart-plugin/README.md | 34 ++++++++++++++++++++++-- packages/sveltekit-plugin/README.md | 32 +++++++++++++++++++++-- packages/vite-plugin/README.md | 30 +++++++++++++++++++-- packages/webpack-plugin/README.md | 36 +++++++++++++++++++++++-- 7 files changed, 219 insertions(+), 16 deletions(-) diff --git a/packages/nuxt-plugin/README.md b/packages/nuxt-plugin/README.md index 320e9eeb..49925485 100644 --- a/packages/nuxt-plugin/README.md +++ b/packages/nuxt-plugin/README.md @@ -121,9 +121,9 @@ export default defineNuxtConfig({ ## Tokenless Example -This configuration will automatically upload the bundle analysis to Codecov. See the [below configuration](#upload-token-example---required-for-private-repositories) for private repositories. +This configuration will automatically upload the bundle analysis to Codecov for public repositories. When an internal PR is created it will use the Codecov token set in your secrets, and if running from a forked PR, it will use the tokenless setting automatically. For setups not using GitHub Actions see the following [example](#public-repo-example---non-github-actions). For private repositories see the following [example](#private-repo-example). -```js +```typescript // nuxt.config.ts import { defineNuxtConfig } from "nuxt/config"; @@ -138,6 +138,7 @@ export default defineNuxtConfig({ { enableBundleAnalysis: true, bundleName: "nuxt-bundle-analysis", + uploadToken: process.env.CODECOV_UPLOAD_TOKEN, gitService: "github", }, ], @@ -145,11 +146,41 @@ export default defineNuxtConfig({ }); ``` -## Upload Token Example - Required for Private Repositories +## Public Repo Example - Non-GitHub Actions + +This setup is for public repositories that are not using GitHub Actions, this configuration will automatically upload the bundle analysis to Codecov. You will need to configure the it similar to the GitHub Actions example, however you will need to provide a branch override, and ensure that it will pass the correct branch name, and with forks including the fork-owner i.e. `fork-owner:branch`. + +```typescript +// nuxt.config.ts +import { defineNuxtConfig } from "nuxt/config"; + +export default defineNuxtConfig({ + devtools: { enabled: true }, + // Ensure that the builder is set to "vite" + builder: "vite", + // Ensure that the plugin is added to the modules array + modules: [ + [ + "@codecov/nuxt-plugin", + { + enableBundleAnalysis: true, + bundleName: "nuxt-bundle-analysis", + uploadToken: process.env.CODECOV_UPLOAD_TOKEN, + gitService: "github", + uploadOverrides: { + branch: "", + }, + }, + ], + ], +}); +``` + +## Private Repo Example This is the required way to use the plugin for private repositories. This configuration will automatically upload the bundle analysis to Codecov. -```js +```typescript // nuxt.config.ts import { defineNuxtConfig } from "nuxt/config"; diff --git a/packages/remix-vite-plugin/README.md b/packages/remix-vite-plugin/README.md index bd7d6c89..cf280954 100644 --- a/packages/remix-vite-plugin/README.md +++ b/packages/remix-vite-plugin/README.md @@ -118,7 +118,33 @@ export default defineConfig({ ## Tokenless Example -This configuration will automatically upload the bundle analysis to Codecov. See the [below configuration](#upload-token-example---required-for-private-repositories) for private repositories. +This configuration will automatically upload the bundle analysis to Codecov for public repositories. When an internal PR is created it will use the Codecov token set in your secrets, and if running from a forked PR, it will use the tokenless setting automatically. For setups not using GitHub Actions see the following [example](#public-repo-example---non-github-actions). For private repositories see the following [example](#private-repo-example). + +```ts +// vite.config.ts +import { vitePlugin as remix } from "@remix-run/dev"; +import { defineConfig } from "vite"; +import tsconfigPaths from "vite-tsconfig-paths"; +import { codecovRemixPlugin } from "@codecov/remix-vite-plugin"; + +export default defineConfig({ + plugins: [ + remix(), + tsconfigPaths() + // Put the Codecov Remix plugin after all other plugins + codecovRemixPlugin({ + enableBundleAnalysis: true, + bundleName: "example-remix-bundle", + uploadToken: process.env.CODECOV_TOKEN, + gitService: "github", + }), + ], +}); +``` + +## Public Repo Example - Non-GitHub Actions + +This setup is for public repositories that are not using GitHub Actions, this configuration will automatically upload the bundle analysis to Codecov. You will need to configure the it similar to the GitHub Actions example, however you will need to provide a branch override, and ensure that it will pass the correct branch name, and with forks including the fork-owner i.e. `fork-owner:branch`. ```ts // vite.config.ts @@ -135,13 +161,17 @@ export default defineConfig({ codecovRemixPlugin({ enableBundleAnalysis: true, bundleName: "example-remix-bundle", + uploadToken: process.env.CODECOV_TOKEN, gitService: "github", + uploadOverrides: { + branch: "", + }, }), ], }); ``` -## Upload Token Example - Required for Private Repositories +## Private Repo Example This is the required way to use the plugin for private repositories. This configuration will automatically upload the bundle analysis to Codecov. diff --git a/packages/rollup-plugin/README.md b/packages/rollup-plugin/README.md index 95c38af6..54129a3a 100644 --- a/packages/rollup-plugin/README.md +++ b/packages/rollup-plugin/README.md @@ -103,7 +103,29 @@ export default defineConfig({ ## Tokenless Example -This configuration will automatically upload the bundle analysis to Codecov. See the [below configuration](#upload-token-example---required-for-private-repositories) for private repositories. +This configuration will automatically upload the bundle analysis to Codecov for public repositories. When an internal PR is created it will use the Codecov token set in your secrets, and if running from a forked PR, it will use the tokenless setting automatically. For setups not using GitHub Actions see the following [example](#public-repo-example---non-github-actions). For private repositories see the following [example](#private-repo-example). + +```js +// rollup.config.js +import { defineConfig } from "rollup"; +import { codecovRollupPlugin } from "@codecov/rollup-plugin"; + +export default defineConfig({ + plugins: [ + // Put the Codecov rollup plugin after all other plugins + codecovRollupPlugin({ + enableBundleAnalysis: true, + bundleName: "example-rollup-bundle", + uploadToken: process.env.CODECOV_TOKEN, + gitService: "github", + }), + ], +}); +``` + +## Public Repo Example - Non-GitHub Actions + +This setup is for public repositories that are not using GitHub Actions, this configuration will automatically upload the bundle analysis to Codecov. You will need to configure the it similar to the GitHub Actions example, however you will need to provide a branch override, and ensure that it will pass the correct branch name, and with forks including the fork-owner i.e. `fork-owner:branch`. ```js // rollup.config.js @@ -116,13 +138,17 @@ export default defineConfig({ codecovRollupPlugin({ enableBundleAnalysis: true, bundleName: "example-rollup-bundle", + uploadToken: process.env.CODECOV_TOKEN, gitService: "github", + uploadOverrides: { + branch: "", + }, }), ], }); ``` -## Upload Token Example - Required for Private Repositories +## Private Repo Example This is the required way to use the plugin for private repositories. This configuration will automatically upload the bundle analysis to Codecov. diff --git a/packages/solidstart-plugin/README.md b/packages/solidstart-plugin/README.md index 25c0da33..1348405c 100644 --- a/packages/solidstart-plugin/README.md +++ b/packages/solidstart-plugin/README.md @@ -118,7 +118,33 @@ export default defineConfig({ ## Tokenless Example -This configuration will automatically upload the bundle analysis to Codecov. See the [below configuration](#upload-token-example---required-for-private-repositories) for private repositories. +This configuration will automatically upload the bundle analysis to Codecov for public repositories. When an internal PR is created it will use the Codecov token set in your secrets, and if running from a forked PR, it will use the tokenless setting automatically. For setups not using GitHub Actions see the following [example](#public-repo-example---non-github-actions). For private repositories see the following [example](#private-repo-example). + +```ts +// app.config.ts +import { defineConfig } from "@solidjs/start/config"; +import solidPlugin from "vite-plugin-solid"; +import { codecovSolidStartPlugin } from "@codecov/solidstart-plugin"; + +export default defineConfig({ + vite: { + plugins: [ + // Put the Codecov SolidStart plugin after all other plugins + solidPlugin(), + codecovSolidStartPlugin({ + enableBundleAnalysis: true, + bundleName: "example-solidstart-bundle", + uploadToken: process.env.CODECOV_TOKEN, + gitService: "github", + }), + ], + }, +}); +``` + +## Public Repo Example - Non-GitHub Actions + +This setup is for public repositories that are not using GitHub Actions, this configuration will automatically upload the bundle analysis to Codecov. You will need to configure the it similar to the GitHub Actions example, however you will need to provide a branch override, and ensure that it will pass the correct branch name, and with forks including the fork-owner i.e. `fork-owner:branch`. ```ts // app.config.ts @@ -134,14 +160,18 @@ export default defineConfig({ codecovSolidStartPlugin({ enableBundleAnalysis: true, bundleName: "example-solidstart-bundle", + uploadToken: process.env.CODECOV_TOKEN, gitService: "github", + uploadOverrides: { + branch: "", + }, }), ], }, }); ``` -## Upload Token Example - Required for Private Repositories +## Private Repo Example This is the required way to use the plugin for private repositories. This configuration will automatically upload the bundle analysis to Codecov. diff --git a/packages/sveltekit-plugin/README.md b/packages/sveltekit-plugin/README.md index 62a1d336..b5157aa9 100644 --- a/packages/sveltekit-plugin/README.md +++ b/packages/sveltekit-plugin/README.md @@ -112,7 +112,31 @@ export default defineConfig({ ## Tokenless Example -This configuration will automatically upload the bundle analysis to Codecov. See the [below configuration](#upload-token-example---required-for-private-repositories) for private repositories. +This configuration will automatically upload the bundle analysis to Codecov for public repositories. When an internal PR is created it will use the Codecov token set in your secrets, and if running from a forked PR, it will use the tokenless setting automatically. For setups not using GitHub Actions see the following [example](#public-repo-example---non-github-actions). For private repositories see the following [example](#private-repo-example). + +```ts +// vite.config.ts +import { sveltekit } from "@sveltejs/kit/vite"; +import { defineConfig } from "vite"; +import { codecovSvelteKitPlugin } from "@codecov/sveltekit-plugin"; + +export default defineConfig({ + plugins: [ + sveltekit(), + // Put the Codecov SvelteKit plugin after all other plugins + codecovSvelteKitPlugin({ + enableBundleAnalysis: true, + bundleName: "example-sveltekit-bundle", + uploadToken: process.env.CODECOV_TOKEN, + gitService: "github", + }), + ], +}); +``` + +## Public Repo Example - Non-GitHub Actions + +This setup is for public repositories that are not using GitHub Actions, this configuration will automatically upload the bundle analysis to Codecov. You will need to configure the it similar to the GitHub Actions example, however you will need to provide a branch override, and ensure that it will pass the correct branch name, and with forks including the fork-owner i.e. `fork-owner:branch`. ```ts // vite.config.ts @@ -127,13 +151,17 @@ export default defineConfig({ codecovSvelteKitPlugin({ enableBundleAnalysis: true, bundleName: "example-sveltekit-bundle", + uploadToken: process.env.CODECOV_TOKEN, gitService: "github", + uploadOverrides: { + branch: "", + }, }), ], }); ``` -## Upload Token Example - Required for Private Repositories +## Private Repo Example This is the required way to use the plugin for private repositories. This configuration will automatically upload the bundle analysis to Codecov. diff --git a/packages/vite-plugin/README.md b/packages/vite-plugin/README.md index b4335569..02861c50 100644 --- a/packages/vite-plugin/README.md +++ b/packages/vite-plugin/README.md @@ -84,7 +84,29 @@ export default defineConfig({ This is the required way to use the plugin for private repositories. This configuration will automatically upload the bundle analysis to Codecov. -This configuration will automatically upload the bundle analysis to Codecov. See the [below configuration](#upload-token-example---required-for-private-repositories) for private repositories. +This configuration will automatically upload the bundle analysis to Codecov for public repositories. When an internal PR is created it will use the Codecov token set in your secrets, and if running from a forked PR, it will use the tokenless setting automatically. For setups not using GitHub Actions see the following [example](#public-repo-example---non-github-actions). For private repositories see the following [example](#private-repo-example). + +```js +// vite.config.js +import { defineConfig } from "vite"; +import { codecovVitePlugin } from "@codecov/vite-plugin"; + +export default defineConfig({ + plugins: [ + // Put the Codecov vite plugin after all other plugins + codecovVitePlugin({ + enableBundleAnalysis: true, + bundleName: "example-vite-bundle", + uploadToken: process.env.CODECOV_TOKEN, + gitService: "github", + }), + ], +}); +``` + +## Public Repo Example - Non-GitHub Actions + +This setup is for public repositories that are not using GitHub Actions, this configuration will automatically upload the bundle analysis to Codecov. You will need to configure the it similar to the GitHub Actions example, however you will need to provide a branch override, and ensure that it will pass the correct branch name, and with forks including the fork-owner i.e. `fork-owner:branch`. ```js // vite.config.js @@ -97,13 +119,17 @@ export default defineConfig({ codecovVitePlugin({ enableBundleAnalysis: true, bundleName: "example-vite-bundle", + uploadToken: process.env.CODECOV_TOKEN, gitService: "github", + uploadOverrides: { + branch: "", + }, }), ], }); ``` -## Upload Token Example - Required for Private Repositories +## Private Repo Example This is the required way to use the plugin for private repositories. This configuration will automatically upload the bundle analysis to Codecov. diff --git a/packages/webpack-plugin/README.md b/packages/webpack-plugin/README.md index 776f493f..dcfec3c0 100644 --- a/packages/webpack-plugin/README.md +++ b/packages/webpack-plugin/README.md @@ -121,7 +121,35 @@ module.exports = { ## Tokenless Example -This configuration will automatically upload the bundle analysis to Codecov. See the [below configuration](#upload-token-example---required-for-private-repositories) for private repositories. +This configuration will automatically upload the bundle analysis to Codecov for public repositories. When an internal PR is created it will use the Codecov token set in your secrets, and if running from a forked PR, it will use the tokenless setting automatically. For setups not using GitHub Actions see the following [example](#public-repo-example---non-github-actions). For private repositories see the following [example](#private-repo-example). + +```js +// webpack.config.js +const path = require("path"); +const { codecovWebpackPlugin } = require("@codecov/webpack-plugin"); + +module.exports = { + entry: "./src/index.js", + mode: "production", + output: { + filename: "main.js", + path: path.resolve(__dirname, "dist"), + }, + plugins: [ + // Put the Codecov vite plugin after all other plugins + codecovWebpackPlugin({ + enableBundleAnalysis: true, + bundleName: "example-webpack-bundle", + uploadToken: process.env.CODECOV_TOKEN, + gitService: "github", + }), + ], +}; +``` + +## Public Repo Example - Non-GitHub Actions + +This setup is for public repositories that are not using GitHub Actions, this configuration will automatically upload the bundle analysis to Codecov. You will need to configure the it similar to the GitHub Actions example, however you will need to provide a branch override, and ensure that it will pass the correct branch name, and with forks including the fork-owner i.e. `fork-owner:branch`. ```js // webpack.config.js @@ -140,13 +168,17 @@ module.exports = { codecovWebpackPlugin({ enableBundleAnalysis: true, bundleName: "example-webpack-bundle", + uploadToken: process.env.CODECOV_TOKEN, gitService: "github", + uploadOverrides: { + branch: "", + }, }), ], }; ``` -## Upload Token Example - Required for Private Repositories +## Private Repo Example This is the required way to use the plugin for private repositories. This configuration will automatically upload the bundle analysis to Codecov. From 0e201d343d5c1e316d4230c37a205dfb0be23626 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Tue, 27 Aug 2024 09:18:55 -0300 Subject: [PATCH 10/39] add in tokenless example --- .github/workflows/ci.yml | 2 + examples/tokenless/.eslintrc.cjs | 18 +++++ examples/tokenless/.gitignore | 24 +++++++ examples/tokenless/README.md | 27 ++++++++ examples/tokenless/index.html | 13 ++++ examples/tokenless/package.json | 36 ++++++++++ examples/tokenless/public/vite.svg | 1 + examples/tokenless/src/App.css | 42 +++++++++++ examples/tokenless/src/App.tsx | 44 ++++++++++++ .../IndexedLazyComponent.tsx | 7 ++ .../src/IndexedLazyComponent/index.ts | 1 + .../src/LazyComponent/LazyComponent.tsx | 14 ++++ examples/tokenless/src/assets/react.svg | 1 + examples/tokenless/src/index.css | 69 +++++++++++++++++++ examples/tokenless/src/main.tsx | 10 +++ examples/tokenless/src/vite-env.d.ts | 1 + examples/tokenless/tsconfig.json | 25 +++++++ examples/tokenless/tsconfig.node.json | 10 +++ examples/tokenless/vite.config.ts | 26 +++++++ 19 files changed, 371 insertions(+) create mode 100644 examples/tokenless/.eslintrc.cjs create mode 100644 examples/tokenless/.gitignore create mode 100644 examples/tokenless/README.md create mode 100644 examples/tokenless/index.html create mode 100644 examples/tokenless/package.json create mode 100644 examples/tokenless/public/vite.svg create mode 100644 examples/tokenless/src/App.css create mode 100644 examples/tokenless/src/App.tsx create mode 100644 examples/tokenless/src/IndexedLazyComponent/IndexedLazyComponent.tsx create mode 100644 examples/tokenless/src/IndexedLazyComponent/index.ts create mode 100644 examples/tokenless/src/LazyComponent/LazyComponent.tsx create mode 100644 examples/tokenless/src/assets/react.svg create mode 100644 examples/tokenless/src/index.css create mode 100644 examples/tokenless/src/main.tsx create mode 100644 examples/tokenless/src/vite-env.d.ts create mode 100644 examples/tokenless/tsconfig.json create mode 100644 examples/tokenless/tsconfig.node.json create mode 100644 examples/tokenless/vite.config.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1ff9c37e..f21fc3b4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -290,6 +290,7 @@ jobs: "vite", "webpack", "solidstart", + "tokenless", ] steps: - name: Checkout @@ -376,6 +377,7 @@ jobs: "vite", "webpack", "solidstart", + "tokenless", ] steps: - name: Checkout diff --git a/examples/tokenless/.eslintrc.cjs b/examples/tokenless/.eslintrc.cjs new file mode 100644 index 00000000..d6c95379 --- /dev/null +++ b/examples/tokenless/.eslintrc.cjs @@ -0,0 +1,18 @@ +module.exports = { + root: true, + env: { browser: true, es2020: true }, + extends: [ + 'eslint:recommended', + 'plugin:@typescript-eslint/recommended', + 'plugin:react-hooks/recommended', + ], + ignorePatterns: ['dist', '.eslintrc.cjs'], + parser: '@typescript-eslint/parser', + plugins: ['react-refresh'], + rules: { + 'react-refresh/only-export-components': [ + 'warn', + { allowConstantExport: true }, + ], + }, +} diff --git a/examples/tokenless/.gitignore b/examples/tokenless/.gitignore new file mode 100644 index 00000000..a547bf36 --- /dev/null +++ b/examples/tokenless/.gitignore @@ -0,0 +1,24 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +dist +dist-ssr +*.local + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +.DS_Store +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? diff --git a/examples/tokenless/README.md b/examples/tokenless/README.md new file mode 100644 index 00000000..1ebe379f --- /dev/null +++ b/examples/tokenless/README.md @@ -0,0 +1,27 @@ +# React + TypeScript + Vite + +This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. + +Currently, two official plugins are available: + +- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh +- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh + +## Expanding the ESLint configuration + +If you are developing a production application, we recommend updating the configuration to enable type aware lint rules: + +- Configure the top-level `parserOptions` property like this: + +```js + parserOptions: { + ecmaVersion: 'latest', + sourceType: 'module', + project: ['./tsconfig.json', './tsconfig.node.json'], + tsconfigRootDir: __dirname, + }, +``` + +- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked` +- Optionally add `plugin:@typescript-eslint/stylistic-type-checked` +- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list diff --git a/examples/tokenless/index.html b/examples/tokenless/index.html new file mode 100644 index 00000000..e4b78eae --- /dev/null +++ b/examples/tokenless/index.html @@ -0,0 +1,13 @@ + + + + + + + Vite + React + TS + + +
+ + + diff --git a/examples/tokenless/package.json b/examples/tokenless/package.json new file mode 100644 index 00000000..0a59cd07 --- /dev/null +++ b/examples/tokenless/package.json @@ -0,0 +1,36 @@ +{ + "name": "@codecov/example-tokenless-app", + "private": true, + "version": "0.0.0", + "type": "module", + "scripts": { + "dev": "vite", + "build": "tsc && vite build", + "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", + "preview": "vite preview" + }, + "dependencies": { + "react": "^18.2.0", + "react-dom": "^18.2.0" + }, + "devDependencies": { + "@codecov/vite-plugin": "workspace:^", + "@types/react": "^18.2.51", + "@types/react-dom": "^18.2.18", + "@typescript-eslint/eslint-plugin": "^6.20.0", + "@typescript-eslint/parser": "^6.20.0", + "@vitejs/plugin-react": "^4.2.1", + "eslint": "^8.56.0", + "eslint-plugin-react-hooks": "^4.6.0", + "eslint-plugin-react-refresh": "^0.4.5", + "rollup": "^4.9.6", + "typescript": "^5.3.3", + "vite": "^5.2.10" + }, + "volta": { + "extends": "../../package.json" + }, + "engines": { + "node": ">=18.0.0" + } +} diff --git a/examples/tokenless/public/vite.svg b/examples/tokenless/public/vite.svg new file mode 100644 index 00000000..e7b8dfb1 --- /dev/null +++ b/examples/tokenless/public/vite.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/tokenless/src/App.css b/examples/tokenless/src/App.css new file mode 100644 index 00000000..b9d355df --- /dev/null +++ b/examples/tokenless/src/App.css @@ -0,0 +1,42 @@ +#root { + max-width: 1280px; + margin: 0 auto; + padding: 2rem; + text-align: center; +} + +.logo { + height: 6em; + padding: 1.5em; + will-change: filter; + transition: filter 300ms; +} +.logo:hover { + filter: drop-shadow(0 0 2em #646cffaa); +} +.logo.react:hover { + filter: drop-shadow(0 0 2em #61dafbaa); +} + +@keyframes logo-spin { + from { + transform: rotate(0deg); + } + to { + transform: rotate(360deg); + } +} + +@media (prefers-reduced-motion: no-preference) { + a:nth-of-type(2) .logo { + animation: logo-spin infinite 20s linear; + } +} + +.card { + padding: 2em; +} + +.read-the-docs { + color: #888; +} diff --git a/examples/tokenless/src/App.tsx b/examples/tokenless/src/App.tsx new file mode 100644 index 00000000..345e0828 --- /dev/null +++ b/examples/tokenless/src/App.tsx @@ -0,0 +1,44 @@ +import { useState, lazy, Suspense } from "react"; +import reactLogo from "./assets/react.svg"; +import viteLogo from "/vite.svg"; +import "./App.css"; + +const IndexedLazyComponent = lazy(() => import("./IndexedLazyComponent")); +const LazyComponent = lazy(() => import("./LazyComponent/LazyComponent")); + +function App() { + const [count, setCount] = useState(0); + + return ( + <> + +

Vite + React

+
+ +

+ Edit src/App.tsx and save to test HMR +

+
+

+ Click on the Vite and React logos to learn more +

+ + + + + + + + ); +} + +export default App; diff --git a/examples/tokenless/src/IndexedLazyComponent/IndexedLazyComponent.tsx b/examples/tokenless/src/IndexedLazyComponent/IndexedLazyComponent.tsx new file mode 100644 index 00000000..6686dc58 --- /dev/null +++ b/examples/tokenless/src/IndexedLazyComponent/IndexedLazyComponent.tsx @@ -0,0 +1,7 @@ +export default function IndexedLazyComponent() { + return ( +
+

Indexed Lazy Component

+
+ ); +} diff --git a/examples/tokenless/src/IndexedLazyComponent/index.ts b/examples/tokenless/src/IndexedLazyComponent/index.ts new file mode 100644 index 00000000..1dd706b5 --- /dev/null +++ b/examples/tokenless/src/IndexedLazyComponent/index.ts @@ -0,0 +1 @@ +export { default } from "./IndexedLazyComponent"; diff --git a/examples/tokenless/src/LazyComponent/LazyComponent.tsx b/examples/tokenless/src/LazyComponent/LazyComponent.tsx new file mode 100644 index 00000000..2a56c928 --- /dev/null +++ b/examples/tokenless/src/LazyComponent/LazyComponent.tsx @@ -0,0 +1,14 @@ +import { lazy, Suspense } from "react"; + +const IndexedLazyComponent = lazy(() => import("../IndexedLazyComponent")); + +export default function LazyComponent() { + return ( +
+

Lazy Component

+ + + +
+ ); +} diff --git a/examples/tokenless/src/assets/react.svg b/examples/tokenless/src/assets/react.svg new file mode 100644 index 00000000..6c87de9b --- /dev/null +++ b/examples/tokenless/src/assets/react.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/tokenless/src/index.css b/examples/tokenless/src/index.css new file mode 100644 index 00000000..2c3fac68 --- /dev/null +++ b/examples/tokenless/src/index.css @@ -0,0 +1,69 @@ +:root { + font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; + line-height: 1.5; + font-weight: 400; + + color-scheme: light dark; + color: rgba(255, 255, 255, 0.87); + background-color: #242424; + + font-synthesis: none; + text-rendering: optimizeLegibility; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; + -webkit-text-size-adjust: 100%; +} + +a { + font-weight: 500; + color: #646cff; + text-decoration: inherit; +} +a:hover { + color: #535bf2; +} + +body { + margin: 0; + display: flex; + place-items: center; + min-width: 320px; + min-height: 100vh; +} + +h1 { + font-size: 3.2em; + line-height: 1.1; +} + +button { + border-radius: 8px; + border: 1px solid transparent; + padding: 0.6em 1.2em; + font-size: 1em; + font-weight: 500; + font-family: inherit; + background-color: #1a1a1a; + cursor: pointer; + transition: border-color 0.25s; +} +button:hover { + border-color: #646cff; +} +button:focus, +button:focus-visible { + outline: 4px auto -webkit-focus-ring-color; +} + +@media (prefers-color-scheme: light) { + :root { + color: #213547; + background-color: #ffffff; + } + a:hover { + color: #747bff; + } + button { + background-color: #f9f9f9; + } +} diff --git a/examples/tokenless/src/main.tsx b/examples/tokenless/src/main.tsx new file mode 100644 index 00000000..f25366e5 --- /dev/null +++ b/examples/tokenless/src/main.tsx @@ -0,0 +1,10 @@ +import React from "react"; +import ReactDOM from "react-dom/client"; +import App from "./App.tsx"; +import "./index.css"; + +ReactDOM.createRoot(document.getElementById("root")!).render( + + + , +); diff --git a/examples/tokenless/src/vite-env.d.ts b/examples/tokenless/src/vite-env.d.ts new file mode 100644 index 00000000..11f02fe2 --- /dev/null +++ b/examples/tokenless/src/vite-env.d.ts @@ -0,0 +1 @@ +/// diff --git a/examples/tokenless/tsconfig.json b/examples/tokenless/tsconfig.json new file mode 100644 index 00000000..de3bc503 --- /dev/null +++ b/examples/tokenless/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "target": "ES2020", + "useDefineForClassFields": true, + "lib": ["ES2020", "DOM", "DOM.Iterable"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true, + }, + "include": ["src"], + "references": [{ "path": "./tsconfig.node.json" }], +} diff --git a/examples/tokenless/tsconfig.node.json b/examples/tokenless/tsconfig.node.json new file mode 100644 index 00000000..42872c59 --- /dev/null +++ b/examples/tokenless/tsconfig.node.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "composite": true, + "skipLibCheck": true, + "module": "ESNext", + "moduleResolution": "bundler", + "allowSyntheticDefaultImports": true + }, + "include": ["vite.config.ts"] +} diff --git a/examples/tokenless/vite.config.ts b/examples/tokenless/vite.config.ts new file mode 100644 index 00000000..2b1345b9 --- /dev/null +++ b/examples/tokenless/vite.config.ts @@ -0,0 +1,26 @@ +import { defineConfig } from "vite"; +import react from "@vitejs/plugin-react"; +import { codecovVitePlugin } from "@codecov/vite-plugin"; + +// https://vitejs.dev/config/ +export default defineConfig({ + build: { + rollupOptions: { + output: { + assetFileNames: "[name].[hash].js", + chunkFileNames: "[name]-[hash].js", + }, + }, + }, + plugins: [ + react(), + codecovVitePlugin({ + enableBundleAnalysis: true, + bundleName: "@codecov/example-tokenless-app", + uploadToken: process.env.TOKENLESS_UPLOAD_TOKEN, + apiUrl: process.env.TOKENLESS_API_URL, + gitService: "github", + debug: true, + }), + ], +}); From 925d17b103a03c555ad6342361cc958757c989fc Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Tue, 27 Aug 2024 09:51:06 -0300 Subject: [PATCH 11/39] add in OIDC config object --- packages/bundler-plugin-core/src/types.ts | 17 ++++++++++ .../utils/__tests__/normalizeOptions.test.ts | 32 +++++++++++++++++++ .../src/utils/normalizeOptions.ts | 26 +++++++++++++++ 3 files changed, 75 insertions(+) diff --git a/packages/bundler-plugin-core/src/types.ts b/packages/bundler-plugin-core/src/types.ts index 76cdc736..2043802d 100644 --- a/packages/bundler-plugin-core/src/types.ts +++ b/packages/bundler-plugin-core/src/types.ts @@ -139,6 +139,23 @@ export interface Options { * Defaults to `false` */ dryRun?: boolean; + + /** Options for OIDC authentication. */ + oidc?: { + /** + * Whether to use GitHub OIDC for authentication. + * + * Defaults to `false` + */ + useGitHubOIDC: boolean; + + /** + * The OIDC endpoint to use for authentication. + * + * Defaults to `https://codecov.io` + */ + OIDCEndpoint: string; + }; } export type BundleAnalysisUploadPlugin = ( diff --git a/packages/bundler-plugin-core/src/utils/__tests__/normalizeOptions.test.ts b/packages/bundler-plugin-core/src/utils/__tests__/normalizeOptions.test.ts index ec4dd48d..e65f0d2b 100644 --- a/packages/bundler-plugin-core/src/utils/__tests__/normalizeOptions.test.ts +++ b/packages/bundler-plugin-core/src/utils/__tests__/normalizeOptions.test.ts @@ -62,6 +62,10 @@ const tests: Test[] = [ }, debug: true, gitService: "bitbucket", + oidc: { + useGitHubOIDC: true, + OIDCEndpoint: "https://codecov.io", + }, }, }, expected: { @@ -83,6 +87,10 @@ const tests: Test[] = [ }, debug: true, gitService: "bitbucket", + oidc: { + useGitHubOIDC: true, + OIDCEndpoint: "https://codecov.io", + }, }, }, }, @@ -120,6 +128,12 @@ const tests: Test[] = [ debug: "true", // @ts-expect-error - testing invalid input gitService: 123, + oidc: { + // @ts-expect-error - testing invalid input + useGitHubOIDC: "true", + // @ts-expect-error - testing invalid input + OIDCEndpoint: 123, + }, }, }, expected: { @@ -139,6 +153,8 @@ const tests: Test[] = [ "`slug` must be a string.", "`debug` must be a boolean.", "`gitService` must be a valid git service.", + "`useGitHubOIDC` must be a boolean.", + "`OIDCEndpoint` must be a string.", ], }, }, @@ -209,6 +225,22 @@ const tests: Test[] = [ errors: ["`retryCount` must be an integer."], }, }, + { + name: "OIDCEndpoint does not match URL format, returns format error message", + input: { + options: { + oidc: { + useGitHubOIDC: true, + OIDCEndpoint: "invalid-url", + }, + bundleName: "test-bundle", + }, + }, + expected: { + success: false, + errors: ["OIDCEndpoint: `invalid-url` is not a valid URL."], + }, + }, ]; describe("normalizeOptions", () => { diff --git a/packages/bundler-plugin-core/src/utils/normalizeOptions.ts b/packages/bundler-plugin-core/src/utils/normalizeOptions.ts index 89cf7e30..64e10365 100644 --- a/packages/bundler-plugin-core/src/utils/normalizeOptions.ts +++ b/packages/bundler-plugin-core/src/utils/normalizeOptions.ts @@ -56,6 +56,31 @@ const UploadOverridesSchema = z.object({ .optional(), }); +const OIDCSchema = (options: Options) => + z.object( + { + useGitHubOIDC: z + .boolean({ + invalid_type_error: "`useGitHubOIDC` must be a boolean.", + }) + .default(false), + /** + * Following along with how we handle this in our GH Action. + * + * See: https://github.com/codecov/codecov-action/blob/main/src/buildExec.ts#L53-L58 + */ + OIDCEndpoint: z + .string({ + invalid_type_error: "`OIDCEndpoint` must be a string.", + }) + .url({ + message: `OIDCEndpoint: \`${options?.oidc?.OIDCEndpoint}\` is not a valid URL.`, + }) + .default("https://codecov.io"), + }, + { invalid_type_error: "`oidc` must be an object." }, + ); + const optionsSchemaFactory = (options: Options) => z.object({ apiUrl: z @@ -123,6 +148,7 @@ const optionsSchemaFactory = (options: Options) => { invalid_type_error: "`gitService` must be a valid git service." }, ) .optional(), + oidc: OIDCSchema(options).optional(), }); interface NormalizedOptionsFailure { From c99080ff5b4cc7121c788a78a3dd9bd7ed6a759d Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Tue, 27 Aug 2024 11:20:43 -0300 Subject: [PATCH 12/39] add in @actions/core package --- packages/bundler-plugin-core/package.json | 1 + pnpm-lock.yaml | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/packages/bundler-plugin-core/package.json b/packages/bundler-plugin-core/package.json index b4c5a73a..6c31bfbf 100644 --- a/packages/bundler-plugin-core/package.json +++ b/packages/bundler-plugin-core/package.json @@ -39,6 +39,7 @@ "generate:typedoc": "typedoc --options ./typedoc.json" }, "dependencies": { + "@actions/core": "^1.10.1", "@actions/github": "^6.0.0", "chalk": "4.1.2", "semver": "^7.5.4", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 14e52699..7dc2eac4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -689,6 +689,9 @@ importers: packages/bundler-plugin-core: dependencies: + '@actions/core': + specifier: ^1.10.1 + version: 1.10.1 '@actions/github': specifier: ^6.0.0 version: 6.0.0 @@ -1164,6 +1167,9 @@ packages: resolution: {integrity: sha512-1Yjs2SvM8TflER/OD3cOjhWWOZb58A2t7wpE2S9XfBYTiIl+XFhQG2bjy4Pu1I+EAlCNUzRDYDdFwFYUKvXcIA==} engines: {node: '>=0.10.0'} + '@actions/core@1.10.1': + resolution: {integrity: sha512-3lBR9EDAY+iYIpTnTIXmWcNbX3T2kCkAEQGIQx4NVQ0575nk2k3GRZDTPQG+vVtS2izSLmINlxXf0uLtnrTP+g==} + '@actions/github@6.0.0': resolution: {integrity: sha512-alScpSVnYmjNEXboZjarjukQEzgCRmjMv6Xj47fsdnqGS73bjJNDpiiXmp8jr0UZLdUB6d9jW63IcmddUP+l0g==} @@ -9832,6 +9838,10 @@ packages: resolution: {integrity: sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==} engines: {node: '>= 0.4.0'} + uuid@8.3.2: + resolution: {integrity: sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==} + hasBin: true + uvu@0.5.6: resolution: {integrity: sha512-+g8ENReyr8YsOc6fv/NVJs2vFdHBnBNdfE49rshrTzDWOlUx4Gq7KOS2GD8eqhy2j+Ejq29+SbKH8yjkAqXqoA==} engines: {node: '>=8'} @@ -10373,6 +10383,11 @@ snapshots: '@aashutoshrathi/word-wrap@1.2.6': {} + '@actions/core@1.10.1': + dependencies: + '@actions/http-client': 2.2.1 + uuid: 8.3.2 + '@actions/github@6.0.0': dependencies: '@actions/http-client': 2.2.1 @@ -22498,6 +22513,8 @@ snapshots: utils-merge@1.0.1: {} + uuid@8.3.2: {} + uvu@0.5.6: dependencies: dequal: 2.0.3 From 2f05934bc516205b2835bea684853a6396afd938 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Tue, 27 Aug 2024 11:20:59 -0300 Subject: [PATCH 13/39] add in new errors for OIDC related errors --- .../bundler-plugin-core/src/errors/BadOIDCServiceError.ts | 5 +++++ packages/bundler-plugin-core/src/errors/FailedOIDCFetch.ts | 5 +++++ 2 files changed, 10 insertions(+) create mode 100644 packages/bundler-plugin-core/src/errors/BadOIDCServiceError.ts create mode 100644 packages/bundler-plugin-core/src/errors/FailedOIDCFetch.ts diff --git a/packages/bundler-plugin-core/src/errors/BadOIDCServiceError.ts b/packages/bundler-plugin-core/src/errors/BadOIDCServiceError.ts new file mode 100644 index 00000000..02c7c326 --- /dev/null +++ b/packages/bundler-plugin-core/src/errors/BadOIDCServiceError.ts @@ -0,0 +1,5 @@ +export class BadOIDCServiceError extends Error { + constructor(msg: string) { + super(msg); + } +} diff --git a/packages/bundler-plugin-core/src/errors/FailedOIDCFetch.ts b/packages/bundler-plugin-core/src/errors/FailedOIDCFetch.ts new file mode 100644 index 00000000..f0a9baa4 --- /dev/null +++ b/packages/bundler-plugin-core/src/errors/FailedOIDCFetch.ts @@ -0,0 +1,5 @@ +export class FailedOIDCFetch extends Error { + constructor(msg: string) { + super(msg); + } +} From 9b4e7777faa7b5c3e83229605dcf96ad1469c8fd Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Tue, 27 Aug 2024 11:21:14 -0300 Subject: [PATCH 14/39] fix msw mock in index.test.ts --- .../src/utils/providers/__tests__/index.test.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/bundler-plugin-core/src/utils/providers/__tests__/index.test.ts b/packages/bundler-plugin-core/src/utils/providers/__tests__/index.test.ts index 40cb90e2..ccb89f0f 100644 --- a/packages/bundler-plugin-core/src/utils/providers/__tests__/index.test.ts +++ b/packages/bundler-plugin-core/src/utils/providers/__tests__/index.test.ts @@ -9,9 +9,12 @@ import { Output } from "../../Output.ts"; import { providerList } from "../index.ts"; const server = setupServer( - http.get("https://api.github.com/repos/:org/:repo/actions/runs//jobs", () => { - return HttpResponse.json({}, { status: 200 }); - }), + http.get( + "https://api.github.com/repos/:org/:repo/actions/runs/:id/jobs", + () => { + return HttpResponse.json({}, { status: 200 }); + }, + ), ); beforeAll(() => { From cee9ade41c4bddc9d8173940acb8f7114d768675 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Tue, 27 Aug 2024 11:21:36 -0300 Subject: [PATCH 15/39] update getPreSignedURL to support OIDC uploads --- .../utils/__tests__/getPreSignedURL.test.ts | 256 ++++++++++++++++-- .../src/utils/getPreSignedURL.ts | 54 ++-- 2 files changed, 266 insertions(+), 44 deletions(-) diff --git a/packages/bundler-plugin-core/src/utils/__tests__/getPreSignedURL.test.ts b/packages/bundler-plugin-core/src/utils/__tests__/getPreSignedURL.test.ts index 0cae4a12..487eb0cb 100644 --- a/packages/bundler-plugin-core/src/utils/__tests__/getPreSignedURL.test.ts +++ b/packages/bundler-plugin-core/src/utils/__tests__/getPreSignedURL.test.ts @@ -19,6 +19,22 @@ import { FailedFetchError } from "../../errors/FailedFetchError.ts"; import { NoUploadTokenError } from "../../errors/NoUploadTokenError.ts"; import { UploadLimitReachedError } from "../../errors/UploadLimitReachedError.ts"; import { UndefinedGitServiceError } from "../../errors/UndefinedGitServiceError.ts"; +import { Output } from "../Output.ts"; +import { BadOIDCServiceError } from "src/errors/BadOIDCServiceError.ts"; +import { FailedOIDCFetch } from "src/errors/FailedOIDCFetch.ts"; + +const mocks = vi.hoisted(() => ({ + getIDToken: vi.fn().mockReturnValue(""), +})); + +vi.mock("@actions/core", async (importOriginal) => { + // eslint-disable-next-line @typescript-eslint/consistent-type-imports + const original = await importOriginal(); + return { + ...original, + getIDToken: mocks.getIDToken, + }; +}); const server = setupServer(); @@ -40,16 +56,30 @@ interface SetupArgs { data?: object; retryCount?: number; sendError?: boolean; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + getIDTokenValue?: any; } describe("getPreSignedURL", () => { let consoleSpy: MockInstance; const requestBodyMock = vi.fn(); + const requestTokenMock = vi.fn(); const spawnSync = td.replace(childProcess, "spawnSync"); - function setup({ status = 200, data = {}, sendError = false }: SetupArgs) { + function setup({ + status = 200, + data = {}, + sendError = false, + getIDTokenValue, + }: SetupArgs) { consoleSpy = vi.spyOn(console, "log").mockImplementation(() => null); + if (getIDTokenValue instanceof Error) { + mocks.getIDToken.mockRejectedValue(getIDTokenValue); + } else { + mocks.getIDToken.mockReturnValue(getIDTokenValue); + } + server.use( http.post( "http://localhost/upload/bundle_analysis/v1", @@ -57,8 +87,14 @@ describe("getPreSignedURL", () => { if (sendError) { return HttpResponse.error(); } + const requestBody = await request.json(); requestBodyMock(requestBody); + + if (request.headers.get("Authorization")) { + requestTokenMock(request.headers.get("Authorization")); + } + return HttpResponse.json(data, { status }); }, ), @@ -82,12 +118,18 @@ describe("getPreSignedURL", () => { }); const url = await getPreSignedURL({ - apiURL: "http://localhost", - uploadToken: "super-cool-token", + output: new Output({ + apiUrl: "http://localhost", + uploadToken: "cool-upload-token", + debug: false, + bundleName: "test-bundle", + retryCount: 0, + enableBundleAnalysis: true, + dryRun: false, + }), serviceParams: { commit: "123", }, - retryCount: 0, }); expect(url).toEqual("http://example.com"); @@ -120,12 +162,18 @@ describe("getPreSignedURL", () => { }); const url = await getPreSignedURL({ - apiURL: "http://localhost", + output: new Output({ + apiUrl: "http://localhost", + debug: false, + bundleName: "test-bundle", + retryCount: 0, + enableBundleAnalysis: true, + dryRun: false, + }), serviceParams: { commit: "123", branch: "owner:branch", }, - retryCount: 0, }); expect(url).toEqual("http://example.com"); @@ -144,13 +192,19 @@ describe("getPreSignedURL", () => { }); const url = await getPreSignedURL({ - apiURL: "http://localhost", + output: new Output({ + apiUrl: "http://localhost", + debug: false, + bundleName: "test-bundle", + retryCount: 0, + enableBundleAnalysis: true, + dryRun: false, + gitService: "github_enterprise", + }), serviceParams: { commit: "123", branch: "owner:branch", }, - retryCount: 0, - gitService: "github_enterprise", }); expect(url).toEqual("http://example.com"); @@ -162,6 +216,37 @@ describe("getPreSignedURL", () => { }); }); }); + + describe("using oidc and github actions", () => { + it("returns the pre-signed URL", async () => { + setup({ + data: { url: "http://example.com" }, + getIDTokenValue: "cool-token", + }); + + const url = await getPreSignedURL({ + output: new Output({ + apiUrl: "http://localhost", + debug: false, + bundleName: "test-bundle", + retryCount: 0, + enableBundleAnalysis: true, + dryRun: false, + oidc: { + OIDCEndpoint: "http://localhost", + useGitHubOIDC: true, + }, + }), + serviceParams: { + commit: "123", + service: "github-actions", + }, + }); + + expect(url).toEqual("http://example.com"); + expect(requestTokenMock).toHaveBeenCalledWith("token cool-token"); + }); + }); }); }); @@ -176,12 +261,19 @@ describe("getPreSignedURL", () => { let error; try { await getPreSignedURL({ - apiURL: "http://localhost", + output: new Output({ + apiUrl: "http://localhost", + debug: false, + bundleName: "test-bundle", + retryCount: 0, + enableBundleAnalysis: true, + dryRun: false, + gitService: "github", + }), serviceParams: { commit: "123", branch: "main", }, - retryCount: 0, }); } catch (e) { error = e; @@ -224,12 +316,18 @@ describe("getPreSignedURL", () => { let error; try { await getPreSignedURL({ - apiURL: "http://localhost", + output: new Output({ + apiUrl: "http://localhost", + debug: false, + bundleName: "test-bundle", + retryCount: 0, + enableBundleAnalysis: true, + dryRun: false, + }), serviceParams: { commit: "123", branch: "owner:branch", }, - retryCount: 0, }); } catch (e) { error = e; @@ -255,12 +353,18 @@ describe("getPreSignedURL", () => { let error; try { await getPreSignedURL({ - apiURL: "http://localhost", - uploadToken: "cool-upload-token", + output: new Output({ + apiUrl: "http://localhost", + uploadToken: "cool-upload-token", + debug: false, + bundleName: "test-bundle", + retryCount: 0, + enableBundleAnalysis: true, + dryRun: false, + }), serviceParams: { commit: "123", }, - retryCount: 0, }); } catch (e) { error = e; @@ -281,12 +385,18 @@ describe("getPreSignedURL", () => { let error; try { await getPreSignedURL({ - apiURL: "http://localhost", - uploadToken: "super-cool-token", + output: new Output({ + apiUrl: "http://localhost", + uploadToken: "cool-upload-token", + debug: false, + bundleName: "test-bundle", + retryCount: 0, + enableBundleAnalysis: true, + dryRun: false, + }), serviceParams: { commit: "123", }, - retryCount: 0, }); } catch (e) { error = e; @@ -317,12 +427,18 @@ describe("getPreSignedURL", () => { let error; try { await getPreSignedURL({ - apiURL: "http://localhost", - uploadToken: "super-cool-token", + output: new Output({ + apiUrl: "http://localhost", + uploadToken: "cool-upload-token", + debug: false, + bundleName: "test-bundle", + retryCount: 0, + enableBundleAnalysis: true, + dryRun: false, + }), serviceParams: { commit: "123", }, - retryCount: 0, }); } catch (e) { error = e; @@ -343,12 +459,18 @@ describe("getPreSignedURL", () => { let error; try { await getPreSignedURL({ - apiURL: "http://localhost", - uploadToken: "super-cool-token", + output: new Output({ + apiUrl: "http://localhost", + uploadToken: "cool-upload-token", + debug: false, + bundleName: "test-bundle", + retryCount: 0, + enableBundleAnalysis: true, + dryRun: false, + }), serviceParams: { commit: "123", }, - retryCount: 0, }); } catch (e) { error = e; @@ -379,12 +501,18 @@ describe("getPreSignedURL", () => { let error; try { await getPreSignedURL({ - apiURL: "http://localhost", - uploadToken: "super-cool-token", + output: new Output({ + apiUrl: "http://localhost", + uploadToken: "cool-upload-token", + debug: false, + bundleName: "test-bundle", + retryCount: 0, + enableBundleAnalysis: true, + dryRun: false, + }), serviceParams: { commit: "123", }, - retryCount: 0, }); } catch (e) { error = e; @@ -394,5 +522,77 @@ describe("getPreSignedURL", () => { expect(error).toBeInstanceOf(FailedFetchError); }); }); + + describe("using oidc and not github actions", () => { + it("throws an error", async () => { + setup({ + data: { url: "http://example.com" }, + getIDTokenValue: "cool-token", + }); + + let error; + try { + await getPreSignedURL({ + output: new Output({ + apiUrl: "http://localhost", + debug: false, + bundleName: "test-bundle", + retryCount: 0, + enableBundleAnalysis: true, + dryRun: false, + oidc: { + OIDCEndpoint: "http://localhost", + useGitHubOIDC: true, + }, + }), + serviceParams: { + commit: "123", + service: "local", + }, + }); + } catch (e) { + error = e; + } + + expect(consoleSpy).toHaveBeenCalled(); + expect(error).toBeInstanceOf(BadOIDCServiceError); + }); + }); + + describe("using oidc and getIDToken fails", () => { + it("throws an error", async () => { + setup({ + data: { url: "http://example.com" }, + getIDTokenValue: new Error("Failed to get token"), + }); + + let error; + try { + await getPreSignedURL({ + output: new Output({ + apiUrl: "http://localhost", + debug: false, + bundleName: "test-bundle", + retryCount: 0, + enableBundleAnalysis: true, + dryRun: false, + oidc: { + OIDCEndpoint: "http://localhost", + useGitHubOIDC: true, + }, + }), + serviceParams: { + commit: "123", + service: "github-actions", + }, + }); + } catch (e) { + error = e; + } + + expect(consoleSpy).toHaveBeenCalled(); + expect(error).toBeInstanceOf(FailedOIDCFetch); + }); + }); }); }); diff --git a/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts b/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts index 6a092d5b..a7c21484 100644 --- a/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts +++ b/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts @@ -1,3 +1,4 @@ +import * as Core from "@actions/core"; import { z } from "zod"; import { FailedFetchError } from "../errors/FailedFetchError.ts"; import { UploadLimitReachedError } from "../errors/UploadLimitReachedError.ts"; @@ -9,13 +10,13 @@ import { preProcessBody } from "./preProcessBody.ts"; import { NoUploadTokenError } from "../errors/NoUploadTokenError.ts"; import { findGitService } from "./findGitService.ts"; import { UndefinedGitServiceError } from "../errors/UndefinedGitServiceError.ts"; +import { FailedOIDCFetch } from "src/errors/FailedOIDCFetch.ts"; +import { type Output } from "./Output.ts"; +import { BadOIDCServiceError } from "src/errors/BadOIDCServiceError.ts"; interface GetPreSignedURLArgs { - apiURL: string; - uploadToken?: string; serviceParams: Partial; - retryCount?: number; - gitService?: string; + output: Output; } type RequestBody = Record; @@ -24,14 +25,13 @@ const PreSignedURLSchema = z.object({ url: z.string(), }); +const API_ENDPOINT = "/upload/bundle_analysis/v1"; + export const getPreSignedURL = async ({ - apiURL, - uploadToken, serviceParams, - retryCount = DEFAULT_RETRY_COUNT, - gitService, + output, }: GetPreSignedURLArgs) => { - const url = `${apiURL}/upload/bundle_analysis/v1`; + let url = output.apiUrl; const headers = new Headers({ "Content-Type": "application/json", @@ -43,9 +43,9 @@ export const getPreSignedURL = async ({ * proper tokenless upload. * See: https://github.com/codecov/codecov-api/pull/741 */ - if (!uploadToken && serviceParams.branch?.includes(":")) { - if (gitService) { - requestBody.git_service = gitService; + if (!output.uploadToken && serviceParams.branch?.includes(":")) { + if (output.gitService) { + requestBody.git_service = output.gitService; } else { const foundGitService = findGitService(); if (!foundGitService || foundGitService === "") { @@ -55,8 +55,30 @@ export const getPreSignedURL = async ({ requestBody.git_service = foundGitService; } - } else if (uploadToken) { - headers.set("Authorization", `token ${uploadToken}`); + } else if (output.oidc?.useGitHubOIDC && Core) { + if (serviceParams?.service !== "github-actions") { + red("OIDC is only supported for GitHub Actions"); + throw new BadOIDCServiceError( + "OIDC is only supported for GitHub Actions", + ); + } + + url = output.oidc.OIDCEndpoint; + let token = ""; + try { + token = await Core.getIDToken(output.oidc.OIDCEndpoint); + } catch (err) { + if (err instanceof Error) { + red(`Failed to get OIDC token with url: ${url}. ${err.message}`); + throw new FailedOIDCFetch( + `Failed to get OIDC token with url: ${url}. ${err.message}`, + ); + } + } + + headers.set("Authorization", `token ${token}`); + } else if (output.uploadToken) { + headers.set("Authorization", `token ${output.uploadToken}`); } else { red("No upload token provided"); throw new NoUploadTokenError("No upload token provided"); @@ -65,8 +87,8 @@ export const getPreSignedURL = async ({ let response: Response; try { response = await fetchWithRetry({ - url, - retryCount, + url: `${url}${API_ENDPOINT}`, + retryCount: output.retryCount ?? DEFAULT_RETRY_COUNT, name: "`get-pre-signed-url`", requestData: { method: "POST", From 56ac030c170ee20208c70b7c4498bb0108186888 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Tue, 27 Aug 2024 11:22:02 -0300 Subject: [PATCH 16/39] update Output to store oidc values and pass this to getPreSignedURL --- packages/bundler-plugin-core/src/utils/Output.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/bundler-plugin-core/src/utils/Output.ts b/packages/bundler-plugin-core/src/utils/Output.ts index 2ed99fed..cc3a8de5 100644 --- a/packages/bundler-plugin-core/src/utils/Output.ts +++ b/packages/bundler-plugin-core/src/utils/Output.ts @@ -19,6 +19,10 @@ class Output { retryCount: number; enableBundleAnalysis: boolean; uploadToken?: string; + oidc?: { + useGitHubOIDC: boolean; + OIDCEndpoint: string; + }; debug: boolean; gitService?: ValidGitService; originalBundleName: string; @@ -61,6 +65,7 @@ class Output { this.debug = userOptions.debug; this.gitService = userOptions.gitService; this.originalBundleName = userOptions.bundleName; + this.oidc = userOptions.oidc; if (userOptions.uploadOverrides) { this.branch = userOptions.uploadOverrides.branch; @@ -143,11 +148,8 @@ class Output { let url = ""; try { url = await getPreSignedURL({ - apiURL: this?.apiUrl ?? "https://api.codecov.io", - uploadToken: this?.uploadToken, serviceParams: provider, - retryCount: this?.retryCount, - gitService: this?.gitService, + output: this, }); } catch (error) { return; From 0bb170fc33fd168ba801e114a3ce1960f6fe1fe0 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Wed, 28 Aug 2024 07:26:00 -0300 Subject: [PATCH 17/39] add in example oidc app --- .github/workflows/ci.yml | 6 ++ examples/oidc/.eslintrc.cjs | 18 +++++ examples/oidc/.gitignore | 24 +++++++ examples/oidc/README.md | 27 ++++++++ examples/oidc/index.html | 13 ++++ examples/oidc/package.json | 36 ++++++++++ examples/oidc/public/vite.svg | 1 + examples/oidc/src/App.css | 42 +++++++++++ examples/oidc/src/App.tsx | 44 ++++++++++++ .../IndexedLazyComponent.tsx | 7 ++ .../oidc/src/IndexedLazyComponent/index.ts | 1 + .../oidc/src/LazyComponent/LazyComponent.tsx | 14 ++++ examples/oidc/src/assets/react.svg | 1 + examples/oidc/src/index.css | 69 +++++++++++++++++++ examples/oidc/src/main.tsx | 10 +++ examples/oidc/src/vite-env.d.ts | 1 + examples/oidc/tsconfig.json | 25 +++++++ examples/oidc/tsconfig.node.json | 10 +++ examples/oidc/vite.config.ts | 28 ++++++++ packages/bundler-plugin-core/src/types.ts | 2 +- .../src/utils/getPreSignedURL.ts | 4 +- .../src/utils/normalizeOptions.ts | 1 + 22 files changed, 381 insertions(+), 3 deletions(-) create mode 100644 examples/oidc/.eslintrc.cjs create mode 100644 examples/oidc/.gitignore create mode 100644 examples/oidc/README.md create mode 100644 examples/oidc/index.html create mode 100644 examples/oidc/package.json create mode 100644 examples/oidc/public/vite.svg create mode 100644 examples/oidc/src/App.css create mode 100644 examples/oidc/src/App.tsx create mode 100644 examples/oidc/src/IndexedLazyComponent/IndexedLazyComponent.tsx create mode 100644 examples/oidc/src/IndexedLazyComponent/index.ts create mode 100644 examples/oidc/src/LazyComponent/LazyComponent.tsx create mode 100644 examples/oidc/src/assets/react.svg create mode 100644 examples/oidc/src/index.css create mode 100644 examples/oidc/src/main.tsx create mode 100644 examples/oidc/src/vite-env.d.ts create mode 100644 examples/oidc/tsconfig.json create mode 100644 examples/oidc/tsconfig.node.json create mode 100644 examples/oidc/vite.config.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f21fc3b4..c321bee8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -284,6 +284,7 @@ jobs: "next-js", "next-js-15", "nuxt", + "oidc", "remix", "rollup", "sveltekit", @@ -343,6 +344,8 @@ jobs: NEXT_API_URL: ${{ secrets.CODECOV_API_URL }} NUXT_UPLOAD_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }} NUXT_API_URL: ${{ secrets.CODECOV_API_URL }} + OIDC_UPLOAD_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }} + OIDC_API_URL: ${{ secrets.CODECOV_API_URL }} REMIX_UPLOAD_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }} REMIX_API_URL: ${{ secrets.CODECOV_API_URL }} ROLLUP_UPLOAD_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }} @@ -371,6 +374,7 @@ jobs: "next-js", "next-js-15", "nuxt", + "oidc", "remix", "rollup", "sveltekit", @@ -430,6 +434,8 @@ jobs: NEXT_API_URL: ${{ secrets.CODECOV_STAGING_API_URL }} NUXT_UPLOAD_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }} NUXT_API_URL: ${{ secrets.CODECOV_API_URL }} + OIDC_UPLOAD_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }} + OIDC_API_URL: ${{ secrets.CODECOV_API_URL }} REMIX_UPLOAD_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }} REMIX_API_URL: ${{ secrets.CODECOV_API_URL }} ROLLUP_UPLOAD_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN_STAGING }} diff --git a/examples/oidc/.eslintrc.cjs b/examples/oidc/.eslintrc.cjs new file mode 100644 index 00000000..d6c95379 --- /dev/null +++ b/examples/oidc/.eslintrc.cjs @@ -0,0 +1,18 @@ +module.exports = { + root: true, + env: { browser: true, es2020: true }, + extends: [ + 'eslint:recommended', + 'plugin:@typescript-eslint/recommended', + 'plugin:react-hooks/recommended', + ], + ignorePatterns: ['dist', '.eslintrc.cjs'], + parser: '@typescript-eslint/parser', + plugins: ['react-refresh'], + rules: { + 'react-refresh/only-export-components': [ + 'warn', + { allowConstantExport: true }, + ], + }, +} diff --git a/examples/oidc/.gitignore b/examples/oidc/.gitignore new file mode 100644 index 00000000..a547bf36 --- /dev/null +++ b/examples/oidc/.gitignore @@ -0,0 +1,24 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +dist +dist-ssr +*.local + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +.DS_Store +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? diff --git a/examples/oidc/README.md b/examples/oidc/README.md new file mode 100644 index 00000000..1ebe379f --- /dev/null +++ b/examples/oidc/README.md @@ -0,0 +1,27 @@ +# React + TypeScript + Vite + +This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. + +Currently, two official plugins are available: + +- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh +- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh + +## Expanding the ESLint configuration + +If you are developing a production application, we recommend updating the configuration to enable type aware lint rules: + +- Configure the top-level `parserOptions` property like this: + +```js + parserOptions: { + ecmaVersion: 'latest', + sourceType: 'module', + project: ['./tsconfig.json', './tsconfig.node.json'], + tsconfigRootDir: __dirname, + }, +``` + +- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked` +- Optionally add `plugin:@typescript-eslint/stylistic-type-checked` +- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list diff --git a/examples/oidc/index.html b/examples/oidc/index.html new file mode 100644 index 00000000..e4b78eae --- /dev/null +++ b/examples/oidc/index.html @@ -0,0 +1,13 @@ + + + + + + + Vite + React + TS + + +
+ + + diff --git a/examples/oidc/package.json b/examples/oidc/package.json new file mode 100644 index 00000000..73989417 --- /dev/null +++ b/examples/oidc/package.json @@ -0,0 +1,36 @@ +{ + "name": "@codecov/example-oidc-app", + "private": true, + "version": "0.0.0", + "type": "module", + "scripts": { + "dev": "vite", + "build": "tsc && vite build", + "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", + "preview": "vite preview" + }, + "dependencies": { + "react": "^18.2.0", + "react-dom": "^18.2.0" + }, + "devDependencies": { + "@codecov/vite-plugin": "workspace:^", + "@types/react": "^18.2.51", + "@types/react-dom": "^18.2.18", + "@typescript-eslint/eslint-plugin": "^6.20.0", + "@typescript-eslint/parser": "^6.20.0", + "@vitejs/plugin-react": "^4.2.1", + "eslint": "^8.56.0", + "eslint-plugin-react-hooks": "^4.6.0", + "eslint-plugin-react-refresh": "^0.4.5", + "rollup": "^4.9.6", + "typescript": "^5.3.3", + "vite": "^5.2.10" + }, + "volta": { + "extends": "../../package.json" + }, + "engines": { + "node": ">=18.0.0" + } +} diff --git a/examples/oidc/public/vite.svg b/examples/oidc/public/vite.svg new file mode 100644 index 00000000..e7b8dfb1 --- /dev/null +++ b/examples/oidc/public/vite.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/oidc/src/App.css b/examples/oidc/src/App.css new file mode 100644 index 00000000..b9d355df --- /dev/null +++ b/examples/oidc/src/App.css @@ -0,0 +1,42 @@ +#root { + max-width: 1280px; + margin: 0 auto; + padding: 2rem; + text-align: center; +} + +.logo { + height: 6em; + padding: 1.5em; + will-change: filter; + transition: filter 300ms; +} +.logo:hover { + filter: drop-shadow(0 0 2em #646cffaa); +} +.logo.react:hover { + filter: drop-shadow(0 0 2em #61dafbaa); +} + +@keyframes logo-spin { + from { + transform: rotate(0deg); + } + to { + transform: rotate(360deg); + } +} + +@media (prefers-reduced-motion: no-preference) { + a:nth-of-type(2) .logo { + animation: logo-spin infinite 20s linear; + } +} + +.card { + padding: 2em; +} + +.read-the-docs { + color: #888; +} diff --git a/examples/oidc/src/App.tsx b/examples/oidc/src/App.tsx new file mode 100644 index 00000000..345e0828 --- /dev/null +++ b/examples/oidc/src/App.tsx @@ -0,0 +1,44 @@ +import { useState, lazy, Suspense } from "react"; +import reactLogo from "./assets/react.svg"; +import viteLogo from "/vite.svg"; +import "./App.css"; + +const IndexedLazyComponent = lazy(() => import("./IndexedLazyComponent")); +const LazyComponent = lazy(() => import("./LazyComponent/LazyComponent")); + +function App() { + const [count, setCount] = useState(0); + + return ( + <> + +

Vite + React

+
+ +

+ Edit src/App.tsx and save to test HMR +

+
+

+ Click on the Vite and React logos to learn more +

+ + + + + + + + ); +} + +export default App; diff --git a/examples/oidc/src/IndexedLazyComponent/IndexedLazyComponent.tsx b/examples/oidc/src/IndexedLazyComponent/IndexedLazyComponent.tsx new file mode 100644 index 00000000..6686dc58 --- /dev/null +++ b/examples/oidc/src/IndexedLazyComponent/IndexedLazyComponent.tsx @@ -0,0 +1,7 @@ +export default function IndexedLazyComponent() { + return ( +
+

Indexed Lazy Component

+
+ ); +} diff --git a/examples/oidc/src/IndexedLazyComponent/index.ts b/examples/oidc/src/IndexedLazyComponent/index.ts new file mode 100644 index 00000000..1dd706b5 --- /dev/null +++ b/examples/oidc/src/IndexedLazyComponent/index.ts @@ -0,0 +1 @@ +export { default } from "./IndexedLazyComponent"; diff --git a/examples/oidc/src/LazyComponent/LazyComponent.tsx b/examples/oidc/src/LazyComponent/LazyComponent.tsx new file mode 100644 index 00000000..2a56c928 --- /dev/null +++ b/examples/oidc/src/LazyComponent/LazyComponent.tsx @@ -0,0 +1,14 @@ +import { lazy, Suspense } from "react"; + +const IndexedLazyComponent = lazy(() => import("../IndexedLazyComponent")); + +export default function LazyComponent() { + return ( +
+

Lazy Component

+ + + +
+ ); +} diff --git a/examples/oidc/src/assets/react.svg b/examples/oidc/src/assets/react.svg new file mode 100644 index 00000000..6c87de9b --- /dev/null +++ b/examples/oidc/src/assets/react.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/oidc/src/index.css b/examples/oidc/src/index.css new file mode 100644 index 00000000..2c3fac68 --- /dev/null +++ b/examples/oidc/src/index.css @@ -0,0 +1,69 @@ +:root { + font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; + line-height: 1.5; + font-weight: 400; + + color-scheme: light dark; + color: rgba(255, 255, 255, 0.87); + background-color: #242424; + + font-synthesis: none; + text-rendering: optimizeLegibility; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; + -webkit-text-size-adjust: 100%; +} + +a { + font-weight: 500; + color: #646cff; + text-decoration: inherit; +} +a:hover { + color: #535bf2; +} + +body { + margin: 0; + display: flex; + place-items: center; + min-width: 320px; + min-height: 100vh; +} + +h1 { + font-size: 3.2em; + line-height: 1.1; +} + +button { + border-radius: 8px; + border: 1px solid transparent; + padding: 0.6em 1.2em; + font-size: 1em; + font-weight: 500; + font-family: inherit; + background-color: #1a1a1a; + cursor: pointer; + transition: border-color 0.25s; +} +button:hover { + border-color: #646cff; +} +button:focus, +button:focus-visible { + outline: 4px auto -webkit-focus-ring-color; +} + +@media (prefers-color-scheme: light) { + :root { + color: #213547; + background-color: #ffffff; + } + a:hover { + color: #747bff; + } + button { + background-color: #f9f9f9; + } +} diff --git a/examples/oidc/src/main.tsx b/examples/oidc/src/main.tsx new file mode 100644 index 00000000..f25366e5 --- /dev/null +++ b/examples/oidc/src/main.tsx @@ -0,0 +1,10 @@ +import React from "react"; +import ReactDOM from "react-dom/client"; +import App from "./App.tsx"; +import "./index.css"; + +ReactDOM.createRoot(document.getElementById("root")!).render( + + + , +); diff --git a/examples/oidc/src/vite-env.d.ts b/examples/oidc/src/vite-env.d.ts new file mode 100644 index 00000000..11f02fe2 --- /dev/null +++ b/examples/oidc/src/vite-env.d.ts @@ -0,0 +1 @@ +/// diff --git a/examples/oidc/tsconfig.json b/examples/oidc/tsconfig.json new file mode 100644 index 00000000..de3bc503 --- /dev/null +++ b/examples/oidc/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "target": "ES2020", + "useDefineForClassFields": true, + "lib": ["ES2020", "DOM", "DOM.Iterable"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true, + }, + "include": ["src"], + "references": [{ "path": "./tsconfig.node.json" }], +} diff --git a/examples/oidc/tsconfig.node.json b/examples/oidc/tsconfig.node.json new file mode 100644 index 00000000..42872c59 --- /dev/null +++ b/examples/oidc/tsconfig.node.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "composite": true, + "skipLibCheck": true, + "module": "ESNext", + "moduleResolution": "bundler", + "allowSyntheticDefaultImports": true + }, + "include": ["vite.config.ts"] +} diff --git a/examples/oidc/vite.config.ts b/examples/oidc/vite.config.ts new file mode 100644 index 00000000..c28c0df7 --- /dev/null +++ b/examples/oidc/vite.config.ts @@ -0,0 +1,28 @@ +import { defineConfig } from "vite"; +import react from "@vitejs/plugin-react"; +import { codecovVitePlugin } from "@codecov/vite-plugin"; + +// https://vitejs.dev/config/ +export default defineConfig({ + build: { + rollupOptions: { + output: { + assetFileNames: "[name].[hash].js", + chunkFileNames: "[name]-[hash].js", + }, + }, + }, + plugins: [ + react(), + codecovVitePlugin({ + enableBundleAnalysis: true, + bundleName: "@codecov/example-oidc-app", + apiUrl: process.env.OIDC_API_URL, + gitService: "github", + oidc: { + useGitHubOIDC: true, + }, + debug: true, + }), + ], +}); diff --git a/packages/bundler-plugin-core/src/types.ts b/packages/bundler-plugin-core/src/types.ts index 2043802d..c505593f 100644 --- a/packages/bundler-plugin-core/src/types.ts +++ b/packages/bundler-plugin-core/src/types.ts @@ -154,7 +154,7 @@ export interface Options { * * Defaults to `https://codecov.io` */ - OIDCEndpoint: string; + OIDCEndpoint?: string; }; } diff --git a/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts b/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts index a7c21484..b94d09c0 100644 --- a/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts +++ b/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts @@ -10,9 +10,9 @@ import { preProcessBody } from "./preProcessBody.ts"; import { NoUploadTokenError } from "../errors/NoUploadTokenError.ts"; import { findGitService } from "./findGitService.ts"; import { UndefinedGitServiceError } from "../errors/UndefinedGitServiceError.ts"; -import { FailedOIDCFetch } from "src/errors/FailedOIDCFetch.ts"; +import { FailedOIDCFetch } from "../errors/FailedOIDCFetch.ts"; import { type Output } from "./Output.ts"; -import { BadOIDCServiceError } from "src/errors/BadOIDCServiceError.ts"; +import { BadOIDCServiceError } from "../errors/BadOIDCServiceError.ts"; interface GetPreSignedURLArgs { serviceParams: Partial; diff --git a/packages/bundler-plugin-core/src/utils/normalizeOptions.ts b/packages/bundler-plugin-core/src/utils/normalizeOptions.ts index 64e10365..fa3678e8 100644 --- a/packages/bundler-plugin-core/src/utils/normalizeOptions.ts +++ b/packages/bundler-plugin-core/src/utils/normalizeOptions.ts @@ -76,6 +76,7 @@ const OIDCSchema = (options: Options) => .url({ message: `OIDCEndpoint: \`${options?.oidc?.OIDCEndpoint}\` is not a valid URL.`, }) + .optional() .default("https://codecov.io"), }, { invalid_type_error: "`oidc` must be an object." }, From 369a83c0bc52db583b690eb131d4ee8f070bcecd Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Wed, 28 Aug 2024 07:54:03 -0300 Subject: [PATCH 18/39] update lock file with new example --- pnpm-lock.yaml | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7dc2eac4..a7622128 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -153,6 +153,52 @@ importers: specifier: workspace:^ version: link:../../packages/nuxt-plugin + examples/oidc: + dependencies: + react: + specifier: ^18.2.0 + version: 18.3.1 + react-dom: + specifier: ^18.2.0 + version: 18.3.1(react@18.3.1) + devDependencies: + '@codecov/vite-plugin': + specifier: workspace:^ + version: link:../../packages/vite-plugin + '@types/react': + specifier: ^18.2.51 + version: 18.3.3 + '@types/react-dom': + specifier: ^18.2.18 + version: 18.3.0 + '@typescript-eslint/eslint-plugin': + specifier: ^6.20.0 + version: 6.20.0(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.4.5))(eslint@8.56.0)(typescript@5.4.5) + '@typescript-eslint/parser': + specifier: ^6.20.0 + version: 6.20.0(eslint@8.56.0)(typescript@5.4.5) + '@vitejs/plugin-react': + specifier: ^4.2.1 + version: 4.2.1(vite@5.2.10(@types/node@20.12.12)(terser@5.27.0)) + eslint: + specifier: ^8.56.0 + version: 8.56.0 + eslint-plugin-react-hooks: + specifier: ^4.6.0 + version: 4.6.0(eslint@8.56.0) + eslint-plugin-react-refresh: + specifier: ^0.4.5 + version: 0.4.5(eslint@8.56.0) + rollup: + specifier: ^4.9.6 + version: 4.9.6 + typescript: + specifier: ^5.3.3 + version: 5.4.5 + vite: + specifier: ^5.2.10 + version: 5.2.10(@types/node@20.12.12)(terser@5.27.0) + examples/remix: dependencies: '@remix-run/node': From b5236a4beaf1528d72cd6bc44ecb366b46ba5dc7 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Wed, 28 Aug 2024 08:47:55 -0300 Subject: [PATCH 19/39] add in quotes to make url more apparent --- packages/bundler-plugin-core/src/utils/getPreSignedURL.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts b/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts index b94d09c0..52cfb42c 100644 --- a/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts +++ b/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts @@ -69,9 +69,9 @@ export const getPreSignedURL = async ({ token = await Core.getIDToken(output.oidc.OIDCEndpoint); } catch (err) { if (err instanceof Error) { - red(`Failed to get OIDC token with url: ${url}. ${err.message}`); + red(`Failed to get OIDC token with url:\`${url}\`. ${err.message}`); throw new FailedOIDCFetch( - `Failed to get OIDC token with url: ${url}. ${err.message}`, + `Failed to get OIDC token with url: \`${url}\`. ${err.message}`, ); } } From 513a73961739c6dc220500ed6698a654a7dab948 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Wed, 28 Aug 2024 08:52:24 -0300 Subject: [PATCH 20/39] testing with id-token permission --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c321bee8..495456ea 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,6 +11,9 @@ concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} cancel-in-progress: true +permissions: + id-token: write + jobs: install: name: Install deps From 63ac370bc50d88ea65ccd7e161d517e19f8965f3 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Tue, 3 Sep 2024 10:02:54 -0300 Subject: [PATCH 21/39] add in example for GH OIDC --- packages/nextjs-webpack-plugin/README.md | 26 ++++++++++ packages/nuxt-plugin/README.md | 63 ++--------------------- packages/remix-vite-plugin/README.md | 61 ++-------------------- packages/rollup-plugin/README.md | 53 ++----------------- packages/solidstart-plugin/README.md | 61 ++-------------------- packages/sveltekit-plugin/README.md | 57 ++------------------- packages/vite-plugin/README.md | 32 ++---------- packages/webpack-plugin/README.md | 65 ++---------------------- 8 files changed, 54 insertions(+), 364 deletions(-) diff --git a/packages/nextjs-webpack-plugin/README.md b/packages/nextjs-webpack-plugin/README.md index 2f49b4aa..3a99c5cc 100644 --- a/packages/nextjs-webpack-plugin/README.md +++ b/packages/nextjs-webpack-plugin/README.md @@ -110,6 +110,32 @@ export default { }; ``` +## OIDC Configuration Example + +For users with [OpenID Connect(OIDC) enabled](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect), setting the `uploadToken` is not necessary. You can use OIDC with the `oidc` configuration as following. + +```typescript +// next.config.mjs +import { codecovNextJSWebpackPlugin } from "@codecov/nextjs-webpack-plugin"; + +export default { + webpack: (config, options) => { + config.plugins.push( + codecovNextJSWebpackPlugin({ + enableBundleAnalysis: true, + bundleName: "example-nextjs-webpack-bundle", + webpack: options.webpack, + oidc: { + useGitHubOIDC: true, + }, + }), + ); + + return config; + }, +}; +``` + ## More information - [NextJS Config Docs](https://nextjs.org/docs/app/api-reference/next-config-js) diff --git a/packages/nuxt-plugin/README.md b/packages/nuxt-plugin/README.md index 49925485..1512e998 100644 --- a/packages/nuxt-plugin/README.md +++ b/packages/nuxt-plugin/README.md @@ -119,9 +119,9 @@ export default defineNuxtConfig({ }); ``` -## Tokenless Example +## OIDC Configuration Example -This configuration will automatically upload the bundle analysis to Codecov for public repositories. When an internal PR is created it will use the Codecov token set in your secrets, and if running from a forked PR, it will use the tokenless setting automatically. For setups not using GitHub Actions see the following [example](#public-repo-example---non-github-actions). For private repositories see the following [example](#private-repo-example). +For users with [OpenID Connect(OIDC) enabled](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect), setting the `uploadToken` is not necessary. You can use OIDC with the `oidc` configuration as following. ```typescript // nuxt.config.ts @@ -138,37 +138,8 @@ export default defineNuxtConfig({ { enableBundleAnalysis: true, bundleName: "nuxt-bundle-analysis", - uploadToken: process.env.CODECOV_UPLOAD_TOKEN, - gitService: "github", - }, - ], - ], -}); -``` - -## Public Repo Example - Non-GitHub Actions - -This setup is for public repositories that are not using GitHub Actions, this configuration will automatically upload the bundle analysis to Codecov. You will need to configure the it similar to the GitHub Actions example, however you will need to provide a branch override, and ensure that it will pass the correct branch name, and with forks including the fork-owner i.e. `fork-owner:branch`. - -```typescript -// nuxt.config.ts -import { defineNuxtConfig } from "nuxt/config"; - -export default defineNuxtConfig({ - devtools: { enabled: true }, - // Ensure that the builder is set to "vite" - builder: "vite", - // Ensure that the plugin is added to the modules array - modules: [ - [ - "@codecov/nuxt-plugin", - { - enableBundleAnalysis: true, - bundleName: "nuxt-bundle-analysis", - uploadToken: process.env.CODECOV_UPLOAD_TOKEN, - gitService: "github", - uploadOverrides: { - branch: "", + oidc: { + useGitHubOIDC: true, }, }, ], @@ -176,32 +147,6 @@ export default defineNuxtConfig({ }); ``` -## Private Repo Example - -This is the required way to use the plugin for private repositories. This configuration will automatically upload the bundle analysis to Codecov. - -```typescript -// nuxt.config.ts -import { defineNuxtConfig } from "nuxt/config"; - -export default defineNuxtConfig({ - devtools: { enabled: true }, - // Ensure that the builder is set to "vite" - builder: "vite", - // Ensure that the plugin is added to the modules array - modules: [ - [ - "@codecov/nuxt-plugin", - { - enableBundleAnalysis: true, - bundleName: "nuxt-bundle-analysis", - uploadToken: process.env.CODECOV_UPLOAD_TOKEN, - }, - ], - ], -}); -``` - ## More information - [Codecov Documentation](https://docs.codecov.com/docs) diff --git a/packages/remix-vite-plugin/README.md b/packages/remix-vite-plugin/README.md index cf280954..c84f270c 100644 --- a/packages/remix-vite-plugin/README.md +++ b/packages/remix-vite-plugin/README.md @@ -116,35 +116,9 @@ export default defineConfig({ }); ``` -## Tokenless Example +## OIDC Configuration Example -This configuration will automatically upload the bundle analysis to Codecov for public repositories. When an internal PR is created it will use the Codecov token set in your secrets, and if running from a forked PR, it will use the tokenless setting automatically. For setups not using GitHub Actions see the following [example](#public-repo-example---non-github-actions). For private repositories see the following [example](#private-repo-example). - -```ts -// vite.config.ts -import { vitePlugin as remix } from "@remix-run/dev"; -import { defineConfig } from "vite"; -import tsconfigPaths from "vite-tsconfig-paths"; -import { codecovRemixPlugin } from "@codecov/remix-vite-plugin"; - -export default defineConfig({ - plugins: [ - remix(), - tsconfigPaths() - // Put the Codecov Remix plugin after all other plugins - codecovRemixPlugin({ - enableBundleAnalysis: true, - bundleName: "example-remix-bundle", - uploadToken: process.env.CODECOV_TOKEN, - gitService: "github", - }), - ], -}); -``` - -## Public Repo Example - Non-GitHub Actions - -This setup is for public repositories that are not using GitHub Actions, this configuration will automatically upload the bundle analysis to Codecov. You will need to configure the it similar to the GitHub Actions example, however you will need to provide a branch override, and ensure that it will pass the correct branch name, and with forks including the fork-owner i.e. `fork-owner:branch`. +For users with [OpenID Connect(OIDC) enabled](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect), setting the `uploadToken` is not necessary. You can use OIDC with the `oidc` configuration as following. ```ts // vite.config.ts @@ -161,41 +135,14 @@ export default defineConfig({ codecovRemixPlugin({ enableBundleAnalysis: true, bundleName: "example-remix-bundle", - uploadToken: process.env.CODECOV_TOKEN, - gitService: "github", - uploadOverrides: { - branch: "", + oidc: { + useGitHubOIDC: true, }, }), ], }); ``` -## Private Repo Example - -This is the required way to use the plugin for private repositories. This configuration will automatically upload the bundle analysis to Codecov. - -```ts -// vite.config.ts -import { vitePlugin as remix } from "@remix-run/dev"; -import { defineConfig } from "vite"; -import tsconfigPaths from "vite-tsconfig-paths"; -import { codecovRemixPlugin } from "@codecov/remix-vite-plugin"; - -export default defineConfig({ - plugins: [ - remix(), - tsconfigPaths() - // Put the Codecov Remix plugin after all other plugins - codecovRemixPlugin({ - enableBundleAnalysis: true, - bundleName: "example-remix-bundle", - uploadToken: process.env.CODECOV_TOKEN, - }), - ], -}); -``` - ## More information - [Codecov Documentation](https://docs.codecov.com/docs) diff --git a/packages/rollup-plugin/README.md b/packages/rollup-plugin/README.md index 54129a3a..31c43141 100644 --- a/packages/rollup-plugin/README.md +++ b/packages/rollup-plugin/README.md @@ -101,31 +101,9 @@ export default defineConfig({ }); ``` -## Tokenless Example +## OIDC Configuration Example -This configuration will automatically upload the bundle analysis to Codecov for public repositories. When an internal PR is created it will use the Codecov token set in your secrets, and if running from a forked PR, it will use the tokenless setting automatically. For setups not using GitHub Actions see the following [example](#public-repo-example---non-github-actions). For private repositories see the following [example](#private-repo-example). - -```js -// rollup.config.js -import { defineConfig } from "rollup"; -import { codecovRollupPlugin } from "@codecov/rollup-plugin"; - -export default defineConfig({ - plugins: [ - // Put the Codecov rollup plugin after all other plugins - codecovRollupPlugin({ - enableBundleAnalysis: true, - bundleName: "example-rollup-bundle", - uploadToken: process.env.CODECOV_TOKEN, - gitService: "github", - }), - ], -}); -``` - -## Public Repo Example - Non-GitHub Actions - -This setup is for public repositories that are not using GitHub Actions, this configuration will automatically upload the bundle analysis to Codecov. You will need to configure the it similar to the GitHub Actions example, however you will need to provide a branch override, and ensure that it will pass the correct branch name, and with forks including the fork-owner i.e. `fork-owner:branch`. +For users with [OpenID Connect(OIDC) enabled](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect), setting the `uploadToken` is not necessary. You can use OIDC with the `oidc` configuration as following. ```js // rollup.config.js @@ -138,37 +116,14 @@ export default defineConfig({ codecovRollupPlugin({ enableBundleAnalysis: true, bundleName: "example-rollup-bundle", - uploadToken: process.env.CODECOV_TOKEN, - gitService: "github", - uploadOverrides: { - branch: "", + oidc: { + useGitHubOIDC: true, }, }), ], }); ``` -## Private Repo Example - -This is the required way to use the plugin for private repositories. This configuration will automatically upload the bundle analysis to Codecov. - -```js -// rollup.config.js -import { defineConfig } from "rollup"; -import { codecovRollupPlugin } from "@codecov/rollup-plugin"; - -export default defineConfig({ - plugins: [ - // Put the Codecov rollup plugin after all other plugins - codecovRollupPlugin({ - enableBundleAnalysis: true, - bundleName: "example-rollup-bundle", - uploadToken: process.env.CODECOV_TOKEN, - }), - ], -}); -``` - ## More information - [Rollup Config Docs](https://codecov.github.io/codecov-javascript-bundler-plugins/modules/_codecov_rollup_plugin.html) diff --git a/packages/solidstart-plugin/README.md b/packages/solidstart-plugin/README.md index 1348405c..6c25d2f4 100644 --- a/packages/solidstart-plugin/README.md +++ b/packages/solidstart-plugin/README.md @@ -116,35 +116,9 @@ export default defineConfig({ }); ``` -## Tokenless Example +## OIDC Configuration Example -This configuration will automatically upload the bundle analysis to Codecov for public repositories. When an internal PR is created it will use the Codecov token set in your secrets, and if running from a forked PR, it will use the tokenless setting automatically. For setups not using GitHub Actions see the following [example](#public-repo-example---non-github-actions). For private repositories see the following [example](#private-repo-example). - -```ts -// app.config.ts -import { defineConfig } from "@solidjs/start/config"; -import solidPlugin from "vite-plugin-solid"; -import { codecovSolidStartPlugin } from "@codecov/solidstart-plugin"; - -export default defineConfig({ - vite: { - plugins: [ - // Put the Codecov SolidStart plugin after all other plugins - solidPlugin(), - codecovSolidStartPlugin({ - enableBundleAnalysis: true, - bundleName: "example-solidstart-bundle", - uploadToken: process.env.CODECOV_TOKEN, - gitService: "github", - }), - ], - }, -}); -``` - -## Public Repo Example - Non-GitHub Actions - -This setup is for public repositories that are not using GitHub Actions, this configuration will automatically upload the bundle analysis to Codecov. You will need to configure the it similar to the GitHub Actions example, however you will need to provide a branch override, and ensure that it will pass the correct branch name, and with forks including the fork-owner i.e. `fork-owner:branch`. +For users with [OpenID Connect(OIDC) enabled](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect), setting the `uploadToken` is not necessary. You can use OIDC with the `oidc` configuration as following. ```ts // app.config.ts @@ -160,10 +134,8 @@ export default defineConfig({ codecovSolidStartPlugin({ enableBundleAnalysis: true, bundleName: "example-solidstart-bundle", - uploadToken: process.env.CODECOV_TOKEN, - gitService: "github", - uploadOverrides: { - branch: "", + oidc: { + useGitHubOIDC: true, }, }), ], @@ -171,31 +143,6 @@ export default defineConfig({ }); ``` -## Private Repo Example - -This is the required way to use the plugin for private repositories. This configuration will automatically upload the bundle analysis to Codecov. - -```ts -// app.config.ts -import { defineConfig } from "@solidjs/start/config"; -import solidPlugin from "vite-plugin-solid"; -import { codecovSolidStartPlugin } from "@codecov/solidstart-plugin"; - -export default defineConfig({ - vite: { - plugins: [ - // Put the Codecov SolidStart plugin after all other plugins - solidPlugin(), - codecovSolidStartPlugin({ - enableBundleAnalysis: true, - bundleName: "example-solidstart-bundle", - uploadToken: process.env.CODECOV_TOKEN, - }), - ], - }, -}); -``` - ## More information - [Codecov Documentation](https://docs.codecov.com/docs) diff --git a/packages/sveltekit-plugin/README.md b/packages/sveltekit-plugin/README.md index b5157aa9..36f7ad4a 100644 --- a/packages/sveltekit-plugin/README.md +++ b/packages/sveltekit-plugin/README.md @@ -110,33 +110,9 @@ export default defineConfig({ }); ``` -## Tokenless Example +## OIDC Configuration Example -This configuration will automatically upload the bundle analysis to Codecov for public repositories. When an internal PR is created it will use the Codecov token set in your secrets, and if running from a forked PR, it will use the tokenless setting automatically. For setups not using GitHub Actions see the following [example](#public-repo-example---non-github-actions). For private repositories see the following [example](#private-repo-example). - -```ts -// vite.config.ts -import { sveltekit } from "@sveltejs/kit/vite"; -import { defineConfig } from "vite"; -import { codecovSvelteKitPlugin } from "@codecov/sveltekit-plugin"; - -export default defineConfig({ - plugins: [ - sveltekit(), - // Put the Codecov SvelteKit plugin after all other plugins - codecovSvelteKitPlugin({ - enableBundleAnalysis: true, - bundleName: "example-sveltekit-bundle", - uploadToken: process.env.CODECOV_TOKEN, - gitService: "github", - }), - ], -}); -``` - -## Public Repo Example - Non-GitHub Actions - -This setup is for public repositories that are not using GitHub Actions, this configuration will automatically upload the bundle analysis to Codecov. You will need to configure the it similar to the GitHub Actions example, however you will need to provide a branch override, and ensure that it will pass the correct branch name, and with forks including the fork-owner i.e. `fork-owner:branch`. +For users with [OpenID Connect(OIDC) enabled](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect), setting the `uploadToken` is not necessary. You can use OIDC with the `oidc` configuration as following. ```ts // vite.config.ts @@ -151,39 +127,14 @@ export default defineConfig({ codecovSvelteKitPlugin({ enableBundleAnalysis: true, bundleName: "example-sveltekit-bundle", - uploadToken: process.env.CODECOV_TOKEN, - gitService: "github", - uploadOverrides: { - branch: "", + oidc: { + useGitHubOIDC: true, }, }), ], }); ``` -## Private Repo Example - -This is the required way to use the plugin for private repositories. This configuration will automatically upload the bundle analysis to Codecov. - -```ts -// vite.config.ts -import { sveltekit } from "@sveltejs/kit/vite"; -import { defineConfig } from "vite"; -import { codecovSvelteKitPlugin } from "@codecov/sveltekit-plugin"; - -export default defineConfig({ - plugins: [ - sveltekit(), - // Put the Codecov SvelteKit plugin after all other plugins - codecovSvelteKitPlugin({ - enableBundleAnalysis: true, - bundleName: "example-sveltekit-bundle", - uploadToken: process.env.CODECOV_TOKEN, - }), - ], -}); -``` - ## More information - [Codecov Documentation](https://docs.codecov.com/docs) diff --git a/packages/vite-plugin/README.md b/packages/vite-plugin/README.md index 02861c50..102b5b12 100644 --- a/packages/vite-plugin/README.md +++ b/packages/vite-plugin/README.md @@ -98,15 +98,14 @@ export default defineConfig({ enableBundleAnalysis: true, bundleName: "example-vite-bundle", uploadToken: process.env.CODECOV_TOKEN, - gitService: "github", }), ], }); ``` -## Public Repo Example - Non-GitHub Actions +## OIDC Configuration Example -This setup is for public repositories that are not using GitHub Actions, this configuration will automatically upload the bundle analysis to Codecov. You will need to configure the it similar to the GitHub Actions example, however you will need to provide a branch override, and ensure that it will pass the correct branch name, and with forks including the fork-owner i.e. `fork-owner:branch`. +For users with [OpenID Connect(OIDC) enabled](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect), setting the `uploadToken` is not necessary. You can use OIDC with the `oidc` configuration as following. ```js // vite.config.js @@ -119,37 +118,14 @@ export default defineConfig({ codecovVitePlugin({ enableBundleAnalysis: true, bundleName: "example-vite-bundle", - uploadToken: process.env.CODECOV_TOKEN, - gitService: "github", - uploadOverrides: { - branch: "", + oidc: { + useGitHubOIDC: true, }, }), ], }); ``` -## Private Repo Example - -This is the required way to use the plugin for private repositories. This configuration will automatically upload the bundle analysis to Codecov. - -```js -// vite.config.js -import { defineConfig } from "vite"; -import { codecovVitePlugin } from "@codecov/vite-plugin"; - -export default defineConfig({ - plugins: [ - // Put the Codecov vite plugin after all other plugins - codecovVitePlugin({ - enableBundleAnalysis: true, - bundleName: "example-vite-bundle", - uploadToken: process.env.CODECOV_TOKEN, - }), - ], -}); -``` - ## More information - [Vite Config Docs](https://codecov.github.io/codecov-javascript-bundler-plugins/modules/_codecov_vite_plugin.html) diff --git a/packages/webpack-plugin/README.md b/packages/webpack-plugin/README.md index dcfec3c0..5654d85d 100644 --- a/packages/webpack-plugin/README.md +++ b/packages/webpack-plugin/README.md @@ -119,37 +119,9 @@ module.exports = { }; ``` -## Tokenless Example +## OIDC Configuration Example -This configuration will automatically upload the bundle analysis to Codecov for public repositories. When an internal PR is created it will use the Codecov token set in your secrets, and if running from a forked PR, it will use the tokenless setting automatically. For setups not using GitHub Actions see the following [example](#public-repo-example---non-github-actions). For private repositories see the following [example](#private-repo-example). - -```js -// webpack.config.js -const path = require("path"); -const { codecovWebpackPlugin } = require("@codecov/webpack-plugin"); - -module.exports = { - entry: "./src/index.js", - mode: "production", - output: { - filename: "main.js", - path: path.resolve(__dirname, "dist"), - }, - plugins: [ - // Put the Codecov vite plugin after all other plugins - codecovWebpackPlugin({ - enableBundleAnalysis: true, - bundleName: "example-webpack-bundle", - uploadToken: process.env.CODECOV_TOKEN, - gitService: "github", - }), - ], -}; -``` - -## Public Repo Example - Non-GitHub Actions - -This setup is for public repositories that are not using GitHub Actions, this configuration will automatically upload the bundle analysis to Codecov. You will need to configure the it similar to the GitHub Actions example, however you will need to provide a branch override, and ensure that it will pass the correct branch name, and with forks including the fork-owner i.e. `fork-owner:branch`. +For users with [OpenID Connect(OIDC) enabled](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect), setting the `uploadToken` is not necessary. You can use OIDC with the `oidc` configuration as following. ```js // webpack.config.js @@ -168,43 +140,14 @@ module.exports = { codecovWebpackPlugin({ enableBundleAnalysis: true, bundleName: "example-webpack-bundle", - uploadToken: process.env.CODECOV_TOKEN, - gitService: "github", - uploadOverrides: { - branch: "", + oidc: { + useGitHubOIDC: true, }, }), ], }; ``` -## Private Repo Example - -This is the required way to use the plugin for private repositories. This configuration will automatically upload the bundle analysis to Codecov. - -```js -// webpack.config.js -const path = require("path"); -const { codecovWebpackPlugin } = require("@codecov/webpack-plugin"); - -module.exports = { - entry: "./src/index.js", - mode: "production", - output: { - filename: "main.js", - path: path.resolve(__dirname, "dist"), - }, - plugins: [ - // Put the Codecov vite plugin after all other plugins - codecovWebpackPlugin({ - enableBundleAnalysis: true, - bundleName: "example-webpack-bundle", - uploadToken: process.env.CODECOV_TOKEN, - }), - ], -}; -``` - ## More information - [Webpack Config Docs](https://codecov.github.io/codecov-javascript-bundler-plugins/modules/_codecov_webpack_plugin.html) From 9579a4af45f7c67b49925ae92627cb04e689bbb5 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Tue, 3 Sep 2024 10:05:03 -0300 Subject: [PATCH 22/39] add in changeset --- .changeset/lucky-seals-admire.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .changeset/lucky-seals-admire.md diff --git a/.changeset/lucky-seals-admire.md b/.changeset/lucky-seals-admire.md new file mode 100644 index 00000000..38f10eec --- /dev/null +++ b/.changeset/lucky-seals-admire.md @@ -0,0 +1,13 @@ +--- +"@codecov/nextjs-webpack-plugin": minor +"@codecov/bundler-plugin-core": minor +"@codecov/remix-vite-plugin": minor +"@codecov/solidstart-plugin": minor +"@codecov/sveltekit-plugin": minor +"@codecov/webpack-plugin": minor +"@codecov/rollup-plugin": minor +"@codecov/nuxt-plugin": minor +"@codecov/vite-plugin": minor +--- + +Add the ability for users to use GH OIDC instead of explicit upload tokens From bb4e1e93be9dfaf17e82ecb114751cf0349baf28 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Thu, 5 Sep 2024 07:12:19 -0300 Subject: [PATCH 23/39] remove redundent tokens from ci --- .github/workflows/ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 495456ea..35b1f423 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -347,7 +347,6 @@ jobs: NEXT_API_URL: ${{ secrets.CODECOV_API_URL }} NUXT_UPLOAD_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }} NUXT_API_URL: ${{ secrets.CODECOV_API_URL }} - OIDC_UPLOAD_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }} OIDC_API_URL: ${{ secrets.CODECOV_API_URL }} REMIX_UPLOAD_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }} REMIX_API_URL: ${{ secrets.CODECOV_API_URL }} @@ -437,7 +436,6 @@ jobs: NEXT_API_URL: ${{ secrets.CODECOV_STAGING_API_URL }} NUXT_UPLOAD_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }} NUXT_API_URL: ${{ secrets.CODECOV_API_URL }} - OIDC_UPLOAD_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }} OIDC_API_URL: ${{ secrets.CODECOV_API_URL }} REMIX_UPLOAD_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }} REMIX_API_URL: ${{ secrets.CODECOV_API_URL }} From dc26415f2c2f1ac3395de00c60d2dadb8edb9a55 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Thu, 5 Sep 2024 07:15:21 -0300 Subject: [PATCH 24/39] remove reassignment of url --- packages/bundler-plugin-core/src/utils/getPreSignedURL.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts b/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts index 52cfb42c..31dbbc8c 100644 --- a/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts +++ b/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts @@ -63,15 +63,16 @@ export const getPreSignedURL = async ({ ); } - url = output.oidc.OIDCEndpoint; let token = ""; try { token = await Core.getIDToken(output.oidc.OIDCEndpoint); } catch (err) { if (err instanceof Error) { - red(`Failed to get OIDC token with url:\`${url}\`. ${err.message}`); + red( + `Failed to get OIDC token with url:\`${output.oidc.OIDCEndpoint}\`. ${err.message}`, + ); throw new FailedOIDCFetch( - `Failed to get OIDC token with url: \`${url}\`. ${err.message}`, + `Failed to get OIDC token with url: \`${output.oidc.OIDCEndpoint}\`. ${err.message}`, ); } } From 9230d801fad5cc0ed73cbcd8bfdc5e4714e7e299 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Thu, 5 Sep 2024 07:18:31 -0300 Subject: [PATCH 25/39] rename ODICEndpoint to be github audience --- packages/bundler-plugin-core/src/types.ts | 2 +- packages/bundler-plugin-core/src/utils/Output.ts | 2 +- .../src/utils/__tests__/getPreSignedURL.test.ts | 6 +++--- .../src/utils/__tests__/normalizeOptions.test.ts | 14 +++++++------- .../src/utils/getPreSignedURL.ts | 6 +++--- .../src/utils/normalizeOptions.ts | 6 +++--- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/packages/bundler-plugin-core/src/types.ts b/packages/bundler-plugin-core/src/types.ts index c505593f..3b13364b 100644 --- a/packages/bundler-plugin-core/src/types.ts +++ b/packages/bundler-plugin-core/src/types.ts @@ -154,7 +154,7 @@ export interface Options { * * Defaults to `https://codecov.io` */ - OIDCEndpoint?: string; + gitHubOIDCTokenAudience?: string; }; } diff --git a/packages/bundler-plugin-core/src/utils/Output.ts b/packages/bundler-plugin-core/src/utils/Output.ts index cc3a8de5..5d55c939 100644 --- a/packages/bundler-plugin-core/src/utils/Output.ts +++ b/packages/bundler-plugin-core/src/utils/Output.ts @@ -21,7 +21,7 @@ class Output { uploadToken?: string; oidc?: { useGitHubOIDC: boolean; - OIDCEndpoint: string; + gitHubOIDCTokenAudience: string; }; debug: boolean; gitService?: ValidGitService; diff --git a/packages/bundler-plugin-core/src/utils/__tests__/getPreSignedURL.test.ts b/packages/bundler-plugin-core/src/utils/__tests__/getPreSignedURL.test.ts index 487eb0cb..1ad71c49 100644 --- a/packages/bundler-plugin-core/src/utils/__tests__/getPreSignedURL.test.ts +++ b/packages/bundler-plugin-core/src/utils/__tests__/getPreSignedURL.test.ts @@ -233,7 +233,7 @@ describe("getPreSignedURL", () => { enableBundleAnalysis: true, dryRun: false, oidc: { - OIDCEndpoint: "http://localhost", + gitHubOIDCTokenAudience: "http://localhost", useGitHubOIDC: true, }, }), @@ -541,7 +541,7 @@ describe("getPreSignedURL", () => { enableBundleAnalysis: true, dryRun: false, oidc: { - OIDCEndpoint: "http://localhost", + gitHubOIDCTokenAudience: "http://localhost", useGitHubOIDC: true, }, }), @@ -577,7 +577,7 @@ describe("getPreSignedURL", () => { enableBundleAnalysis: true, dryRun: false, oidc: { - OIDCEndpoint: "http://localhost", + gitHubOIDCTokenAudience: "http://localhost", useGitHubOIDC: true, }, }), diff --git a/packages/bundler-plugin-core/src/utils/__tests__/normalizeOptions.test.ts b/packages/bundler-plugin-core/src/utils/__tests__/normalizeOptions.test.ts index e65f0d2b..faaf43dc 100644 --- a/packages/bundler-plugin-core/src/utils/__tests__/normalizeOptions.test.ts +++ b/packages/bundler-plugin-core/src/utils/__tests__/normalizeOptions.test.ts @@ -64,7 +64,7 @@ const tests: Test[] = [ gitService: "bitbucket", oidc: { useGitHubOIDC: true, - OIDCEndpoint: "https://codecov.io", + gitHubOIDCTokenAudience: "https://codecov.io", }, }, }, @@ -89,7 +89,7 @@ const tests: Test[] = [ gitService: "bitbucket", oidc: { useGitHubOIDC: true, - OIDCEndpoint: "https://codecov.io", + gitHubOIDCTokenAudience: "https://codecov.io", }, }, }, @@ -132,7 +132,7 @@ const tests: Test[] = [ // @ts-expect-error - testing invalid input useGitHubOIDC: "true", // @ts-expect-error - testing invalid input - OIDCEndpoint: 123, + gitHubOIDCTokenAudience: 123, }, }, }, @@ -154,7 +154,7 @@ const tests: Test[] = [ "`debug` must be a boolean.", "`gitService` must be a valid git service.", "`useGitHubOIDC` must be a boolean.", - "`OIDCEndpoint` must be a string.", + "`gitHubOIDCTokenAudience` must be a string.", ], }, }, @@ -226,19 +226,19 @@ const tests: Test[] = [ }, }, { - name: "OIDCEndpoint does not match URL format, returns format error message", + name: "gitHubOIDCTokenAudience does not match URL format, returns format error message", input: { options: { oidc: { useGitHubOIDC: true, - OIDCEndpoint: "invalid-url", + gitHubOIDCTokenAudience: "invalid-url", }, bundleName: "test-bundle", }, }, expected: { success: false, - errors: ["OIDCEndpoint: `invalid-url` is not a valid URL."], + errors: ["gitHubOIDCTokenAudience: `invalid-url` is not a valid URL."], }, }, ]; diff --git a/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts b/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts index 31dbbc8c..b92ccd6f 100644 --- a/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts +++ b/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts @@ -65,14 +65,14 @@ export const getPreSignedURL = async ({ let token = ""; try { - token = await Core.getIDToken(output.oidc.OIDCEndpoint); + token = await Core.getIDToken(output.oidc.gitHubOIDCTokenAudience); } catch (err) { if (err instanceof Error) { red( - `Failed to get OIDC token with url:\`${output.oidc.OIDCEndpoint}\`. ${err.message}`, + `Failed to get OIDC token with url:\`${output.oidc.gitHubOIDCTokenAudience}\`. ${err.message}`, ); throw new FailedOIDCFetch( - `Failed to get OIDC token with url: \`${output.oidc.OIDCEndpoint}\`. ${err.message}`, + `Failed to get OIDC token with url: \`${output.oidc.gitHubOIDCTokenAudience}\`. ${err.message}`, ); } } diff --git a/packages/bundler-plugin-core/src/utils/normalizeOptions.ts b/packages/bundler-plugin-core/src/utils/normalizeOptions.ts index fa3678e8..53f217db 100644 --- a/packages/bundler-plugin-core/src/utils/normalizeOptions.ts +++ b/packages/bundler-plugin-core/src/utils/normalizeOptions.ts @@ -69,12 +69,12 @@ const OIDCSchema = (options: Options) => * * See: https://github.com/codecov/codecov-action/blob/main/src/buildExec.ts#L53-L58 */ - OIDCEndpoint: z + gitHubOIDCTokenAudience: z .string({ - invalid_type_error: "`OIDCEndpoint` must be a string.", + invalid_type_error: "`gitHubOIDCTokenAudience` must be a string.", }) .url({ - message: `OIDCEndpoint: \`${options?.oidc?.OIDCEndpoint}\` is not a valid URL.`, + message: `gitHubOIDCTokenAudience: \`${options?.oidc?.gitHubOIDCTokenAudience}\` is not a valid URL.`, }) .optional() .default("https://codecov.io"), From 576935e9a14f3d4ffe1f0c1bc42200427dcb41c8 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Thu, 5 Sep 2024 07:18:56 -0300 Subject: [PATCH 26/39] swap from positive to nonegative to allow >= 0 --- packages/bundler-plugin-core/src/utils/normalizeOptions.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/bundler-plugin-core/src/utils/normalizeOptions.ts b/packages/bundler-plugin-core/src/utils/normalizeOptions.ts index 53f217db..423ad46a 100644 --- a/packages/bundler-plugin-core/src/utils/normalizeOptions.ts +++ b/packages/bundler-plugin-core/src/utils/normalizeOptions.ts @@ -110,8 +110,8 @@ const optionsSchemaFactory = (options: Options) => .number({ invalid_type_error: "`retryCount` must be a number.", }) - .positive({ - message: "`retryCount` must be a positive number.", + .nonnegative({ + message: "`retryCount` must be a nonnegative number.", }) .int({ message: "`retryCount` must be an integer.", From 42e41c7ebda88c98f45984955ebdbdc8b91a18ee Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Thu, 5 Sep 2024 07:19:59 -0300 Subject: [PATCH 27/39] add Error to failed oidc fetch error --- .../errors/{FailedOIDCFetch.ts => FailedOIDCFetchError.ts} | 2 +- .../src/utils/__tests__/getPreSignedURL.test.ts | 4 ++-- packages/bundler-plugin-core/src/utils/getPreSignedURL.ts | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) rename packages/bundler-plugin-core/src/errors/{FailedOIDCFetch.ts => FailedOIDCFetchError.ts} (50%) diff --git a/packages/bundler-plugin-core/src/errors/FailedOIDCFetch.ts b/packages/bundler-plugin-core/src/errors/FailedOIDCFetchError.ts similarity index 50% rename from packages/bundler-plugin-core/src/errors/FailedOIDCFetch.ts rename to packages/bundler-plugin-core/src/errors/FailedOIDCFetchError.ts index f0a9baa4..95fdf236 100644 --- a/packages/bundler-plugin-core/src/errors/FailedOIDCFetch.ts +++ b/packages/bundler-plugin-core/src/errors/FailedOIDCFetchError.ts @@ -1,4 +1,4 @@ -export class FailedOIDCFetch extends Error { +export class FailedOIDCFetchError extends Error { constructor(msg: string) { super(msg); } diff --git a/packages/bundler-plugin-core/src/utils/__tests__/getPreSignedURL.test.ts b/packages/bundler-plugin-core/src/utils/__tests__/getPreSignedURL.test.ts index 1ad71c49..65abb8aa 100644 --- a/packages/bundler-plugin-core/src/utils/__tests__/getPreSignedURL.test.ts +++ b/packages/bundler-plugin-core/src/utils/__tests__/getPreSignedURL.test.ts @@ -21,7 +21,7 @@ import { UploadLimitReachedError } from "../../errors/UploadLimitReachedError.ts import { UndefinedGitServiceError } from "../../errors/UndefinedGitServiceError.ts"; import { Output } from "../Output.ts"; import { BadOIDCServiceError } from "src/errors/BadOIDCServiceError.ts"; -import { FailedOIDCFetch } from "src/errors/FailedOIDCFetch.ts"; +import { FailedOIDCFetchError } from "src/errors/FailedOIDCFetchError.ts"; const mocks = vi.hoisted(() => ({ getIDToken: vi.fn().mockReturnValue(""), @@ -591,7 +591,7 @@ describe("getPreSignedURL", () => { } expect(consoleSpy).toHaveBeenCalled(); - expect(error).toBeInstanceOf(FailedOIDCFetch); + expect(error).toBeInstanceOf(FailedOIDCFetchError); }); }); }); diff --git a/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts b/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts index b92ccd6f..d010b710 100644 --- a/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts +++ b/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts @@ -10,7 +10,7 @@ import { preProcessBody } from "./preProcessBody.ts"; import { NoUploadTokenError } from "../errors/NoUploadTokenError.ts"; import { findGitService } from "./findGitService.ts"; import { UndefinedGitServiceError } from "../errors/UndefinedGitServiceError.ts"; -import { FailedOIDCFetch } from "../errors/FailedOIDCFetch.ts"; +import { FailedOIDCFetchError } from "../errors/FailedOIDCFetchError.ts"; import { type Output } from "./Output.ts"; import { BadOIDCServiceError } from "../errors/BadOIDCServiceError.ts"; @@ -71,7 +71,7 @@ export const getPreSignedURL = async ({ red( `Failed to get OIDC token with url:\`${output.oidc.gitHubOIDCTokenAudience}\`. ${err.message}`, ); - throw new FailedOIDCFetch( + throw new FailedOIDCFetchError( `Failed to get OIDC token with url: \`${output.oidc.gitHubOIDCTokenAudience}\`. ${err.message}`, ); } From 0decbe8c007b7c40121b655902d414c6ec481a71 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Thu, 5 Sep 2024 07:22:16 -0300 Subject: [PATCH 28/39] remove redundent assignment --- packages/bundler-plugin-core/src/utils/getPreSignedURL.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts b/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts index d010b710..c7aeddf9 100644 --- a/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts +++ b/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts @@ -31,8 +31,6 @@ export const getPreSignedURL = async ({ serviceParams, output, }: GetPreSignedURLArgs) => { - let url = output.apiUrl; - const headers = new Headers({ "Content-Type": "application/json", }); @@ -88,7 +86,7 @@ export const getPreSignedURL = async ({ let response: Response; try { response = await fetchWithRetry({ - url: `${url}${API_ENDPOINT}`, + url: `${output.apiUrl}${API_ENDPOINT}`, retryCount: output.retryCount ?? DEFAULT_RETRY_COUNT, name: "`get-pre-signed-url`", requestData: { From afba80c245e6df96f49f4256e94c90096e73fe3b Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Thu, 5 Sep 2024 07:25:13 -0300 Subject: [PATCH 29/39] remove url requirement for GH OIDC auidence --- .../utils/__tests__/normalizeOptions.test.ts | 20 +------- .../src/utils/normalizeOptions.ts | 48 +++++++++---------- 2 files changed, 24 insertions(+), 44 deletions(-) diff --git a/packages/bundler-plugin-core/src/utils/__tests__/normalizeOptions.test.ts b/packages/bundler-plugin-core/src/utils/__tests__/normalizeOptions.test.ts index faaf43dc..f55286f6 100644 --- a/packages/bundler-plugin-core/src/utils/__tests__/normalizeOptions.test.ts +++ b/packages/bundler-plugin-core/src/utils/__tests__/normalizeOptions.test.ts @@ -200,7 +200,7 @@ const tests: Test[] = [ }, }, { - name: "retry count is a negative number, returns positive number error message", + name: "retry count is a negative number, returns nonnegative number error message", input: { options: { bundleName: "test-bundle", @@ -209,7 +209,7 @@ const tests: Test[] = [ }, expected: { success: false, - errors: ["`retryCount` must be a positive number."], + errors: ["`retryCount` must be a nonnegative number."], }, }, { @@ -225,22 +225,6 @@ const tests: Test[] = [ errors: ["`retryCount` must be an integer."], }, }, - { - name: "gitHubOIDCTokenAudience does not match URL format, returns format error message", - input: { - options: { - oidc: { - useGitHubOIDC: true, - gitHubOIDCTokenAudience: "invalid-url", - }, - bundleName: "test-bundle", - }, - }, - expected: { - success: false, - errors: ["gitHubOIDCTokenAudience: `invalid-url` is not a valid URL."], - }, - }, ]; describe("normalizeOptions", () => { diff --git a/packages/bundler-plugin-core/src/utils/normalizeOptions.ts b/packages/bundler-plugin-core/src/utils/normalizeOptions.ts index 423ad46a..8971effb 100644 --- a/packages/bundler-plugin-core/src/utils/normalizeOptions.ts +++ b/packages/bundler-plugin-core/src/utils/normalizeOptions.ts @@ -56,31 +56,27 @@ const UploadOverridesSchema = z.object({ .optional(), }); -const OIDCSchema = (options: Options) => - z.object( - { - useGitHubOIDC: z - .boolean({ - invalid_type_error: "`useGitHubOIDC` must be a boolean.", - }) - .default(false), - /** - * Following along with how we handle this in our GH Action. - * - * See: https://github.com/codecov/codecov-action/blob/main/src/buildExec.ts#L53-L58 - */ - gitHubOIDCTokenAudience: z - .string({ - invalid_type_error: "`gitHubOIDCTokenAudience` must be a string.", - }) - .url({ - message: `gitHubOIDCTokenAudience: \`${options?.oidc?.gitHubOIDCTokenAudience}\` is not a valid URL.`, - }) - .optional() - .default("https://codecov.io"), - }, - { invalid_type_error: "`oidc` must be an object." }, - ); +const OIDCSchema = z.object( + { + useGitHubOIDC: z + .boolean({ + invalid_type_error: "`useGitHubOIDC` must be a boolean.", + }) + .default(false), + /** + * Following along with how we handle this in our GH Action. + * + * See: https://github.com/codecov/codecov-action/blob/main/src/buildExec.ts#L53-L58 + */ + gitHubOIDCTokenAudience: z + .string({ + invalid_type_error: "`gitHubOIDCTokenAudience` must be a string.", + }) + .optional() + .default("https://codecov.io"), + }, + { invalid_type_error: "`oidc` must be an object." }, +); const optionsSchemaFactory = (options: Options) => z.object({ @@ -149,7 +145,7 @@ const optionsSchemaFactory = (options: Options) => { invalid_type_error: "`gitService` must be a valid git service." }, ) .optional(), - oidc: OIDCSchema(options).optional(), + oidc: OIDCSchema.optional(), }); interface NormalizedOptionsFailure { From 15b9993f13ed9b440d5f84e7257658b6dd643458 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Thu, 5 Sep 2024 07:37:21 -0300 Subject: [PATCH 30/39] tidy up some types descriptions --- packages/bundler-plugin-core/src/types.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/bundler-plugin-core/src/types.ts b/packages/bundler-plugin-core/src/types.ts index 3b13364b..ed14a5a8 100644 --- a/packages/bundler-plugin-core/src/types.ts +++ b/packages/bundler-plugin-core/src/types.ts @@ -89,8 +89,11 @@ export interface Options { gitService?: ValidGitService; /** - * The upload token to use for uploading the bundle analysis information. This field is - * **required** for uploading bundle analysis information in private repositories. + * The upload token to use for uploading the bundle analysis information. + * + * This field is **required** for uploading bundle analysis information in private repositories. + * Alternatively if you're using GitHub Actions and have configured OIDC authentication you can + * omit this field, and enable the `oidc.useGitHubOIDC` option. * * This value can either be a global upload token or a repo token. * - The global upload token can be found under the organization settings page. @@ -150,7 +153,7 @@ export interface Options { useGitHubOIDC: boolean; /** - * The OIDC endpoint to use for authentication. + * The OIDC audience to use for authentication. * * Defaults to `https://codecov.io` */ From 4c1c0aefed196c4e96df0ffefa5b5cf5b719319d Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Thu, 5 Sep 2024 07:45:56 -0300 Subject: [PATCH 31/39] revert back to providing various args to getPreSignedURL --- .../bundler-plugin-core/src/utils/Output.ts | 6 +- .../utils/__tests__/getPreSignedURL.test.ts | 171 +++++------------- .../src/utils/getPreSignedURL.ts | 38 ++-- 3 files changed, 75 insertions(+), 140 deletions(-) diff --git a/packages/bundler-plugin-core/src/utils/Output.ts b/packages/bundler-plugin-core/src/utils/Output.ts index 5d55c939..7584f80f 100644 --- a/packages/bundler-plugin-core/src/utils/Output.ts +++ b/packages/bundler-plugin-core/src/utils/Output.ts @@ -148,8 +148,12 @@ class Output { let url = ""; try { url = await getPreSignedURL({ + apiUrl: this.apiUrl, + uploadToken: this.uploadToken, + gitService: this.gitService, + oidc: this.oidc, + retryCount: this.retryCount, serviceParams: provider, - output: this, }); } catch (error) { return; diff --git a/packages/bundler-plugin-core/src/utils/__tests__/getPreSignedURL.test.ts b/packages/bundler-plugin-core/src/utils/__tests__/getPreSignedURL.test.ts index 65abb8aa..43258ef6 100644 --- a/packages/bundler-plugin-core/src/utils/__tests__/getPreSignedURL.test.ts +++ b/packages/bundler-plugin-core/src/utils/__tests__/getPreSignedURL.test.ts @@ -19,7 +19,6 @@ import { FailedFetchError } from "../../errors/FailedFetchError.ts"; import { NoUploadTokenError } from "../../errors/NoUploadTokenError.ts"; import { UploadLimitReachedError } from "../../errors/UploadLimitReachedError.ts"; import { UndefinedGitServiceError } from "../../errors/UndefinedGitServiceError.ts"; -import { Output } from "../Output.ts"; import { BadOIDCServiceError } from "src/errors/BadOIDCServiceError.ts"; import { FailedOIDCFetchError } from "src/errors/FailedOIDCFetchError.ts"; @@ -118,15 +117,9 @@ describe("getPreSignedURL", () => { }); const url = await getPreSignedURL({ - output: new Output({ - apiUrl: "http://localhost", - uploadToken: "cool-upload-token", - debug: false, - bundleName: "test-bundle", - retryCount: 0, - enableBundleAnalysis: true, - dryRun: false, - }), + apiUrl: "http://localhost", + uploadToken: "cool-upload-token", + retryCount: 0, serviceParams: { commit: "123", }, @@ -162,14 +155,8 @@ describe("getPreSignedURL", () => { }); const url = await getPreSignedURL({ - output: new Output({ - apiUrl: "http://localhost", - debug: false, - bundleName: "test-bundle", - retryCount: 0, - enableBundleAnalysis: true, - dryRun: false, - }), + apiUrl: "http://localhost", + retryCount: 0, serviceParams: { commit: "123", branch: "owner:branch", @@ -192,15 +179,9 @@ describe("getPreSignedURL", () => { }); const url = await getPreSignedURL({ - output: new Output({ - apiUrl: "http://localhost", - debug: false, - bundleName: "test-bundle", - retryCount: 0, - enableBundleAnalysis: true, - dryRun: false, - gitService: "github_enterprise", - }), + apiUrl: "http://localhost", + retryCount: 0, + gitService: "github_enterprise", serviceParams: { commit: "123", branch: "owner:branch", @@ -225,18 +206,12 @@ describe("getPreSignedURL", () => { }); const url = await getPreSignedURL({ - output: new Output({ - apiUrl: "http://localhost", - debug: false, - bundleName: "test-bundle", - retryCount: 0, - enableBundleAnalysis: true, - dryRun: false, - oidc: { - gitHubOIDCTokenAudience: "http://localhost", - useGitHubOIDC: true, - }, - }), + apiUrl: "http://localhost", + retryCount: 0, + oidc: { + gitHubOIDCTokenAudience: "http://localhost", + useGitHubOIDC: true, + }, serviceParams: { commit: "123", service: "github-actions", @@ -261,15 +236,9 @@ describe("getPreSignedURL", () => { let error; try { await getPreSignedURL({ - output: new Output({ - apiUrl: "http://localhost", - debug: false, - bundleName: "test-bundle", - retryCount: 0, - enableBundleAnalysis: true, - dryRun: false, - gitService: "github", - }), + apiUrl: "http://localhost", + retryCount: 0, + gitService: "github", serviceParams: { commit: "123", branch: "main", @@ -316,14 +285,8 @@ describe("getPreSignedURL", () => { let error; try { await getPreSignedURL({ - output: new Output({ - apiUrl: "http://localhost", - debug: false, - bundleName: "test-bundle", - retryCount: 0, - enableBundleAnalysis: true, - dryRun: false, - }), + apiUrl: "http://localhost", + retryCount: 0, serviceParams: { commit: "123", branch: "owner:branch", @@ -353,15 +316,9 @@ describe("getPreSignedURL", () => { let error; try { await getPreSignedURL({ - output: new Output({ - apiUrl: "http://localhost", - uploadToken: "cool-upload-token", - debug: false, - bundleName: "test-bundle", - retryCount: 0, - enableBundleAnalysis: true, - dryRun: false, - }), + apiUrl: "http://localhost", + uploadToken: "cool-upload-token", + retryCount: 0, serviceParams: { commit: "123", }, @@ -385,15 +342,9 @@ describe("getPreSignedURL", () => { let error; try { await getPreSignedURL({ - output: new Output({ - apiUrl: "http://localhost", - uploadToken: "cool-upload-token", - debug: false, - bundleName: "test-bundle", - retryCount: 0, - enableBundleAnalysis: true, - dryRun: false, - }), + apiUrl: "http://localhost", + uploadToken: "cool-upload-token", + retryCount: 0, serviceParams: { commit: "123", }, @@ -427,15 +378,9 @@ describe("getPreSignedURL", () => { let error; try { await getPreSignedURL({ - output: new Output({ - apiUrl: "http://localhost", - uploadToken: "cool-upload-token", - debug: false, - bundleName: "test-bundle", - retryCount: 0, - enableBundleAnalysis: true, - dryRun: false, - }), + apiUrl: "http://localhost", + uploadToken: "cool-upload-token", + retryCount: 0, serviceParams: { commit: "123", }, @@ -459,15 +404,9 @@ describe("getPreSignedURL", () => { let error; try { await getPreSignedURL({ - output: new Output({ - apiUrl: "http://localhost", - uploadToken: "cool-upload-token", - debug: false, - bundleName: "test-bundle", - retryCount: 0, - enableBundleAnalysis: true, - dryRun: false, - }), + apiUrl: "http://localhost", + uploadToken: "cool-upload-token", + retryCount: 0, serviceParams: { commit: "123", }, @@ -501,15 +440,9 @@ describe("getPreSignedURL", () => { let error; try { await getPreSignedURL({ - output: new Output({ - apiUrl: "http://localhost", - uploadToken: "cool-upload-token", - debug: false, - bundleName: "test-bundle", - retryCount: 0, - enableBundleAnalysis: true, - dryRun: false, - }), + apiUrl: "http://localhost", + uploadToken: "cool-upload-token", + retryCount: 0, serviceParams: { commit: "123", }, @@ -533,18 +466,12 @@ describe("getPreSignedURL", () => { let error; try { await getPreSignedURL({ - output: new Output({ - apiUrl: "http://localhost", - debug: false, - bundleName: "test-bundle", - retryCount: 0, - enableBundleAnalysis: true, - dryRun: false, - oidc: { - gitHubOIDCTokenAudience: "http://localhost", - useGitHubOIDC: true, - }, - }), + apiUrl: "http://localhost", + retryCount: 0, + oidc: { + gitHubOIDCTokenAudience: "http://localhost", + useGitHubOIDC: true, + }, serviceParams: { commit: "123", service: "local", @@ -569,18 +496,12 @@ describe("getPreSignedURL", () => { let error; try { await getPreSignedURL({ - output: new Output({ - apiUrl: "http://localhost", - debug: false, - bundleName: "test-bundle", - retryCount: 0, - enableBundleAnalysis: true, - dryRun: false, - oidc: { - gitHubOIDCTokenAudience: "http://localhost", - useGitHubOIDC: true, - }, - }), + apiUrl: "http://localhost", + retryCount: 0, + oidc: { + gitHubOIDCTokenAudience: "http://localhost", + useGitHubOIDC: true, + }, serviceParams: { commit: "123", service: "github-actions", diff --git a/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts b/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts index c7aeddf9..4bb227f5 100644 --- a/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts +++ b/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts @@ -11,12 +11,18 @@ import { NoUploadTokenError } from "../errors/NoUploadTokenError.ts"; import { findGitService } from "./findGitService.ts"; import { UndefinedGitServiceError } from "../errors/UndefinedGitServiceError.ts"; import { FailedOIDCFetchError } from "../errors/FailedOIDCFetchError.ts"; -import { type Output } from "./Output.ts"; import { BadOIDCServiceError } from "../errors/BadOIDCServiceError.ts"; interface GetPreSignedURLArgs { + apiUrl: string; + uploadToken?: string; serviceParams: Partial; - output: Output; + retryCount?: number; + gitService?: string; + oidc?: { + useGitHubOIDC: boolean; + gitHubOIDCTokenAudience: string; + }; } type RequestBody = Record; @@ -28,8 +34,12 @@ const PreSignedURLSchema = z.object({ const API_ENDPOINT = "/upload/bundle_analysis/v1"; export const getPreSignedURL = async ({ + apiUrl, + uploadToken, serviceParams, - output, + retryCount = DEFAULT_RETRY_COUNT, + gitService, + oidc, }: GetPreSignedURLArgs) => { const headers = new Headers({ "Content-Type": "application/json", @@ -41,9 +51,9 @@ export const getPreSignedURL = async ({ * proper tokenless upload. * See: https://github.com/codecov/codecov-api/pull/741 */ - if (!output.uploadToken && serviceParams.branch?.includes(":")) { - if (output.gitService) { - requestBody.git_service = output.gitService; + if (!uploadToken && serviceParams.branch?.includes(":")) { + if (gitService) { + requestBody.git_service = gitService; } else { const foundGitService = findGitService(); if (!foundGitService || foundGitService === "") { @@ -53,7 +63,7 @@ export const getPreSignedURL = async ({ requestBody.git_service = foundGitService; } - } else if (output.oidc?.useGitHubOIDC && Core) { + } else if (oidc?.useGitHubOIDC && Core) { if (serviceParams?.service !== "github-actions") { red("OIDC is only supported for GitHub Actions"); throw new BadOIDCServiceError( @@ -63,21 +73,21 @@ export const getPreSignedURL = async ({ let token = ""; try { - token = await Core.getIDToken(output.oidc.gitHubOIDCTokenAudience); + token = await Core.getIDToken(oidc.gitHubOIDCTokenAudience); } catch (err) { if (err instanceof Error) { red( - `Failed to get OIDC token with url:\`${output.oidc.gitHubOIDCTokenAudience}\`. ${err.message}`, + `Failed to get OIDC token with url:\`${oidc.gitHubOIDCTokenAudience}\`. ${err.message}`, ); throw new FailedOIDCFetchError( - `Failed to get OIDC token with url: \`${output.oidc.gitHubOIDCTokenAudience}\`. ${err.message}`, + `Failed to get OIDC token with url: \`${oidc.gitHubOIDCTokenAudience}\`. ${err.message}`, ); } } headers.set("Authorization", `token ${token}`); - } else if (output.uploadToken) { - headers.set("Authorization", `token ${output.uploadToken}`); + } else if (uploadToken) { + headers.set("Authorization", `token ${uploadToken}`); } else { red("No upload token provided"); throw new NoUploadTokenError("No upload token provided"); @@ -86,8 +96,8 @@ export const getPreSignedURL = async ({ let response: Response; try { response = await fetchWithRetry({ - url: `${output.apiUrl}${API_ENDPOINT}`, - retryCount: output.retryCount ?? DEFAULT_RETRY_COUNT, + url: `${apiUrl}${API_ENDPOINT}`, + retryCount: retryCount ?? DEFAULT_RETRY_COUNT, name: "`get-pre-signed-url`", requestData: { method: "POST", From bea9450e7282cd4c4ec546d26db012275e783b07 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Thu, 5 Sep 2024 07:55:18 -0300 Subject: [PATCH 32/39] some more tidying up of docstrings --- packages/bundler-plugin-core/src/types.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/bundler-plugin-core/src/types.ts b/packages/bundler-plugin-core/src/types.ts index ed14a5a8..c509731d 100644 --- a/packages/bundler-plugin-core/src/types.ts +++ b/packages/bundler-plugin-core/src/types.ts @@ -146,7 +146,12 @@ export interface Options { /** Options for OIDC authentication. */ oidc?: { /** - * Whether to use GitHub OIDC for authentication. + * When using GitHub Actions this option can be enabled to use OIDC authentication, which + * removes the requirement for an upload token. + * + * [OpenID Connect + * (OIDC)](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect) + * is **required** to be configured in order to use GitHub OIDC. * * Defaults to `false` */ @@ -155,6 +160,9 @@ export interface Options { /** * The OIDC audience to use for authentication. * + * If you're using a self hosted version of Codecov, you will need to provide the audience for + * the OIDC token. + * * Defaults to `https://codecov.io` */ gitHubOIDCTokenAudience?: string; From 6240c34ec01600da82f7aa51ff212acb5f1996ec Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Thu, 5 Sep 2024 07:55:31 -0300 Subject: [PATCH 33/39] fixing some small typos in the readme's --- packages/nextjs-webpack-plugin/README.md | 2 +- packages/nuxt-plugin/README.md | 2 +- packages/remix-vite-plugin/README.md | 2 +- packages/rollup-plugin/README.md | 2 +- packages/solidstart-plugin/README.md | 2 +- packages/sveltekit-plugin/README.md | 2 +- packages/vite-plugin/README.md | 2 +- packages/webpack-plugin/README.md | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/nextjs-webpack-plugin/README.md b/packages/nextjs-webpack-plugin/README.md index 3a99c5cc..f74a2f89 100644 --- a/packages/nextjs-webpack-plugin/README.md +++ b/packages/nextjs-webpack-plugin/README.md @@ -112,7 +112,7 @@ export default { ## OIDC Configuration Example -For users with [OpenID Connect(OIDC) enabled](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect), setting the `uploadToken` is not necessary. You can use OIDC with the `oidc` configuration as following. +For users with [OpenID Connect (OIDC) enabled](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect), setting the `uploadToken` is not necessary. You can use OIDC with the `oidc` configuration as following. ```typescript // next.config.mjs diff --git a/packages/nuxt-plugin/README.md b/packages/nuxt-plugin/README.md index 1512e998..c00e1b3a 100644 --- a/packages/nuxt-plugin/README.md +++ b/packages/nuxt-plugin/README.md @@ -121,7 +121,7 @@ export default defineNuxtConfig({ ## OIDC Configuration Example -For users with [OpenID Connect(OIDC) enabled](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect), setting the `uploadToken` is not necessary. You can use OIDC with the `oidc` configuration as following. +For users with [OpenID Connect (OIDC) enabled](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect), setting the `uploadToken` is not necessary. You can use OIDC with the `oidc` configuration as following. ```typescript // nuxt.config.ts diff --git a/packages/remix-vite-plugin/README.md b/packages/remix-vite-plugin/README.md index c84f270c..c2adb3a3 100644 --- a/packages/remix-vite-plugin/README.md +++ b/packages/remix-vite-plugin/README.md @@ -118,7 +118,7 @@ export default defineConfig({ ## OIDC Configuration Example -For users with [OpenID Connect(OIDC) enabled](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect), setting the `uploadToken` is not necessary. You can use OIDC with the `oidc` configuration as following. +For users with [OpenID Connect (OIDC) enabled](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect), setting the `uploadToken` is not necessary. You can use OIDC with the `oidc` configuration as following. ```ts // vite.config.ts diff --git a/packages/rollup-plugin/README.md b/packages/rollup-plugin/README.md index 31c43141..3bcdc2ce 100644 --- a/packages/rollup-plugin/README.md +++ b/packages/rollup-plugin/README.md @@ -103,7 +103,7 @@ export default defineConfig({ ## OIDC Configuration Example -For users with [OpenID Connect(OIDC) enabled](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect), setting the `uploadToken` is not necessary. You can use OIDC with the `oidc` configuration as following. +For users with [OpenID Connect (OIDC) enabled](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect), setting the `uploadToken` is not necessary. You can use OIDC with the `oidc` configuration as following. ```js // rollup.config.js diff --git a/packages/solidstart-plugin/README.md b/packages/solidstart-plugin/README.md index 6c25d2f4..008a63da 100644 --- a/packages/solidstart-plugin/README.md +++ b/packages/solidstart-plugin/README.md @@ -118,7 +118,7 @@ export default defineConfig({ ## OIDC Configuration Example -For users with [OpenID Connect(OIDC) enabled](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect), setting the `uploadToken` is not necessary. You can use OIDC with the `oidc` configuration as following. +For users with [OpenID Connect (OIDC) enabled](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect), setting the `uploadToken` is not necessary. You can use OIDC with the `oidc` configuration as following. ```ts // app.config.ts diff --git a/packages/sveltekit-plugin/README.md b/packages/sveltekit-plugin/README.md index 36f7ad4a..a7af4c26 100644 --- a/packages/sveltekit-plugin/README.md +++ b/packages/sveltekit-plugin/README.md @@ -112,7 +112,7 @@ export default defineConfig({ ## OIDC Configuration Example -For users with [OpenID Connect(OIDC) enabled](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect), setting the `uploadToken` is not necessary. You can use OIDC with the `oidc` configuration as following. +For users with [OpenID Connect (OIDC) enabled](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect), setting the `uploadToken` is not necessary. You can use OIDC with the `oidc` configuration as following. ```ts // vite.config.ts diff --git a/packages/vite-plugin/README.md b/packages/vite-plugin/README.md index 102b5b12..d1e3e3f2 100644 --- a/packages/vite-plugin/README.md +++ b/packages/vite-plugin/README.md @@ -105,7 +105,7 @@ export default defineConfig({ ## OIDC Configuration Example -For users with [OpenID Connect(OIDC) enabled](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect), setting the `uploadToken` is not necessary. You can use OIDC with the `oidc` configuration as following. +For users with [OpenID Connect (OIDC) enabled](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect), setting the `uploadToken` is not necessary. You can use OIDC with the `oidc` configuration as following. ```js // vite.config.js diff --git a/packages/webpack-plugin/README.md b/packages/webpack-plugin/README.md index 5654d85d..754399cf 100644 --- a/packages/webpack-plugin/README.md +++ b/packages/webpack-plugin/README.md @@ -121,7 +121,7 @@ module.exports = { ## OIDC Configuration Example -For users with [OpenID Connect(OIDC) enabled](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect), setting the `uploadToken` is not necessary. You can use OIDC with the `oidc` configuration as following. +For users with [OpenID Connect (OIDC) enabled](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect), setting the `uploadToken` is not necessary. You can use OIDC with the `oidc` configuration as following. ```js // webpack.config.js From 13dc764fa1e0b1301b0aafc35af0bc7d8753de40 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Thu, 5 Sep 2024 13:05:19 -0300 Subject: [PATCH 34/39] move default retry count to fetch with retry implementation --- packages/bundler-plugin-core/src/utils/fetchWithRetry.ts | 6 +++--- packages/bundler-plugin-core/src/utils/getPreSignedURL.ts | 5 ++--- packages/bundler-plugin-core/src/utils/uploadStats.ts | 3 +-- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/bundler-plugin-core/src/utils/fetchWithRetry.ts b/packages/bundler-plugin-core/src/utils/fetchWithRetry.ts index 68f9bb89..6467be66 100644 --- a/packages/bundler-plugin-core/src/utils/fetchWithRetry.ts +++ b/packages/bundler-plugin-core/src/utils/fetchWithRetry.ts @@ -1,18 +1,18 @@ import { BadResponseError } from "../errors/BadResponseError"; -import { DEFAULT_RETRY_DELAY } from "./constants"; +import { DEFAULT_RETRY_DELAY, DEFAULT_RETRY_COUNT } from "./constants"; import { delay } from "./delay"; import { debug, red } from "./logging"; interface FetchWithRetryArgs { url: string; - retryCount: number; + retryCount?: number; requestData: RequestInit; name?: string; } export const fetchWithRetry = async ({ url, - retryCount, + retryCount = DEFAULT_RETRY_COUNT, requestData, name, }: FetchWithRetryArgs) => { diff --git a/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts b/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts index 4bb227f5..73a3d789 100644 --- a/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts +++ b/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts @@ -3,7 +3,6 @@ import { z } from "zod"; import { FailedFetchError } from "../errors/FailedFetchError.ts"; import { UploadLimitReachedError } from "../errors/UploadLimitReachedError.ts"; import { type ProviderServiceParams } from "../types.ts"; -import { DEFAULT_RETRY_COUNT } from "./constants.ts"; import { fetchWithRetry } from "./fetchWithRetry.ts"; import { green, red } from "./logging.ts"; import { preProcessBody } from "./preProcessBody.ts"; @@ -37,7 +36,7 @@ export const getPreSignedURL = async ({ apiUrl, uploadToken, serviceParams, - retryCount = DEFAULT_RETRY_COUNT, + retryCount, gitService, oidc, }: GetPreSignedURLArgs) => { @@ -96,8 +95,8 @@ export const getPreSignedURL = async ({ let response: Response; try { response = await fetchWithRetry({ + retryCount, url: `${apiUrl}${API_ENDPOINT}`, - retryCount: retryCount ?? DEFAULT_RETRY_COUNT, name: "`get-pre-signed-url`", requestData: { method: "POST", diff --git a/packages/bundler-plugin-core/src/utils/uploadStats.ts b/packages/bundler-plugin-core/src/utils/uploadStats.ts index 3067ba4d..a1ab59bf 100644 --- a/packages/bundler-plugin-core/src/utils/uploadStats.ts +++ b/packages/bundler-plugin-core/src/utils/uploadStats.ts @@ -3,7 +3,6 @@ import { ReadableStream, TextEncoderStream } from "node:stream/web"; import { FailedUploadError } from "../errors/FailedUploadError"; import { green, red } from "./logging"; import { fetchWithRetry } from "./fetchWithRetry"; -import { DEFAULT_RETRY_COUNT } from "./constants"; import { UploadLimitReachedError } from "../errors/UploadLimitReachedError"; import { FailedFetchError } from "../errors/FailedFetchError"; @@ -18,7 +17,7 @@ export async function uploadStats({ message, bundleName, preSignedUrl, - retryCount = DEFAULT_RETRY_COUNT, + retryCount, }: UploadStatsArgs) { const iterator = message[Symbol.iterator](); const stream = new ReadableStream({ From 2fd70cd47efd9489b8999458b5fddab43df7f8ad Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Thu, 5 Sep 2024 13:07:03 -0300 Subject: [PATCH 35/39] small typo suggestion --- .../src/utils/__tests__/normalizeOptions.test.ts | 4 ++-- packages/bundler-plugin-core/src/utils/normalizeOptions.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/bundler-plugin-core/src/utils/__tests__/normalizeOptions.test.ts b/packages/bundler-plugin-core/src/utils/__tests__/normalizeOptions.test.ts index f55286f6..01eccc97 100644 --- a/packages/bundler-plugin-core/src/utils/__tests__/normalizeOptions.test.ts +++ b/packages/bundler-plugin-core/src/utils/__tests__/normalizeOptions.test.ts @@ -200,7 +200,7 @@ const tests: Test[] = [ }, }, { - name: "retry count is a negative number, returns nonnegative number error message", + name: "retry count is a negative number, returns non-negative number error message", input: { options: { bundleName: "test-bundle", @@ -209,7 +209,7 @@ const tests: Test[] = [ }, expected: { success: false, - errors: ["`retryCount` must be a nonnegative number."], + errors: ["`retryCount` must be a non-negative number."], }, }, { diff --git a/packages/bundler-plugin-core/src/utils/normalizeOptions.ts b/packages/bundler-plugin-core/src/utils/normalizeOptions.ts index 8971effb..036da8b9 100644 --- a/packages/bundler-plugin-core/src/utils/normalizeOptions.ts +++ b/packages/bundler-plugin-core/src/utils/normalizeOptions.ts @@ -107,7 +107,7 @@ const optionsSchemaFactory = (options: Options) => invalid_type_error: "`retryCount` must be a number.", }) .nonnegative({ - message: "`retryCount` must be a nonnegative number.", + message: "`retryCount` must be a non-negative number.", }) .int({ message: "`retryCount` must be an integer.", From b53eb746fff9441147d5aeaa969a6057e84d20af Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Thu, 5 Sep 2024 13:28:04 -0300 Subject: [PATCH 36/39] yea retry count does need to be more than 0 --- .../src/utils/__tests__/normalizeOptions.test.ts | 4 ++-- packages/bundler-plugin-core/src/utils/normalizeOptions.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/bundler-plugin-core/src/utils/__tests__/normalizeOptions.test.ts b/packages/bundler-plugin-core/src/utils/__tests__/normalizeOptions.test.ts index 01eccc97..a5a02c40 100644 --- a/packages/bundler-plugin-core/src/utils/__tests__/normalizeOptions.test.ts +++ b/packages/bundler-plugin-core/src/utils/__tests__/normalizeOptions.test.ts @@ -200,7 +200,7 @@ const tests: Test[] = [ }, }, { - name: "retry count is a negative number, returns non-negative number error message", + name: "retry count is a negative number, returns positive number error message", input: { options: { bundleName: "test-bundle", @@ -209,7 +209,7 @@ const tests: Test[] = [ }, expected: { success: false, - errors: ["`retryCount` must be a non-negative number."], + errors: ["`retryCount` must be a positive number."], }, }, { diff --git a/packages/bundler-plugin-core/src/utils/normalizeOptions.ts b/packages/bundler-plugin-core/src/utils/normalizeOptions.ts index 036da8b9..6dbedd88 100644 --- a/packages/bundler-plugin-core/src/utils/normalizeOptions.ts +++ b/packages/bundler-plugin-core/src/utils/normalizeOptions.ts @@ -106,8 +106,8 @@ const optionsSchemaFactory = (options: Options) => .number({ invalid_type_error: "`retryCount` must be a number.", }) - .nonnegative({ - message: "`retryCount` must be a non-negative number.", + .positive({ + message: "`retryCount` must be a positive number.", }) .int({ message: "`retryCount` must be an integer.", From c181de6131d0f15815a9628d55da25bb57fb65cf Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Mon, 9 Sep 2024 07:11:27 -0300 Subject: [PATCH 37/39] bump from ES2021 to ES2022 --- tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index 9dfbd48c..834660a0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,7 +8,7 @@ "compilerOptions": { /* LANGUAGE COMPILATION OPTIONS */ "target": "ESNext", - "lib": ["DOM", "DOM.Iterable", "ES2021"], + "lib": ["DOM", "DOM.Iterable", "ES2022"], "module": "ESNext", "moduleResolution": "Bundler", "resolveJsonModule": true, From f945dad3d482fc6c63b87ef62e55a6924c94831a Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Mon, 9 Sep 2024 07:12:05 -0300 Subject: [PATCH 38/39] update custom errors to accept error options --- .../bundler-plugin-core/src/errors/BadOIDCServiceError.ts | 4 ++-- packages/bundler-plugin-core/src/errors/BadResponseError.ts | 4 ++-- packages/bundler-plugin-core/src/errors/FailedFetchError.ts | 4 ++-- .../bundler-plugin-core/src/errors/FailedOIDCFetchError.ts | 4 ++-- packages/bundler-plugin-core/src/errors/FailedUploadError.ts | 4 ++-- packages/bundler-plugin-core/src/errors/InvalidSlugError.ts | 4 ++-- packages/bundler-plugin-core/src/errors/NoUploadTokenError.ts | 4 ++-- .../src/errors/UndefinedGitServiceError.ts | 4 ++-- .../bundler-plugin-core/src/errors/UploadLimitReachedError.ts | 4 ++-- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/packages/bundler-plugin-core/src/errors/BadOIDCServiceError.ts b/packages/bundler-plugin-core/src/errors/BadOIDCServiceError.ts index 02c7c326..14538660 100644 --- a/packages/bundler-plugin-core/src/errors/BadOIDCServiceError.ts +++ b/packages/bundler-plugin-core/src/errors/BadOIDCServiceError.ts @@ -1,5 +1,5 @@ export class BadOIDCServiceError extends Error { - constructor(msg: string) { - super(msg); + constructor(msg: string, options?: ErrorOptions) { + super(msg, options); } } diff --git a/packages/bundler-plugin-core/src/errors/BadResponseError.ts b/packages/bundler-plugin-core/src/errors/BadResponseError.ts index c218a7ab..f5f69cc9 100644 --- a/packages/bundler-plugin-core/src/errors/BadResponseError.ts +++ b/packages/bundler-plugin-core/src/errors/BadResponseError.ts @@ -1,5 +1,5 @@ export class BadResponseError extends Error { - constructor(msg: string) { - super(msg); + constructor(msg: string, options?: ErrorOptions) { + super(msg, options); } } diff --git a/packages/bundler-plugin-core/src/errors/FailedFetchError.ts b/packages/bundler-plugin-core/src/errors/FailedFetchError.ts index 07b5b001..b602da42 100644 --- a/packages/bundler-plugin-core/src/errors/FailedFetchError.ts +++ b/packages/bundler-plugin-core/src/errors/FailedFetchError.ts @@ -1,5 +1,5 @@ export class FailedFetchError extends Error { - constructor(msg: string) { - super(msg); + constructor(msg: string, options?: ErrorOptions) { + super(msg, options); } } diff --git a/packages/bundler-plugin-core/src/errors/FailedOIDCFetchError.ts b/packages/bundler-plugin-core/src/errors/FailedOIDCFetchError.ts index 95fdf236..e8a35158 100644 --- a/packages/bundler-plugin-core/src/errors/FailedOIDCFetchError.ts +++ b/packages/bundler-plugin-core/src/errors/FailedOIDCFetchError.ts @@ -1,5 +1,5 @@ export class FailedOIDCFetchError extends Error { - constructor(msg: string) { - super(msg); + constructor(msg: string, options?: ErrorOptions) { + super(msg, options); } } diff --git a/packages/bundler-plugin-core/src/errors/FailedUploadError.ts b/packages/bundler-plugin-core/src/errors/FailedUploadError.ts index c228c35d..35d6088a 100644 --- a/packages/bundler-plugin-core/src/errors/FailedUploadError.ts +++ b/packages/bundler-plugin-core/src/errors/FailedUploadError.ts @@ -1,5 +1,5 @@ export class FailedUploadError extends Error { - constructor(msg: string) { - super(msg); + constructor(msg: string, options?: ErrorOptions) { + super(msg, options); } } diff --git a/packages/bundler-plugin-core/src/errors/InvalidSlugError.ts b/packages/bundler-plugin-core/src/errors/InvalidSlugError.ts index c33ac778..1b1a7f47 100644 --- a/packages/bundler-plugin-core/src/errors/InvalidSlugError.ts +++ b/packages/bundler-plugin-core/src/errors/InvalidSlugError.ts @@ -1,5 +1,5 @@ export class InvalidSlugError extends Error { - constructor(msg: string) { - super(msg); + constructor(msg: string, options?: ErrorOptions) { + super(msg, options); } } diff --git a/packages/bundler-plugin-core/src/errors/NoUploadTokenError.ts b/packages/bundler-plugin-core/src/errors/NoUploadTokenError.ts index 4b342015..e627ab2f 100644 --- a/packages/bundler-plugin-core/src/errors/NoUploadTokenError.ts +++ b/packages/bundler-plugin-core/src/errors/NoUploadTokenError.ts @@ -1,5 +1,5 @@ export class NoUploadTokenError extends Error { - constructor(msg: string) { - super(msg); + constructor(msg: string, options?: ErrorOptions) { + super(msg, options); } } diff --git a/packages/bundler-plugin-core/src/errors/UndefinedGitServiceError.ts b/packages/bundler-plugin-core/src/errors/UndefinedGitServiceError.ts index baf3f8a7..aa5c7ad4 100644 --- a/packages/bundler-plugin-core/src/errors/UndefinedGitServiceError.ts +++ b/packages/bundler-plugin-core/src/errors/UndefinedGitServiceError.ts @@ -1,5 +1,5 @@ export class UndefinedGitServiceError extends Error { - constructor(msg: string) { - super(msg); + constructor(msg: string, options?: ErrorOptions) { + super(msg, options); } } diff --git a/packages/bundler-plugin-core/src/errors/UploadLimitReachedError.ts b/packages/bundler-plugin-core/src/errors/UploadLimitReachedError.ts index b4cb205b..387b5efa 100644 --- a/packages/bundler-plugin-core/src/errors/UploadLimitReachedError.ts +++ b/packages/bundler-plugin-core/src/errors/UploadLimitReachedError.ts @@ -1,5 +1,5 @@ export class UploadLimitReachedError extends Error { - constructor(msg: string) { - super(msg); + constructor(msg: string, options?: ErrorOptions) { + super(msg, options); } } From d3aa6748acae0af21ec5646496abe29a510f6675 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Mon, 9 Sep 2024 07:14:23 -0300 Subject: [PATCH 39/39] add cause to thrown errors --- .../bundler-plugin-core/src/utils/getPreSignedURL.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts b/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts index 73a3d789..41e7200a 100644 --- a/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts +++ b/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts @@ -73,13 +73,14 @@ export const getPreSignedURL = async ({ let token = ""; try { token = await Core.getIDToken(oidc.gitHubOIDCTokenAudience); - } catch (err) { + } catch (err: unknown) { if (err instanceof Error) { red( `Failed to get OIDC token with url:\`${oidc.gitHubOIDCTokenAudience}\`. ${err.message}`, ); throw new FailedOIDCFetchError( `Failed to get OIDC token with url: \`${oidc.gitHubOIDCTokenAudience}\`. ${err.message}`, + { cause: err }, ); } } @@ -106,7 +107,7 @@ export const getPreSignedURL = async ({ }); } catch (e) { red("Failed to fetch pre-signed URL"); - throw new FailedFetchError("Failed to fetch pre-signed URL"); + throw new FailedFetchError("Failed to fetch pre-signed URL", { cause: e }); } if (response.status === 429) { @@ -124,7 +125,9 @@ export const getPreSignedURL = async ({ data = await response.json(); } catch (e) { red("Failed to parse pre-signed URL body"); - throw new FailedFetchError("Failed to parse pre-signed URL body"); + throw new FailedFetchError("Failed to parse pre-signed URL body", { + cause: e, + }); } const parsedData = PreSignedURLSchema.safeParse(data);