From d3f16f1d9a302e0a911676cb0ec9d24478f4e9e4 Mon Sep 17 00:00:00 2001 From: Aymeric Giraudet Date: Tue, 16 Jul 2024 14:36:23 +0200 Subject: [PATCH] ci: add downgrade script for algoliasearch v4 and steps (#6286) * ci: add downgrade script for algoliasearch v4 and steps * test:ci instead * store results --- .circleci/config.yml | 32 ++++++++- .../types/algoliasearch.d.ts | 2 +- scripts/legacy/downgrade-algoliasearch-v4.js | 67 +++++++++++++++++++ 3 files changed, 97 insertions(+), 4 deletions(-) create mode 100755 scripts/legacy/downgrade-algoliasearch-v4.js diff --git a/.circleci/config.yml b/.circleci/config.yml index 46fc7e845f..1b99dafb67 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -51,7 +51,10 @@ workflows: - unit tests: requires: - build - - legacy algoliasearch: + - legacy algoliasearch v3: + requires: + - build + - legacy algoliasearch v4: requires: - build - vue v3: @@ -97,7 +100,8 @@ workflows: - lint - unit tests - examples - - legacy algoliasearch + - legacy algoliasearch v3 + - legacy algoliasearch v4 - helper docs - e2e tests filters: @@ -202,7 +206,7 @@ jobs: name: Type Checking command: yarn run type-check - legacy algoliasearch: + legacy algoliasearch v3: <<: *defaults steps: - checkout @@ -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: diff --git a/packages/algoliasearch-helper/types/algoliasearch.d.ts b/packages/algoliasearch-helper/types/algoliasearch.d.ts index 5f404f1c7b..6b215f4348 100644 --- a/packages/algoliasearch-helper/types/algoliasearch.d.ts +++ b/packages/algoliasearch-helper/types/algoliasearch.d.ts @@ -177,7 +177,7 @@ export type RecommendResponse = PickForClient<{ export type RecommendResponses = PickForClient<{ v3: any; // @ts-ignore - v4: { results: Array> }; + v4: RecommendClient.RecommendQueriesResponse; // @ts-ignore v5: AlgoliaSearch.GetRecommendationsResponse; }>; diff --git a/scripts/legacy/downgrade-algoliasearch-v4.js b/scripts/legacy/downgrade-algoliasearch-v4.js new file mode 100755 index 0000000000..bbf378e0a6 --- /dev/null +++ b/scripts/legacy/downgrade-algoliasearch-v4.js @@ -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')), +]; + +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');