Skip to content

Commit 4e63891

Browse files
authored
fix(javascript): utils build and cache (#147)
1 parent c7e7577 commit 4e63891

File tree

7 files changed

+69
-67
lines changed

7 files changed

+69
-67
lines changed

.github/actions/cache/action.yml

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,110 +4,107 @@ description: Restore cached dependencies.
44

55
inputs:
66
job:
7-
description: The job that requires this composite
7+
description: The job that requires this composite.
88
required: false
99
language:
10-
description: The language to retrieve dependencies
10+
description: The language to retrieve dependencies.
1111
required: false
1212
default: javascript
13-
spec:
14-
description: The spec name to restore
15-
required: false
1613

1714
runs:
1815
using: composite
1916
steps:
2017
# restore clients
2118
- name: Restore built JavaScript common client
22-
if: ${{ inputs.job == 'cts' }}
19+
if: ${{ inputs.job == 'cts' || inputs.job == 'javascript-client' }}
2320
uses: actions/cache@v2
2421
with:
2522
path: /home/runner/work/api-clients-automation/api-clients-automation/clients/algoliasearch-client-javascript/packages/client-common/dist
26-
key: ${{ runner.os }}-1-js-client-common-${{ hashFiles('clients/algoliasearch-client-javascript/packages/client-common/**') }}
23+
key: ${{ runner.os }}-${{ env.CACHE_VERSION }}-js-client-common-${{ hashFiles('clients/algoliasearch-client-javascript/packages/client-common/**') }}
2724

2825
- name: Restore built JavaScript node requester
29-
if: ${{ inputs.job == 'cts' }}
26+
if: ${{ inputs.job == 'cts' || inputs.job == 'javascript-client' }}
3027
uses: actions/cache@v2
3128
with:
3229
path: /home/runner/work/api-clients-automation/api-clients-automation/clients/algoliasearch-client-javascript/packages/requester-node-http/dist
33-
key: ${{ runner.os }}-1-js-requester-node-http-${{ hashFiles('clients/algoliasearch-client-javascript/packages/requester-node-http/**') }}
30+
key: ${{ runner.os }}-${{ env.CACHE_VERSION }}-js-requester-node-http-${{ hashFiles('clients/algoliasearch-client-javascript/packages/requester-node-http/**') }}
3431

3532
- name: Restore built JavaScript browser requester
36-
if: ${{ inputs.job == 'cts' }}
33+
if: ${{ inputs.job == 'cts' || inputs.job == 'javascript-client' }}
3734
uses: actions/cache@v2
3835
with:
3936
path: /home/runner/work/api-clients-automation/api-clients-automation/clients/algoliasearch-client-javascript/packages/requester-browser-xhr/dist
40-
key: ${{ runner.os }}-1-js-requester-browser-xhr-${{ hashFiles('clients/algoliasearch-client-javascript/packages/requester-browser-xhr/**') }}
37+
key: ${{ runner.os }}-${{ env.CACHE_VERSION }}-js-requester-browser-xhr-${{ hashFiles('clients/algoliasearch-client-javascript/packages/requester-browser-xhr/**') }}
4138

4239
- name: Restore built JavaScript search client
4340
if: ${{ inputs.job == 'cts' }}
4441
uses: actions/cache@v2
4542
with:
4643
path: /home/runner/work/api-clients-automation/api-clients-automation/clients/algoliasearch-client-javascript/packages/client-search/dist
47-
key: ${{ runner.os }}-1-js-client-search-${{ hashFiles('clients/algoliasearch-client-javascript/packages/client-search/**') }}-${{ hashFiles('specs/bundled/search.yml') }}
44+
key: ${{ runner.os }}-${{ env.CACHE_VERSION }}-js-client-search-${{ hashFiles('clients/algoliasearch-client-javascript/packages/client-search/**') }}-${{ hashFiles('specs/bundled/search.yml') }}
4845

4946
- name: Restore built JavaScript recommend client
5047
if: ${{ inputs.job == 'cts' }}
5148
uses: actions/cache@v2
5249
with:
5350
path: /home/runner/work/api-clients-automation/api-clients-automation/clients/algoliasearch-client-javascript/packages/recommend/dist
54-
key: ${{ runner.os }}-1-js-client-recommend-${{ hashFiles('clients/algoliasearch-client-javascript/packages/recommend/**') }}-${{ hashFiles('specs/bundled/recommend.yml') }}
51+
key: ${{ runner.os }}-${{ env.CACHE_VERSION }}-js-client-recommend-${{ hashFiles('clients/algoliasearch-client-javascript/packages/recommend/**') }}-${{ hashFiles('specs/bundled/recommend.yml') }}
5552

5653
- name: Restore built JavaScript query-suggestions client
5754
if: ${{ inputs.job == 'cts' }}
5855
uses: actions/cache@v2
5956
with:
6057
path: /home/runner/work/api-clients-automation/api-clients-automation/clients/algoliasearch-client-javascript/packages/client-query-suggestions/dist
61-
key: ${{ runner.os }}-1-js-client-query-suggestions-${{ hashFiles('clients/algoliasearch-client-javascript/packages/client-query-suggestions/**') }}-${{ hashFiles('specs/bundled/query-suggestions.yml') }}
58+
key: ${{ runner.os }}-${{ env.CACHE_VERSION }}-js-client-query-suggestions-${{ hashFiles('clients/algoliasearch-client-javascript/packages/client-query-suggestions/**') }}-${{ hashFiles('specs/bundled/query-suggestions.yml') }}
6259

6360
- name: Restore built JavaScript personalization client
6461
if: ${{ inputs.job == 'cts' }}
6562
uses: actions/cache@v2
6663
with:
6764
path: /home/runner/work/api-clients-automation/api-clients-automation/clients/algoliasearch-client-javascript/packages/client-personalization/dist
68-
key: ${{ runner.os }}-1-js-client-personalization-${{ hashFiles('clients/algoliasearch-client-javascript/packages/client-personalization/**') }}-${{ hashFiles('specs/bundled/personalization.yml') }}
65+
key: ${{ runner.os }}-${{ env.CACHE_VERSION }}-js-client-personalization-${{ hashFiles('clients/algoliasearch-client-javascript/packages/client-personalization/**') }}-${{ hashFiles('specs/bundled/personalization.yml') }}
6966

7067
- name: Restore built JavaScript analytics client
7168
if: ${{ inputs.job == 'cts' }}
7269
uses: actions/cache@v2
7370
with:
7471
path: /home/runner/work/api-clients-automation/api-clients-automation/clients/algoliasearch-client-javascript/packages/client-analytics/dist
75-
key: ${{ runner.os }}-1-js-client-analytics-${{ hashFiles('clients/algoliasearch-client-javascript/packages/client-analytics/**') }}-${{ hashFiles('specs/bundled/analytics.yml') }}
72+
key: ${{ runner.os }}-${{ env.CACHE_VERSION }}-js-client-analytics-${{ hashFiles('clients/algoliasearch-client-javascript/packages/client-analytics/**') }}-${{ hashFiles('specs/bundled/analytics.yml') }}
7673

7774
- name: Restore built JavaScript abtesting client
7875
if: ${{ inputs.job == 'cts' }}
7976
uses: actions/cache@v2
8077
with:
8178
path: /home/runner/work/api-clients-automation/api-clients-automation/clients/algoliasearch-client-javascript/packages/client-abtesting/dist
82-
key: ${{ runner.os }}-1-js-client-abtesting-${{ hashFiles('clients/algoliasearch-client-javascript/packages/client-abtesting/**') }}-${{ hashFiles('specs/bundled/abtesting.yml') }}
79+
key: ${{ runner.os }}-${{ env.CACHE_VERSION }}-js-client-abtesting-${{ hashFiles('clients/algoliasearch-client-javascript/packages/client-abtesting/**') }}-${{ hashFiles('specs/bundled/abtesting.yml') }}
8380

8481
- name: Restore built JavaScript insights client
8582
if: ${{ inputs.job == 'cts' }}
8683
uses: actions/cache@v2
8784
with:
8885
path: /home/runner/work/api-clients-automation/api-clients-automation/clients/algoliasearch-client-javascript/packages/client-insights/dist
89-
key: ${{ runner.os }}-1-js-client-insights-${{ hashFiles('clients/algoliasearch-client-javascript/packages/client-insights/**') }}-${{ hashFiles('specs/bundled/insights.yml') }}
86+
key: ${{ runner.os }}-${{ env.CACHE_VERSION }}-js-client-insights-${{ hashFiles('clients/algoliasearch-client-javascript/packages/client-insights/**') }}-${{ hashFiles('specs/bundled/insights.yml') }}
9087

9188
- name: Restore built JavaScript sources client
9289
if: ${{ inputs.job == 'cts' }}
9390
uses: actions/cache@v2
9491
with:
9592
path: /home/runner/work/api-clients-automation/api-clients-automation/clients/algoliasearch-client-javascript/packages/client-sources/dist
96-
key: ${{ runner.os }}-1-js-client-sources-${{ hashFiles('clients/algoliasearch-client-javascript/packages/client-sources/**') }}-${{ hashFiles('specs/bundled/sources.yml') }}
93+
key: ${{ runner.os }}-${{ env.CACHE_VERSION }}-js-client-sources-${{ hashFiles('clients/algoliasearch-client-javascript/packages/client-sources/**') }}-${{ hashFiles('specs/bundled/sources.yml') }}
9794

9895
- name: Restore built JavaScript predict client
9996
if: ${{ inputs.job == 'cts' }}
10097
uses: actions/cache@v2
10198
with:
10299
path: /home/runner/work/api-clients-automation/api-clients-automation/clients/algoliasearch-client-javascript/packages/client-predict/dist
103-
key: ${{ runner.os }}-1-js-client-predict-${{ hashFiles('clients/algoliasearch-client-javascript/packages/client-predict/**') }}-${{ hashFiles('specs/dist/predict.yml') }}
100+
key: ${{ runner.os }}-${{ env.CACHE_VERSION }}-js-client-predict-${{ hashFiles('clients/algoliasearch-client-javascript/packages/client-predict/**') }}-${{ hashFiles('specs/dist/predict.yml') }}
104101

105102
- name: Restore built Java client
106103
if: ${{ inputs.job == 'cts' }}
107104
uses: actions/cache@v2
108105
with:
109106
path: /home/runner/work/api-clients-automation/api-clients-automation/clients/algoliasearch-client-java-2/target
110-
key: ${{ runner.os }}-1-java-client-${{ hashFiles('clients/algoliasearch-client-java-2/**') }}-${{ hashFiles('specs/bundled/search.yml') }}
107+
key: ${{ runner.os }}-${{ env.CACHE_VERSION }}-java-client-${{ hashFiles('clients/algoliasearch-client-java-2/**') }}-${{ hashFiles('specs/bundled/search.yml') }}
111108

112109
# setup yarn
113110
- name: Get yarn cache directory path
@@ -119,7 +116,7 @@ runs:
119116
uses: actions/cache@v2
120117
with:
121118
path: ${{ steps.yarn-cache-dir.outputs.dir || '/home/runner/work/api-clients-automation/api-clients-automation/.yarn/cache' }}
122-
key: node-cache-${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
119+
key: node-cache-${{ env.CACHE_VERSION }}-${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
123120

124121
- name: Install JavaScript dependencies
125122
shell: bash

.github/workflows/check.yml

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ on:
77
branches:
88
- main
99

10+
env:
11+
CACHE_VERSION: '5'
12+
1013
concurrency:
1114
group: ${{ github.ref }}
1215
cancel-in-progress: true
@@ -62,75 +65,72 @@ jobs:
6265
- name: Check diff with pushed spec
6366
run: exit $(git status --porcelain specs/bundled/${{ matrix.client }}.yml | wc -l)
6467

65-
client_javascript:
68+
client_javascript_common:
6669
timeout-minutes: 10
6770
runs-on: ubuntu-20.04
68-
needs:
69-
- setup
70-
- specs
71-
if: ${{ always() && needs.setup.outputs.RUN_JS == 'true' }}
71+
needs: setup
72+
if: ${{ always() && needs.setup.outputs.RUN_JS_COMMON == 'true' }}
7273
strategy:
73-
matrix: ${{ fromJSON(needs.setup.outputs.JS_MATRIX) }}
74+
matrix:
75+
client:
76+
- client-common
77+
- requester-browser-xhr
78+
- requester-node-http
7479
steps:
7580
- uses: actions/checkout@v2
7681

7782
- name: Restore cache
7883
uses: ./.github/actions/cache
7984
with:
8085
job: client
81-
spec: ${{ matrix.client.name }}
8286

83-
- name: Cache ${{ matrix.client.name }} client
87+
- name: Cache ${{ matrix.client }} client
8488
id: cache
8589
uses: actions/cache@v2
8690
with:
87-
path: '/home/runner/work/api-clients-automation/api-clients-automation/${{ matrix.client.folder }}/dist'
88-
key: ${{ runner.os }}-1-js-client-${{ matrix.client.name }}-${{ hashFiles(format('{0}/**', matrix.client.folder)) }}-${{ hashFiles(format('specs/bundled/{0}.yml', matrix.client.name)) }}
89-
90-
- name: Generate ${{ matrix.client.name }} client
91-
if: steps.cache.outputs.cache-hit != 'true'
92-
run: yarn generate javascript ${{ matrix.client.name }}
93-
94-
- name: Check diff with pushed client
95-
if: steps.cache.outputs.cache-hit != 'true'
96-
run: exit $(git status --porcelain ${{ matrix.client.folder }} | wc -l)
91+
path: '/home/runner/work/api-clients-automation/api-clients-automation/clients/algoliasearch-client-javascript/packages/${{ matrix.client }}/dist'
92+
key: ${{ runner.os }}-${{ env.CACHE_VERSION }}-js-${{ matrix.client }}-${{ hashFiles(format('clients/algoliasearch-client-javascript/packages/{0}/**', matrix.client)) }}
9793

98-
- name: Build ${{ matrix.client.name }} client
94+
- name: Build ${{ matrix.client }} client
9995
if: steps.cache.outputs.cache-hit != 'true'
100-
run: yarn build:clients javascript ${{ matrix.client.name }}
96+
run: yarn workspace algoliasearch-client-javascript build:utils ${{ matrix.client }}
10197

102-
client_javascript_common:
98+
client_javascript:
10399
timeout-minutes: 10
104100
runs-on: ubuntu-20.04
105101
needs:
106102
- setup
107103
- specs
108-
if: ${{ always() && needs.setup.outputs.RUN_JS_COMMON == 'true' }}
104+
- client_javascript_common
105+
if: ${{ always() && needs.setup.outputs.RUN_JS == 'true' }}
109106
strategy:
110-
matrix:
111-
client:
112-
- client-common
113-
- requester-browser-xhr
114-
- requester-node-http
107+
matrix: ${{ fromJSON(needs.setup.outputs.JS_MATRIX) }}
115108
steps:
116109
- uses: actions/checkout@v2
117110

118111
- name: Restore cache
119112
uses: ./.github/actions/cache
120113
with:
121-
job: client
122-
spec: ${{ matrix.client }}
114+
job: javascript-client
123115

124-
- name: Cache ${{ matrix.client }} client
116+
- name: Cache ${{ matrix.client.name }} client
125117
id: cache
126118
uses: actions/cache@v2
127119
with:
128-
path: '/home/runner/work/api-clients-automation/api-clients-automation/clients/algoliasearch-client-javascript/packages/${{ matrix.client }}/dist'
129-
key: ${{ runner.os }}-1-js-${{ matrix.client }}-${{ hashFiles(format('clients/algoliasearch-client-javascript/packages/{0}/**', matrix.client)) }}
120+
path: '/home/runner/work/api-clients-automation/api-clients-automation/${{ matrix.client.folder }}/dist'
121+
key: ${{ runner.os }}-${{ env.CACHE_VERSION }}-js-client-${{ matrix.client.name }}-${{ hashFiles(format('{0}/**', matrix.client.folder)) }}-${{ hashFiles(format('specs/bundled/{0}.yml', matrix.client.name)) }}
130122

131-
- name: Build ${{ matrix.client }} client
123+
- name: Generate ${{ matrix.client.name }} client
124+
if: steps.cache.outputs.cache-hit != 'true'
125+
run: yarn generate javascript ${{ matrix.client.name }}
126+
127+
- name: Check diff with pushed client
132128
if: steps.cache.outputs.cache-hit != 'true'
133-
run: yarn workspace @algolia/${{ matrix.client }} build
129+
run: exit $(git status --porcelain ${{ matrix.client.folder }} | wc -l)
130+
131+
- name: Build ${{ matrix.client.name }} client
132+
if: steps.cache.outputs.cache-hit != 'true'
133+
run: yarn build:clients javascript ${{ matrix.client.name }}
134134

135135
client_java:
136136
runs-on: ubuntu-20.04
@@ -149,14 +149,13 @@ jobs:
149149
with:
150150
job: client
151151
language: java
152-
spec: ${{ matrix.client.name }}
153152

154153
- name: Cache ${{ matrix.client.name }} client
155154
id: cache
156155
uses: actions/cache@v2
157156
with:
158157
path: '/home/runner/work/api-clients-automation/api-clients-automation/${{ matrix.client.folder }}/target'
159-
key: ${{ runner.os }}-1-java-client-${{ matrix.client.name }}-${{ hashFiles(format('{0}/**', matrix.client.folder)) }}-${{ hashFiles(format('specs/bundled/{0}.yml', matrix.client.name)) }}
158+
key: ${{ runner.os }}-${{ env.CACHE_VERSION }}-java-client-${{ matrix.client.name }}-${{ hashFiles(format('{0}/**', matrix.client.folder)) }}-${{ hashFiles(format('specs/bundled/{0}.yml', matrix.client.name)) }}
160159

161160
- name: Generate ${{ matrix.client.name }} client
162161
if: steps.cache.outputs.cache-hit != 'true'
@@ -187,7 +186,6 @@ jobs:
187186
with:
188187
job: client
189188
language: php
190-
spec: ${{ matrix.client.name }}
191189

192190
- name: Generate ${{ matrix.client.name }} client
193191
if: steps.cache.outputs.cache-hit != 'true'
@@ -206,10 +204,8 @@ jobs:
206204
timeout-minutes: 20
207205
needs:
208206
- client_javascript
209-
- client_javascript_common
210207
- client_java
211208
- client_php
212-
213209
if: ${{ always() && needs.setup.outputs.RUN_CTS == 'true' }}
214210
steps:
215211
- uses: actions/checkout@v2

.github/workflows/process-release.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
name: Process release
2+
23
on:
34
issues:
45
types:
56
- closed
7+
8+
env:
9+
CACHE_VERSION: '5'
10+
611
jobs:
712
build:
813
name: Release

clients/algoliasearch-client-javascript/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
],
77
"private": true,
88
"scripts": {
9-
"build:utils": "BUILD_UTILS=true yarn rollup -c rollup.config.js",
9+
"build:utils": "UTILS=${0:-all} yarn rollup -c rollup.config.js",
1010
"build": "CLIENT=${0:-all} yarn rollup -c rollup.config.js",
1111
"clean:utils": "yarn workspace @algolia/client-common clean && yarn workspace @algolia/requester-node-http clean && yarn workspace @algolia/requester-browser-xhr clean",
1212
"clean": "rm -rf packages/*/dist",

clients/algoliasearch-client-javascript/packages/client-common/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"module": "dist/client-common.esm.node.js",
1111
"types": "dist/index.d.ts",
1212
"scripts": {
13-
"build": "tsc",
1413
"clean": "rm -rf dist/"
1514
},
1615
"engines": {

clients/algoliasearch-client-javascript/packages/requester-node-http/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"module": "dist/requester-node-http.esm.node.js",
1111
"types": "dist/index.d.ts",
1212
"scripts": {
13-
"build": "tsc",
1413
"clean": "rm -rf dist/"
1514
},
1615
"engines": {

clients/algoliasearch-client-javascript/rollup.config.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { version } from './version';
1313

1414
// Retrieve package to build
1515
const client = process.env.CLIENT?.replace('@algolia/', '');
16-
const onlyBuildUtils = Boolean(process.env.BUILD_UTILS);
16+
const utils = process.env.UTILS;
1717

1818
function createLicence(name) {
1919
return `/*! ${name}.umd.js | ${version} | © Algolia, inc. | https://github.com/algolia/algoliasearch-client-javascript */`;
@@ -62,15 +62,15 @@ function getAvailableClients() {
6262
}
6363

6464
function initPackagesConfig() {
65-
if (onlyBuildUtils) {
65+
if (utils) {
6666
const commonOptions = {
6767
input: 'index.ts',
6868
formats: ['cjs-node', 'esm-node'],
6969
external: [],
7070
dependencies: [],
7171
};
7272

73-
return [
73+
const availableUtils = [
7474
// Common
7575
{
7676
...commonOptions,
@@ -97,6 +97,12 @@ function initPackagesConfig() {
9797
dependencies: ['@algolia/client-common'],
9898
},
9999
];
100+
101+
return utils === 'all'
102+
? availableUtils
103+
: availableUtils.filter(
104+
(availableUtil) => availableUtil.package === utils
105+
);
100106
}
101107

102108
const availableClients = getAvailableClients();

0 commit comments

Comments
 (0)