Skip to content

Commit

Permalink
refactor(doc-report): use a local copy of envVars for docs report
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoerge committed Sep 6, 2023
1 parent 1394ee3 commit f163375
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 6 deletions.
2 changes: 0 additions & 2 deletions perf/config/envVars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ type KnownEnvVar =
| 'COMMIT_SHA'
| 'BRANCH_DEPLOYMENT_URL'
| 'SANITY_STUDIO_DATASET'
| 'DOCS_REPORT_DATASET'
| 'DOCS_REPORT_TOKEN'

export function readEnv(name: KnownEnvVar): string {
const val = findEnv(name)
Expand Down
2 changes: 1 addition & 1 deletion scripts/doc-report/docClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {type SanityClient, createClient} from '@sanity/client'
import {sanityIdify} from '../utils/sanityIdify'
import {readEnv} from 'sanity-perf-tests/config/envVars'
import {readEnv} from './envVars'

export function createDocClient(dataset: string): SanityClient {
return createClient({
Expand Down
2 changes: 1 addition & 1 deletion scripts/doc-report/docReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {groupBy} from 'lodash'
import {combineLatest, map} from 'rxjs'
import {startTimer} from '../utils/startTimer'
import {createDocClient} from './docClient'
import {readEnv} from 'sanity-perf-tests/config/envVars'
import {readEnv} from './envVars'

const QUERY = `*[_type=='exportSymbol'] {
_id,
Expand Down
2 changes: 1 addition & 1 deletion scripts/doc-report/docReportCleanup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {sanityIdify} from '../utils/sanityIdify'
import {createDocClient} from './docClient'
import {readEnv} from 'sanity-perf-tests/config/envVars'
import {readEnv} from './envVars'

const DATASET = readEnv('DOCS_REPORT_DATASET')
const studioMetricsClient = createDocClient(DATASET)
Expand Down
2 changes: 1 addition & 1 deletion scripts/doc-report/docReportCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type {PackageManifest} from '../types'
import {sanityIdify} from '../utils/sanityIdify'
import {startTimer} from '../utils/startTimer'
import {createDocClient} from './docClient'
import {readEnv} from 'sanity-perf-tests/config/envVars'
import {readEnv} from './envVars'

const ALLOWED_TAGS = ['public', 'alpha', 'beta', 'internal', 'experimental', 'deprecated']
interface Package {
Expand Down
13 changes: 13 additions & 0 deletions scripts/doc-report/envVars.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
type KnownEnvVar = 'DOCS_REPORT_DATASET' | 'DOCS_REPORT_TOKEN'

export function readEnv(name: KnownEnvVar): string {
const val = findEnv(name)
if (val === undefined) {
throw new Error(`Missing required environment variable "${name}"`)
}
return val
}

export function findEnv(name: KnownEnvVar): string | undefined {
return process.env[name]
}

0 comments on commit f163375

Please sign in to comment.