-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(e2e): run e2e tests on PRs on ephemeral datasets (#5046)
* chore(e2e): run e2e tests in production build * chore(e2e): run e2e tests on PRs on ephemeral datasets - refactor: create a unified PR cleanup action - refactor: moved envVars script to utils and make it more resuable * chore(e2e): add missing env var to pr e2e tests
- Loading branch information
Showing
12 changed files
with
131 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import {sanityIdify} from '../utils/sanityIdify' | ||
import {startTimer} from '../utils/startTimer' | ||
import {readEnv} from '../utils/envVars' | ||
import {KnownEnvVar, createE2EClient} from './e2eClient' | ||
|
||
const DATASET = readEnv<KnownEnvVar>('SANITY_E2E_DATASET') | ||
const studioE2EClient = createE2EClient(DATASET) | ||
|
||
const timer = startTimer(`Deleting dataset ${DATASET}`) | ||
|
||
studioE2EClient.datasets | ||
.delete(sanityIdify(DATASET)) | ||
.then((res) => { | ||
if (res.deleted) { | ||
console.log('Deleted dataset') | ||
} else { | ||
console.log('Dataset was not deleted') | ||
} | ||
}) | ||
.catch((err) => { | ||
throw new Error(`Something went wrong! ${err?.response?.body?.message}`) | ||
}) | ||
.finally(() => { | ||
timer.end() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import {type SanityClient, createClient} from '@sanity/client' | ||
import {sanityIdify} from '../utils/sanityIdify' | ||
import {readEnv} from '../utils/envVars' | ||
|
||
export type KnownEnvVar = | ||
| 'SANITY_E2E_DATASET' | ||
| 'SANITY_E2E_PROJECT_ID' | ||
| 'SANITY_E2E_SESSION_TOKEN' | ||
|
||
export function createE2EClient(dataset: string): SanityClient { | ||
return createClient({ | ||
projectId: readEnv<KnownEnvVar>('SANITY_E2E_PROJECT_ID'), | ||
dataset: sanityIdify(dataset), | ||
token: readEnv<KnownEnvVar>('SANITY_E2E_SESSION_TOKEN'), | ||
apiVersion: '2023-02-03', | ||
useCdn: false, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import {readEnv} from '../utils/envVars' | ||
import {sanityIdify} from '../utils/sanityIdify' | ||
import {startTimer} from '../utils/startTimer' | ||
import {KnownEnvVar, createE2EClient} from './e2eClient' | ||
|
||
const dataset = sanityIdify(readEnv<KnownEnvVar>('SANITY_E2E_DATASET')) | ||
|
||
const studioE2EClient = createE2EClient(readEnv<KnownEnvVar>('SANITY_E2E_DATASET')) | ||
|
||
studioE2EClient.datasets.list().then(async (datasets) => { | ||
// If the dataset doesn't exist, create it | ||
if (!datasets.find((ds) => ds.name === dataset)) { | ||
const timer = startTimer(`Creating dataset ${dataset}`) | ||
await studioE2EClient.datasets.create(dataset, { | ||
aclMode: 'public', | ||
}) | ||
timer.end() | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export function readEnv<KnownEnvVar extends keyof NodeJS.ProcessEnv>(name: KnownEnvVar): string { | ||
const val = findEnv<KnownEnvVar>(name) | ||
if (val === undefined) { | ||
throw new Error(`Missing required environment variable "${name}"`) | ||
} | ||
return val | ||
} | ||
|
||
export function findEnv<KnownEnvVar extends keyof NodeJS.ProcessEnv>( | ||
name: KnownEnvVar, | ||
): string | undefined { | ||
return process.env[name] | ||
} |
8486c0a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
performance-studio – ./
performance-studio.sanity.build
performance-studio-git-next.sanity.build
8486c0a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
test-studio – ./
test-studio-git-next.sanity.build
test-studio.sanity.build