Skip to content

Commit 25ec98d

Browse files
authored
chore(js): decouple workspaces APIC-550 (#739)
1 parent d7fcc6d commit 25ec98d

File tree

22 files changed

+14272
-5822
lines changed

22 files changed

+14272
-5822
lines changed

.github/actions/setup/action.yml

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ inputs:
99
workflow_name:
1010
description: Name of the workflow that is executing this action.
1111
required: false
12+
language:
13+
description: the language for which to install deps
14+
required: false
1215

1316
runs:
1417
using: composite
@@ -52,7 +55,8 @@ runs:
5255
uses: actions/cache@v3
5356
with:
5457
path: ${{ steps.yarn-cache-dir.outputs.dir || '.yarn/cache' }}
55-
key: yarn-cache-${{ env.CACHE_VERSION }}-${{ hashFiles('yarn.lock') }}
58+
# let yarn handle the cache hash
59+
key: yarn-cache-${{ env.CACHE_VERSION }}
5660

5761
- name: Cache node modules
5862
uses: actions/cache@v3
@@ -62,11 +66,38 @@ runs:
6266

6367
- name: Install JavaScript dependencies
6468
shell: bash
65-
run: YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn install
69+
run: yarn install
70+
71+
# JavaScript client deps
72+
- name: Get yarn js-client cache directory path
73+
if: ${{ inputs.language == 'javascript' }}
74+
shell: bash
75+
id: yarn-cache-dir-client
76+
run: echo "::set-output name=dir::$(cd clients/algoliasearch-client-javascript && yarn config get cacheFolder)"
77+
78+
- name: Restore Yarn js-client
79+
if: ${{ inputs.language == 'javascript' }}
80+
uses: actions/cache@v3
81+
with:
82+
path: ${{ steps.yarn-cache-dir-client.outputs.dir || 'clients/algoliasearch-client-javascript/.yarn/cache' }}
83+
# let yarn handle the cache hash
84+
key: yarn-cache-client-${{ env.CACHE_VERSION }}
85+
86+
- name: Cache js-client node modules
87+
if: ${{ inputs.language == 'javascript' }}
88+
uses: actions/cache@v3
89+
with:
90+
path: clients/algoliasearch-client-javascript/node_modules
91+
key: node-modules-client-${{ env.CACHE_VERSION }}-${{ hashFiles('clients/algoliasearch-client-javascript/yarn.lock') }}
92+
93+
- name: Install JavaScript client dependencies
94+
if: ${{ inputs.language == 'javascript' }}
95+
shell: bash
96+
run: cd clients/algoliasearch-client-javascript && yarn install
6697

6798
# PHP deps
6899
- name: Run composer update
69-
if: inputs.type != 'minimal'
100+
if: ${{ inputs.language == 'php' }}
70101
shell: bash
71102
run: |
72103
composer update --working-dir=clients/algoliasearch-client-php

.github/workflows/check.yml

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ jobs:
9696
runs-on: ubuntu-20.04
9797
timeout-minutes: 10
9898
needs: setup
99-
strategy:
99+
env:
100100
matrix: ${{ fromJSON(needs.setup.outputs.SPECS_MATRIX) }}
101101
steps:
102102
- uses: actions/checkout@v2
@@ -105,8 +105,8 @@ jobs:
105105
id: cache
106106
uses: actions/cache@v3
107107
with:
108-
key: ${{ matrix.client.cacheKey }}
109-
path: ${{ matrix.client.bundledPath }}
108+
key: ${{ matrix.cacheKey }}
109+
path: ${{ matrix.bundledPath }}
110110

111111
- name: Setup
112112
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
@@ -116,14 +116,14 @@ jobs:
116116

117117
- name: Building specs
118118
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
119-
run: yarn cli build specs ${{ matrix.client.toRun }}
119+
run: yarn cli build specs ${{ matrix.toRun }}
120120

121121
- name: Store bundled specs
122122
uses: actions/upload-artifact@v3
123123
with:
124124
if-no-files-found: error
125125
name: specs
126-
path: ${{ matrix.client.bundledPath }}
126+
path: ${{ matrix.bundledPath }}
127127

128128
client_javascript_utils:
129129
timeout-minutes: 10
@@ -155,14 +155,15 @@ jobs:
155155
uses: ./.github/actions/setup
156156
with:
157157
type: minimal
158+
language: javascript
158159

159160
- name: Build '${{ matrix.client }}' client
160161
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
161-
run: yarn workspace algoliasearch-client-javascript build ${{ matrix.client }}
162+
run: cd clients/algoliasearch-client-javascript && yarn build ${{ matrix.client }}
162163

163164
- name: Run tests for 'client-common'
164165
if: ${{ steps.cache.outputs.cache-hit != 'true' && matrix.client == 'client-common' }}
165-
run: yarn workspace @experimental-api-clients-automation/client-common test
166+
run: cd clients/algoliasearch-client-javascript && yarn workspace @experimental-api-clients-automation/client-common test
166167

167168
- name: Store '${{ matrix.client }}' JavaScript utils package
168169
uses: actions/upload-artifact@v3
@@ -211,11 +212,17 @@ jobs:
211212

212213
- name: Setup
213214
uses: ./.github/actions/setup
215+
with:
216+
language: ${{ matrix.client.language }}
214217

215218
- name: Generate clients
216219
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
217220
run: yarn cli generate ${{ matrix.client.language }} ${{ matrix.client.toRun }}
218221

222+
- name: Update `yarn.lock` for JavaScript
223+
if: ${{ matrix.client.language == 'javascript' }}
224+
run: cd ${{ matrix.client.path }} && YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn install
225+
219226
- name: Build clients
220227
if: ${{ steps.cache.outputs.cache-hit != 'true' && matrix.client.language != 'php' }}
221228
run: yarn cli build clients ${{ matrix.client.language }} ${{ matrix.client.toBuild }}
@@ -226,17 +233,35 @@ jobs:
226233

227234
- name: Run JavaScript 'algoliasearch' client tests
228235
if: ${{ steps.cache.outputs.cache-hit != 'true' && matrix.client.language == 'javascript' }}
229-
run: yarn workspace @experimental-api-clients-automation/algoliasearch test
236+
run: cd ${{ matrix.client.path }} && yarn workspace @experimental-api-clients-automation/algoliasearch test
230237

231238
- name: Clean CTS output before generate
232239
run: rm -rf ${{ matrix.client.testsToDelete }} || true
233240

234241
- name: Generate CTS
235242
run: yarn cli cts generate ${{ matrix.client.language }} ${{ matrix.client.toRun }}
236243

237-
- name: Update `yarn.lock` for JavaScript release
238-
if: ${{ matrix.client.language == 'javascript' && (startsWith(github.head_ref, 'chore/prepare-release-') || github.ref == 'refs/heads/main') }}
239-
run: YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn install
244+
# JavaScript test deps (needs to be cached because they are huge and inefficient)
245+
- name: Get yarn js test cache directory path
246+
if: ${{ matrix.client.language == 'javascript' }}
247+
shell: bash
248+
id: yarn-cache-dir-tests
249+
run: echo "::set-output name=dir::$(cd ${{ matrix.client.testsRootFolder }} && yarn config get cacheFolder)"
250+
251+
- name: Restore Yarn js tests
252+
if: ${{ matrix.client.language == 'javascript' }}
253+
uses: actions/cache@v3
254+
with:
255+
path: ${{ steps.yarn-cache-dir-tests.outputs.dir || format('{0}/.yarn/cache', matrix.client.testsRootFolder) }}
256+
# let yarn handle the cache hash
257+
key: yarn-cache-tests-${{ env.CACHE_VERSION }}
258+
259+
- name: Cache js tests node modules
260+
if: ${{ matrix.client.language == 'javascript' }}
261+
uses: actions/cache@v3
262+
with:
263+
path: ${{ matrix.client.testsRootFolder }}/node_modules
264+
key: node-modules-tests-${{ env.CACHE_VERSION }}-${{ hashFiles(format('{0}/.yarn.lock', matrix.client.testsRootFolder)) }}
240265

241266
- name: Run CTS
242267
run: yarn cli cts run ${{ matrix.client.language }}

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ node_modules
66

77
yarn-error.log
88

9-
.yarn/*
10-
!.yarn/releases
11-
!.yarn/plugins
9+
**/.yarn/*
10+
!**/.yarn/releases
11+
!**/.yarn/plugins
1212

1313
.vscode/
1414
.idea/

0 commit comments

Comments
 (0)