Skip to content

Commit 3c7c1ab

Browse files
committed
Update various files to use environment methods, rename sentry env var
1 parent 1eada7f commit 3c7c1ab

9 files changed

Lines changed: 21 additions & 23 deletions

File tree

‎.github/workflows/build-and-test.yml‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Runs build, unit tests, and E2E tests - gates deployment
2+
# @TODO: Push to a preview branch on Vercel, and run the E2E tests on that preview instead of from a dev server
23
name: CI - Build & Test
34

45
on:
@@ -19,14 +20,14 @@ jobs:
1920

2021
# Define environment variables once at the job level
2122
# These will be available to ALL steps in this job
22-
# @TODO: These are real keys set on GitHub. But the production build only occurs on Vercel, and it's the only place that needs real keys. Once we set up a test framework using Docker containers for Suprabase, Upstash, etc., we should replace these keys with test keys.
23+
# @TODO: Same issue with type-check.yml. These are real keys set on GitHub. But the production build only occurs on Vercel, and it's the only place that needs real keys. Once we set up a test framework using Docker containers for Suprabase, Upstash, etc., we should replace these keys with test keys.
2324
env:
2425
CONVERTKIT_API_KEY: ${{ secrets.CONVERTKIT_API_KEY }}
2526
CONVERTKIT_FORM_ID: ${{ secrets.CONVERTKIT_FORM_ID }}
2627
CRON_SECRET: ${{ secrets.CRON_SECRET }}
2728
RESEND_API_KEY: ${{ secrets.RESEND_API_KEY }}
2829
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
29-
PUBLIC_SENTRY_DSN: ${{ secrets.PUBLIC_SENTRY_DSN }}
30+
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
3031
PUBLIC_SUPABASE_URL: ${{ secrets.PUBLIC_SUPABASE_URL }}
3132
PUBLIC_SUPABASE_KEY: ${{ secrets.PUBLIC_SUPABASE_KEY }}
3233
SUPABASE_SERVICE_ROLE_KEY: ${{ secrets.SUPABASE_SERVICE_ROLE_KEY }}

‎.github/workflows/type-check.yml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ jobs:
1313

1414
# Define environment variables once at the job level
1515
# These will be available to ALL steps in this job
16+
# @TODO: Same issue with build-and-test.yml. These are real keys set on GitHub. But the production build only occurs on Vercel, and it's the only place that needs real keys. Once we set up a test framework using Docker containers for Suprabase, Upstash, etc., we should replace these keys with test keys.
1617
env:
1718
CONVERTKIT_API_KEY: ${{ secrets.CONVERTKIT_API_KEY }}
1819
CONVERTKIT_FORM_ID: ${{ secrets.CONVERTKIT_FORM_ID }}
1920
RESEND_API_KEY: ${{ secrets.RESEND_API_KEY }}
2021
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
21-
PUBLIC_SENTRY_DSN: ${{ secrets.PUBLIC_SENTRY_DSN }}
22+
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
2223
WEBMENTION_IO_TOKEN: ${{ secrets.WEBMENTION_IO_TOKEN }}
2324

2425
steps:

‎sentry.server.config.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as Sentry from "@sentry/astro"
2-
import { PUBLIC_SENTRY_DSN } from "astro:env/client"
2+
import { SENTRY_DSN } from "astro:env/client"
33

44
/**
55
* Server-side Sentry initialization
@@ -8,16 +8,16 @@ import { PUBLIC_SENTRY_DSN } from "astro:env/client"
88
* It tracks server-side errors, API errors, and build-time issues.
99
*
1010
* Note: SENTRY_AUTH_TOKEN is only needed for uploading source maps during build.
11-
* The server SDK only needs PUBLIC_SENTRY_DSN to report errors.
11+
* The server SDK only needs SENTRY_DSN to report errors.
1212
*/
1313

1414
const isProd = import.meta.env.PROD
1515
const isDev = import.meta.env.DEV
1616

1717
// Initialize Sentry in production if DSN is available
18-
if (isProd && PUBLIC_SENTRY_DSN) {
18+
if (isProd) {
1919
Sentry.init({
20-
dsn: PUBLIC_SENTRY_DSN,
20+
dsn: SENTRY_DSN,
2121

2222
/** Release name to track regressions between releases */
2323
release: import.meta.env['npm_package_name'] + '@' + import.meta.env['npm_package_version'],

‎src/components/Avatar/__tests__/server.spec.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest'
2-
2+
import { isDev } from '@components/scripts/utils'
33
/**
44
* Comprehensive unit tests for AvatarManager
55
*
@@ -59,7 +59,7 @@ describe('AvatarManager', () => {
5959

6060
// Constructor should only run once (if in development mode)
6161
// In production, console.log won't be called
62-
if (import.meta.env.DEV) {
62+
if (isDev()) {
6363
expect(consoleLogSpy).toHaveBeenCalledTimes(1)
6464
}
6565
})

‎src/components/Avatar/server.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
import type { ImageMetadata } from 'astro'
18+
import { isDev } from '@components/scripts/utils'
1819

1920
type AvatarMap = Record<string, ImageMetadata>
2021

@@ -60,15 +61,15 @@ class AvatarManagerClass {
6061
if (filename && imageData) {
6162
// Deep freeze the image metadata to prevent modifications
6263
map[filename] = Object.freeze({ ...imageData })
63-
} else if (import.meta.env.DEV) {
64+
} else if (isDev()) {
6465
console.warn(`[AvatarManager] Failed to process avatar at path: ${path}`)
6566
}
6667
}
6768

6869
// Freeze the map to prevent modifications
6970
this.avatarMap = Object.freeze(map)
7071

71-
if (import.meta.env.DEV) {
72+
if (isDev()) {
7273
console.log(`[AvatarManager] Initialized with ${Object.keys(this.avatarMap).length} avatars`)
7374
}
7475
}

‎src/components/scripts/bootstrap/index.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ import {
1010
initConsentSideEffects,
1111
} from '@components/scripts/store'
1212
import { SentryBootstrap } from '@components/scripts/sentry/client'
13-
import { PUBLIC_SENTRY_DSN } from 'astro:env/client'
13+
import { isProd } from "@components.scripts/utils"
1414

1515
export class AppBootstrap {
1616
static init(): void {
1717
addScriptBreadcrumb({ scriptName: 'AppBootstrap', operation: 'init' })
1818

1919
try {
2020
/* Be careful adding script here. It runs before any script tags in components. */
21-
if (import.meta.env.PROD && PUBLIC_SENTRY_DSN) {
21+
if (isProd()) {
2222
SentryBootstrap.init()
2323
} else {
2424
console.info('🔧 Sentry disabled in development mode')

‎src/components/scripts/errors/handler.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { captureException } from '@sentry/browser'
22
import { ClientScriptError } from './ClientScriptError'
3+
import { isProd } from '@components/scripts/utils'
34

45
export interface ScriptErrorContext {
56
scriptName: string
@@ -31,7 +32,7 @@ export function handleScriptError(
3132
): ClientScriptError {
3233
// Transform to ClientScriptError (normalizes message internally)
3334
const clientError = new ClientScriptError(error)
34-
if (import.meta.env.PROD) {
35+
if (isProd()) {
3536
captureException(clientError, {
3637
tags: {
3738
scriptName: context.scriptName,

‎src/components/scripts/sentry/client.ts‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
makeFetchTransport,
1111
linkedErrorsIntegration,
1212
} from '@sentry/browser'
13-
import { PUBLIC_SENTRY_DSN } from 'astro:env/client'
13+
import { SENTRY_DSN } from 'astro:env/client'
1414
import { $consent } from '@components/scripts/store/consent'
1515

1616
/**
@@ -31,18 +31,12 @@ import { $consent } from '@components/scripts/store/consent'
3131

3232
export class SentryBootstrap {
3333
static init(): void {
34-
// Skip initialization if DSN is not configured
35-
if (!PUBLIC_SENTRY_DSN) {
36-
console.warn('⚠️ Sentry DSN not configured, skipping initialization')
37-
return
38-
}
39-
4034
// Check analytics consent for PII handling
4135
const consentState = $consent.get()
4236
const hasAnalyticsConsent = consentState.analytics
4337

4438
const client = new BrowserClient({
45-
dsn: PUBLIC_SENTRY_DSN,
39+
dsn: SENTRY_DSN,
4640

4741
integrations: [
4842
// Core integrations

‎src/lib/config/environmentalVariableValidation.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export const environmentalVariablesConfig: AstroUserConfig['env'] = {
116116
context: 'server',
117117
optional: false, // Only required for uploading source maps during build
118118
}),
119-
PUBLIC_SENTRY_DSN: envField.string({
119+
SENTRY_DSN: envField.string({
120120
access: 'public',
121121
context: 'client',
122122
optional: false, // Optional - Sentry only enabled if provided

0 commit comments

Comments
 (0)