Skip to content

Commit 72f84df

Browse files
fix: use unique Algolia index for each CI job
1 parent 14c3590 commit 72f84df

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

.github/workflows/tests.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,13 @@ jobs:
4444
.next
4545
public/sw.js
4646
test:
47-
# Note: This is run in a separate job in order to support parallelization
48-
# that is currently disabled due to Algolia conflicts. All tests use the
49-
# same Algolia `test-*` indices which leads to shared db test state (e.g.
50-
# one test might clear the search index while another one is using it).
5147
needs: build
5248
runs-on: ubuntu-latest
49+
strategy:
50+
fail-fast: false
51+
matrix:
52+
browser: [electron, firefox, chrome]
53+
parallel: [1, 2, 3, 4, 5]
5354
steps:
5455
- uses: actions/checkout@v2
5556
- uses: actions/setup-node@v2
@@ -68,8 +69,11 @@ jobs:
6869
node_modules
6970
key: ${{ runner.os }}-${{ hashFiles('yarn.lock') }}
7071
- run: yarn install --immutable --immutable-cache
72+
# Each job uses its own Algolia index so as to not mess up the state of
73+
# other jobs. Ideally, we'd run Algolia locally, but this works for now.
74+
- run: echo "ALGOLIA_PREFIX=$(uuidgen)" >> $GITHUB_ENV
7175
- run: yarn start:db & yarn wait-on http-get://localhost:8080
7276
- run: yarn start:next & yarn wait-on http-get://localhost:3000
73-
- run: yarn start:cy --record --parallel --headless
77+
- run: yarn start:cy --record --parallel --headless --group ${{ matrix.browser }} -b ${{ matrix.browser }}
7478
- uses: codecov/codecov-action@v1
7579
if: ${{ success() || failure() }}

cypress/plugins/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ const algoliaId = process.env.NEXT_PUBLIC_ALGOLIA_APP_ID as string;
6969
const algoliaKey = process.env.ALGOLIA_ADMIN_KEY as string;
7070
const search = algoliasearch(algoliaId, algoliaKey);
7171

72-
const partition = process.env.NODE_ENV || 'test';
73-
const usersIdx = search.initIndex(`${partition}-users`);
74-
const matchesIdx = search.initIndex(`${partition}-matches`);
75-
const meetingsIdx = search.initIndex(`${partition}-meetings`);
72+
const prefix = process.env.ALGOLIA_PREFIX || (process.env.APP_ENV as string);
73+
const usersIdx = search.initIndex(`${prefix}-users`);
74+
const matchesIdx = search.initIndex(`${prefix}-matches`);
75+
const meetingsIdx = search.initIndex(`${prefix}-meetings`);
7676

7777
export interface Overrides {
7878
match?: Partial<MatchJSON> | null;

lib/api/algolia.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
import { WaitablePromise } from '@algolia/client-common';
77
import algoliasearch from 'algoliasearch';
88

9+
const prefix = process.env.ALGOLIA_PREFIX || (process.env.APP_ENV as string);
910
const algoliaId = process.env.NEXT_PUBLIC_ALGOLIA_APP_ID as string;
1011
const algoliaKey = process.env.ALGOLIA_ADMIN_KEY as string;
1112

@@ -15,7 +16,7 @@ export function updateFilterableAttrs(
1516
indexId: string,
1617
attrs: string[]
1718
): WaitablePromise<SetSettingsResponse> {
18-
const idx = client.initIndex(`${process.env.APP_ENV as string}-${indexId}`);
19+
const idx = client.initIndex(`${prefix}-${indexId}`);
1920
const attributesForFaceting = attrs.map((attr) => `filterOnly(${attr})`);
2021
return idx.setSettings({ attributesForFaceting });
2122
}
@@ -24,14 +25,14 @@ export function deleteObj(
2425
indexId: string,
2526
objId: string
2627
): WaitablePromise<DeleteResponse> {
27-
const idx = client.initIndex(`${process.env.APP_ENV as string}-${indexId}`);
28+
const idx = client.initIndex(`${prefix}-${indexId}`);
2829
return idx.deleteObject(objId);
2930
}
3031

3132
export default function index<T extends { toSearchHit: () => object }>(
3233
indexId: string,
3334
obj: T
3435
): WaitablePromise<SaveObjectResponse> {
35-
const idx = client.initIndex(`${process.env.APP_ENV as string}-${indexId}`);
36+
const idx = client.initIndex(`${prefix}-${indexId}`);
3637
return idx.saveObject(obj.toSearchHit());
3738
}

lib/api/search.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import algoliasearch from 'algoliasearch';
33
import { Option, Query } from 'lib/model/query/base';
44
import { APIError } from 'lib/api/error';
55

6+
const prefix = process.env.ALGOLIA_PREFIX || (process.env.APP_ENV as string);
67
const algoliaId = process.env.NEXT_PUBLIC_ALGOLIA_APP_ID as string;
78
const algoliaKey = process.env.ALGOLIA_ADMIN_KEY as string;
89

@@ -86,7 +87,7 @@ export async function list<T, H = T>(
8687
try {
8788
let hits = 0;
8889
const results: T[] = [];
89-
const idx = client.initIndex(`${process.env.APP_ENV as string}-${indexId}`);
90+
const idx = client.initIndex(`${prefix}-${indexId}`);
9091

9192
await Promise.all(
9293
filterStrings.map(async (filters) => {

0 commit comments

Comments
 (0)