From fef503c65de94e474b124066324b2440fdeea35a Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 3 Jan 2023 10:48:48 +0000 Subject: [PATCH] Upload source maps to sentry (#810) * Pretend to upload source maps to sentry * Build release not in docker so we can upload source maps sensibly and also upload the release as a plain tarball while we're at it * fix yaml * Try specifying version this way * test rebuild * pass secrets through * Too many sentries * It's almost 2023 and we're still having BSD vs GNU tar issues * Maybe get sensible tag name & release identifier * Wrong plugin, and also try the 'release' option which might the right thing * Try a different github action see if github likes that any better * add contents write permission and switch to the asset upload plugin that had the helpful doc * actually put release name in tarball path * copy docker config to right path * Prettify vite config * Only activate sentry plugin if we have secrets * Use env var for tag name * Also spelling env correctly would likely help * Fix variable syntax * Put env var in correct place One day maybe I will not find yaml syntax confusing --- .github/workflows/build.yaml | 5 +++++ .github/workflows/publish.yaml | 29 ++++++++++++++++++++++++++++- Dockerfile | 12 ++---------- package.json | 1 + vite.config.js | 34 ++++++++++++++++++++++++++-------- 5 files changed, 62 insertions(+), 19 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 765e758f..eee14064 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -18,6 +18,11 @@ jobs: run: "yarn install" - name: Build run: "yarn run build" + env: + SENTRY_ORG: ${{ secrets.SENTRY_ORG }} + SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }} + SENTRY_URL: ${{ secrets.SENTRY_URL }} + SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} - name: Upload Artifact uses: actions/upload-artifact@v2 with: diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 86557ef3..f49980d2 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -13,7 +13,7 @@ jobs: name: Build & publish runs-on: ubuntu-latest permissions: - contents: read + contents: write # required to upload release asset packages: write steps: - name: Check it out @@ -26,6 +26,33 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Yarn cache + uses: actions/setup-node@v3 + with: + cache: "yarn" + - name: Install dependencies + run: "yarn install" + - name: Build + run: "yarn run build" + env: + SENTRY_ORG: ${{ secrets.SENTRY_ORG }} + SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }} + SENTRY_URL: ${{ secrets.SENTRY_URL }} + SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} + VITE_APP_VERSION: ${{ github.event.release.tag_name }} + + - name: Create Tarball + env: + GITHUB_TAG_NAME: ${{ github.event.release.tag_name }} + run: | + tar --numeric-owner --transform "s/dist/element-call-${GITHUB_TAG_NAME}/" -cvzf element-call-${GITHUB_TAG_NAME}.tar.gz dist + - name: Upload + uses: alexellis/upload-assets@0.4.0 + env: + GITHUB_TOKEN: ${{ github.token }} + with: + asset_paths: '["element-call-${{ github.event.release.tag_name }}.tar.gz"]' + - name: Extract metadata (tags, labels) for Docker id: meta uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 diff --git a/Dockerfile b/Dockerfile index 3d7363af..05354e3f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,7 @@ -FROM --platform=$BUILDPLATFORM node:16-buster as builder - -WORKDIR /src - -COPY . /src -RUN scripts/dockerbuild.sh - -# App FROM nginxinc/nginx-unprivileged:alpine -COPY --from=builder /src/dist /app -COPY config/nginx.conf /etc/nginx/conf.d/ +COPY ./dist /app +COPY config/nginx.conf /etc/nginx/conf.d/default.conf USER root diff --git a/package.json b/package.json index 046bc006..16509120 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,7 @@ }, "devDependencies": { "@babel/core": "^7.16.5", + "@sentry/vite-plugin": "^0.3.0", "@storybook/react": "^6.5.0-alpha.5", "@testing-library/jest-dom": "^5.16.5", "@testing-library/react": "^13.4.0", diff --git a/vite.config.js b/vite.config.js index c56eac66..99116ec6 100644 --- a/vite.config.js +++ b/vite.config.js @@ -17,24 +17,42 @@ limitations under the License. import { defineConfig, loadEnv } from "vite"; import svgrPlugin from "vite-plugin-svgr"; import htmlTemplate from "vite-plugin-html-template"; +import sentryVitePlugin from "@sentry/vite-plugin"; + import path from "path"; // https://vitejs.dev/config/ export default defineConfig(({ mode }) => { const env = loadEnv(mode, process.cwd()); + const plugins = [ + svgrPlugin(), + htmlTemplate.default({ + data: { + title: env.VITE_PRODUCT_NAME || "Element Call", + }, + }), + ]; + + if ( + process.env.SENTRY_ORG && + process.env.SENTRY_PROJECT && + process.env.SENTRY_AUTH_TOKEN && + process.env.SENTRY_URL + ) { + plugins.push( + sentryVitePlugin({ + include: "./dist", + release: process.env.VITE_APP_VERSION, + }) + ); + } + return { build: { sourcemap: true, }, - plugins: [ - svgrPlugin(), - htmlTemplate.default({ - data: { - title: env.VITE_PRODUCT_NAME || "Element Call", - }, - }), - ], + plugins, resolve: { alias: { // matrix-widget-api has its transpiled lib/index.js as its entry point,