diff --git a/package.json b/package.json index b23417f3ad..eaf6776246 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,8 @@ "prestart": "hc-tools ./scripts/generate-tutorial-variant-map.ts && hc-tools ./scripts/extract-hvd-content.ts", "prettier:check": "prettier --check .", "prettier:write": "prettier --write .", - "postbuild": "hc-tools ./scripts/capture-build-metrics.ts dev-portal && next-sitemap && hc-tools ./scripts/upload-source-maps.ts", + "postbuild": "hc-tools ./scripts/capture-build-metrics.ts dev-portal && next-sitemap && npm run sourcemaps", + "sourcemaps": "hc-tools ./scripts/upload-source-maps.ts", "rewrite-docs-content-links": "hc-tools ./scripts/docs-content-link-rewrites/rewrite-links.ts", "sitemap": "next-sitemap", "start:local-preview": "./scripts/content-repo-preview/start.sh", diff --git a/scripts/upload-source-maps.ts b/scripts/upload-source-maps.ts index 96a204fff7..f878f87ff7 100644 --- a/scripts/upload-source-maps.ts +++ b/scripts/upload-source-maps.ts @@ -6,18 +6,24 @@ import { execSync } from 'child_process' /** * Set up constants based on environment variables + * + * Note that dd stands for DataDog, many constants are used for DataDog. + * Docs on Vercel System Environment Variables: + * https://vercel.com/docs/projects/environment-variables/system-environment-variables */ -// https://vercel.com/docs/projects/environment-variables/system-environment-variables -const COMMIT_SHA = process.env.VERCEL_GIT_COMMIT_SHA -const DEPLOYMENT_URL = `https://${process.env.VERCEL_PROJECT_PRODUCTION_URL}` -const IS_DEV = process.env.VERCEL_ENV === 'development' -const IS_PROD = process.env.VERCEL_ENV === 'production' -// Note that dd stands for DataDog, these constants are used for DataDog +const VERCEL_ENV = process.env.VERCEL_ENV +const IS_DEV = VERCEL_ENV === 'development' +const COMMIT_SHA = IS_DEV + ? execSync('git rev-parse HEAD') + : process.env.VERCEL_GIT_COMMIT_SHA +const DD_SERVICE_MAP = { + development: 'non-prod.developer.hashicorp.com', + preview: 'non-prod.developer.hashicorp.com', + production: 'developer.hashicorp.com', +} const DD_API_KEY = process.env.DD_API_KEY -const DD_SERVICE = IS_PROD - ? 'developer.hashicorp.com' - : 'non-prod.developer.hashicorp.com' -const DD_PATH_PREFIX = `${DEPLOYMENT_URL}/_next/static/` +const DD_DRY_RUN = IS_DEV ? '--dry-run' : '' +const DD_SERVICE = DD_SERVICE_MAP[VERCEL_ENV] /** * Upload source maps to DataDog using the `datadog-ci` CLI. @@ -31,13 +37,15 @@ const DD_PATH_PREFIX = `${DEPLOYMENT_URL}/_next/static/` */ function main() { try { + // Log out cur + console.log('Running git rev-parse HEAD...') + execSync('git rev-parse HEAD', { stdio: 'inherit' }) // Log out git remotes (debugging related issue in datadog-ci use) + console.log('Running git remote -v...') execSync('git remote -v', { stdio: 'inherit' }) // Run the upload command execSync( - `DATADOG_API_KEY=${DD_API_KEY} ./node_modules/.bin/datadog-ci sourcemaps upload .next/static/ --service=${DD_SERVICE} --release-version=${COMMIT_SHA} --minified-path-prefix=${DD_PATH_PREFIX} ${ - IS_DEV ? '--dry-run' : '' - }`, + `DATADOG_API_KEY=${DD_API_KEY} ./node_modules/.bin/datadog-ci sourcemaps upload .next/static/ --service="${DD_SERVICE}" --release-version="${COMMIT_SHA}" --minified-path-prefix="/_next/static/" ${DD_DRY_RUN}`, { stdio: 'inherit' } ) // Remove source maps after uploading