Skip to content

Commit

Permalink
ci: add downgrade script for algoliasearch v4 and steps (#6286)
Browse files Browse the repository at this point in the history
* ci: add downgrade script for algoliasearch v4 and steps

* test:ci instead

* store results
  • Loading branch information
aymeric-giraudet authored and Haroenv committed Aug 19, 2024
1 parent 6e3a209 commit d3f16f1
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 4 deletions.
32 changes: 29 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ workflows:
- unit tests:
requires:
- build
- legacy algoliasearch:
- legacy algoliasearch v3:
requires:
- build
- legacy algoliasearch v4:
requires:
- build
- vue v3:
Expand Down Expand Up @@ -97,7 +100,8 @@ workflows:
- lint
- unit tests
- examples
- legacy algoliasearch
- legacy algoliasearch v3
- legacy algoliasearch v4
- helper docs
- e2e tests
filters:
Expand Down Expand Up @@ -202,7 +206,7 @@ jobs:
name: Type Checking
command: yarn run type-check

legacy algoliasearch:
legacy algoliasearch v3:
<<: *defaults
steps:
- checkout
Expand All @@ -221,6 +225,28 @@ jobs:
name: Type Checking
command: yarn run type-check:v3

legacy algoliasearch v4:
<<: *defaults
resource_class: large
steps:
- checkout
- *attach_workspace
- *install_yarn_version
- *restore_yarn_cache
- *run_yarn_install
- run:
name: Update dependencies
command: |
./scripts/legacy/downgrade-algoliasearch-v4.js
- run:
name: Unit & Integration tests
command: yarn run test:ci
- store_test_results:
path: junit/jest/
- run:
name: Type Checking
command: yarn run type-check

vue v3:
<<: *defaults
steps:
Expand Down
2 changes: 1 addition & 1 deletion packages/algoliasearch-helper/types/algoliasearch.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export type RecommendResponse<T> = PickForClient<{
export type RecommendResponses<T> = PickForClient<{
v3: any;
// @ts-ignore
v4: { results: Array<RecommendResponse<T>> };
v4: RecommendClient.RecommendQueriesResponse<T>;
// @ts-ignore
v5: AlgoliaSearch.GetRecommendationsResponse;
}>;
Expand Down
67 changes: 67 additions & 0 deletions scripts/legacy/downgrade-algoliasearch-v4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env node
const path = require('path');

const shell = require('shelljs');

const packageJsonPaths = [
path.resolve(__dirname, '../../package.json'),
...JSON.parse(
shell.exec(
"yarn run --silent lerna list --json --all --ignore='example-*'",
{
silent: true,
}
).stdout
).map(({ location }) => path.resolve(location, 'package.json')),

Check warning on line 15 in scripts/legacy/downgrade-algoliasearch-v4.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

scripts/legacy/downgrade-algoliasearch-v4.js#L15

Detected possible user input going into a `path.join` or `path.resolve` function.
];

console.log(
`Downgrading algoliasearch dependency to v4 in:
- ${packageJsonPaths.join('\n- ')}`
);

// change main dependency
shell.sed(
'-i',
/"algoliasearch": "5.*"(,?)/,
'"algoliasearch": "4.23.2"$1',
packageJsonPaths
);

// Downgrade other dependency
shell.sed(
'-i',
/"@algolia\/client-search": "5.*"(,?)/,
'"@algolia/client-search": "4.23.2"$1',
packageJsonPaths
);

// remove resolution
shell.sed('-i', /"@algolia\/client-common": "5.*"(,?)/, '', packageJsonPaths);
shell.sed(
'-i',
/"places.js\/algoliasearch": "5.*"(,?)/,
'"places.js/algoliasearch": "4.23.2"$1',
packageJsonPaths
);

// replace import in examples
shell.sed(
'-i',
/import { liteClient as algoliasearch } from 'algoliasearch\/lite'/,
"import algoliasearch from 'algoliasearch/lite'",
...shell.ls('examples/*/*/*.{js,ts,tsx,vue}'),
...shell.ls('examples/*/*/{src,pages,app}/*.{js,ts,tsx,vue}')
);

// replace dependency in examples
shell.sed(
'-i',
/"algoliasearch": ".*"(,)?/,
'"algoliasearch": "4.23.2"$1',
...shell.ls('examples/*/*/package.json')
);

shell.exec('yarn install');

shell.exec('cp -r node_modules/algoliasearch-v4 node_modules/algoliasearch');

0 comments on commit d3f16f1

Please sign in to comment.