Skip to content

Commit

Permalink
test source maps script locally
Browse files Browse the repository at this point in the history
  • Loading branch information
zchsh committed Jul 26, 2024
1 parent b25f984 commit ab433ed
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
34 changes: 21 additions & 13 deletions scripts/upload-source-maps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down

0 comments on commit ab433ed

Please sign in to comment.