Yos*_*sho 4 bash sentry source-maps reactjs create-react-app
我有一个 create-react-app 项目,我希望部署过程生成 Sentry 版本并将源映射上传到 Sentry。
此脚本将为package.json文件中指定的版本创建 Sentry 版本,并将源映射上传到 Sentry。
它适用于任何 JS 项目,而不仅仅是 React。
在您的项目根目录中创建一个文件并将其命名为deploy.sh:
SENTRY_TOKEN="YOUR_TOKEN"
PACKAGE_VERSION=`cat package.json \
| grep version \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g' \
| tr -d '[[:space:]]'`
printf "\nBuilding version $PACKAGE_VERSION...\n\n"
#2) Build for dev and cd to build directory
npm run build # or whatever your build command is
cd build/static/js # or whatever your build folder is
#3) create Sentry release
SOURCE_MAP=`find . -maxdepth 1 -mindepth 1 -name '*.map' | awk '{ gsub("./", "") ; print $0 }'`
printf "\nCreating a Sentry release for version $PACKAGE_VERSION...\n"
curl https://sentry.io/api/0/projects/:sentry_organization_slug/:sentry_project_slug/releases/ \
-X POST \
-H "Authorization: Bearer ${SENTRY_TOKEN}" \
-H 'Content-Type: application/json' \
-d "{\"version\": \"${PACKAGE_VERSION}\"}" \
#4) Upload a file for the given release
printf "\n\nUploading sourcemap file to Sentry: ${SOURCE_MAP}...\n"
curl "https://sentry.io/api/0/projects/:sentry_organization_slug/:sentry_project_slug/releases/$PACKAGE_VERSION/files/" \
-X POST \
-H "Authorization: Bearer ${SENTRY_TOKEN}" \
-F file=@${SOURCE_MAP} \
-F name="https://THE_URL_OF_THE_MAIN_JS_FILE/$SOURCE_MAP"
#5) IMPORTANT: Delete the sourcemaps before deploying
rm $SOURCE_MAP
#6) upload to your cloud provider
...
Run Code Online (Sandbox Code Playgroud)
代替:
:sentry_organization_slug并:sentry_project_slug使用哨兵的正确值(来自哨兵帐户网站内任何页面的 URL)SENTRY_TOKEN 使用 Sentry 的令牌THE_URL_OF_THE_MAIN_JS_FILE 使用可公开访问您的 React 构建文件的 URL。跑。
确保不要忘记在每次发布时更新 package.json 版本
| 归档时间: |
|
| 查看次数: |
2889 次 |
| 最近记录: |