From 5ba6e83d8a0f69a38829cb255548be2ee2fd60f4 Mon Sep 17 00:00:00 2001 From: Hassan Abouelela <47495861+HassanAbouelela@users.noreply.github.com> Date: Thu, 21 Jan 2021 00:13:01 +0300 Subject: Corrects SHA & Path In Workflow Changes the sourcemap path to point to the location it is compiled to. Dynamically determines the correct SHA to use for program compilation and sentry release as it was incorrect for PRs due to the way github actions work. Signed-off-by: Hassan Abouelela <47495861+HassanAbouelela@users.noreply.github.com> --- .github/workflows/create_sentry_release.yml | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/.github/workflows/create_sentry_release.yml b/.github/workflows/create_sentry_release.yml index 4ae20bb..d258c5d 100644 --- a/.github/workflows/create_sentry_release.yml +++ b/.github/workflows/create_sentry_release.yml @@ -13,16 +13,23 @@ jobs: steps: - uses: actions/checkout@v2 - uses: EgorDm/gha-yarn-node-cache@v1 - + - name: Install dependencies run: yarn install - + + - name: Set SHA + id: commit-sha + run: | + if ${{ github.ref == 'refs/heads/main' }}; + then echo "::set-output name=sha::${{ github.sha }}"; + else echo "::set-output name=sha::${{ github.event.pull_request.head.sha }}"; + fi; + - name: Build application run: yarn build env: REACT_APP_SENTRY_DSN: ${{ secrets.SENTRY_DSN }} - REACT_APP_SHA: ${{ github.sha }} - REACT_APP_BRANCH: main + COMMIT_REF: ${{ steps.commit-sha.outputs.sha }} REACT_APP_OAUTH2_CLIENT_ID: ${{ secrets.CLIENT_ID }} - name: Create Sentry release (production) @@ -34,7 +41,8 @@ jobs: SENTRY_PROJECT: forms-frontend with: environment: production - sourcemaps: ./build/static/js/ + sourcemaps: ./build/ + version: ${{ steps.commit-sha.outputs.sha }} version_prefix: forms-frontend@ - name: Create Sentry release (deploy preview) @@ -46,5 +54,6 @@ jobs: SENTRY_PROJECT: forms-frontend with: environment: deploy-preview - sourcemaps: ./build/static/js/ + sourcemaps: ./build/ + version: ${{ steps.commit-sha.outputs.sha }} version_prefix: forms-frontend@ -- cgit v1.2.3 From 7b1f6e8875c05558b1dc014dcbabd27f534455d3 Mon Sep 17 00:00:00 2001 From: Hassan Abouelela <47495861+HassanAbouelela@users.noreply.github.com> Date: Thu, 21 Jan 2021 00:14:18 +0300 Subject: Compiles Source Maps Adds source map compilation for builds. Additionally, simplifies the file naming, and url. Signed-off-by: Hassan Abouelela <47495861+HassanAbouelela@users.noreply.github.com> --- webpack.config.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/webpack.config.js b/webpack.config.js index 93e7e9d..e24c8f1 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -6,13 +6,15 @@ if (process.env.NODE_ENV === "development") { require("dotenv").config(); } module.exports = { entry: "./src/index.tsx", - mode: process.env.NODE_ENV, + mode: process.env.NODE_ENV || "production", output: { path: path.resolve(__dirname, "build"), - filename: "[name].[contenthash].bundle.js", + filename: "[name].bundle.js", + sourceMapFilename: "[name].bundle.js.map", publicPath: "/", - devtoolModuleFilenameTemplate: "file:///" + path.resolve(__dirname, "[resource-path]?[loaders]") + devtoolModuleFilenameTemplate: "[resource-path]" }, + devtool: "source-map", optimization: { splitChunks: { chunks: 'all', -- cgit v1.2.3 From 72dca9ecaeb938ee1d7337b84b2b0f49761de0f7 Mon Sep 17 00:00:00 2001 From: Hassan Abouelela <47495861+HassanAbouelela@users.noreply.github.com> Date: Thu, 21 Jan 2021 00:15:20 +0300 Subject: Adds Sentry Release Tags Adds tags for sentry release, either containing the PR number or branch name. Signed-off-by: Hassan Abouelela <47495861+HassanAbouelela@users.noreply.github.com> --- src/index.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/index.tsx b/src/index.tsx index 871eb40..9eea4ce 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -14,6 +14,11 @@ if (process.env.NODE_ENV === "production") { release: `forms-frontend@${process.env.REACT_APP_SHA}`, environment: process.env.CONTEXT }); + + // Set tag as PR number, "main", or if unavailable, "unknown" + const branch = process.env.REACT_APP_BRANCH ?? "unknown"; + const branch_name = branch.replace(RegExp("pull/|/head", "g"), ""); + Sentry.setTag(branch_name === "main" ? "branch" : "pull_request", branch_name); } console.log("%c Python Discord Forms ", `font-size: 6em; font-family: "Hind", "Arial"; font-weight: 900; background-color: ${colors.blurple}; border-radius: 10px;`); -- cgit v1.2.3