Skip to content

Commit

Permalink
fix(javascript): utils build and cache (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcuts committed Feb 21, 2022
1 parent c7e7577 commit 4e63891
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 67 deletions.
41 changes: 19 additions & 22 deletions .github/actions/cache/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,110 +4,107 @@ description: Restore cached dependencies.

inputs:
job:
description: The job that requires this composite
description: The job that requires this composite.
required: false
language:
description: The language to retrieve dependencies
description: The language to retrieve dependencies.
required: false
default: javascript
spec:
description: The spec name to restore
required: false

runs:
using: composite
steps:
# restore clients
- name: Restore built JavaScript common client
if: ${{ inputs.job == 'cts' }}
if: ${{ inputs.job == 'cts' || inputs.job == 'javascript-client' }}
uses: actions/cache@v2
with:
path: /home/runner/work/api-clients-automation/api-clients-automation/clients/algoliasearch-client-javascript/packages/client-common/dist
key: ${{ runner.os }}-1-js-client-common-${{ hashFiles('clients/algoliasearch-client-javascript/packages/client-common/**') }}
key: ${{ runner.os }}-${{ env.CACHE_VERSION }}-js-client-common-${{ hashFiles('clients/algoliasearch-client-javascript/packages/client-common/**') }}

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

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

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

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

- name: Restore built JavaScript query-suggestions client
if: ${{ inputs.job == 'cts' }}
uses: actions/cache@v2
with:
path: /home/runner/work/api-clients-automation/api-clients-automation/clients/algoliasearch-client-javascript/packages/client-query-suggestions/dist
key: ${{ runner.os }}-1-js-client-query-suggestions-${{ hashFiles('clients/algoliasearch-client-javascript/packages/client-query-suggestions/**') }}-${{ hashFiles('specs/bundled/query-suggestions.yml') }}
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') }}

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

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

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

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

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

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

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

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

- name: Install JavaScript dependencies
shell: bash
Expand Down
74 changes: 35 additions & 39 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:
branches:
- main

env:
CACHE_VERSION: '5'

concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
Expand Down Expand Up @@ -62,75 +65,72 @@ jobs:
- name: Check diff with pushed spec
run: exit $(git status --porcelain specs/bundled/${{ matrix.client }}.yml | wc -l)

client_javascript:
client_javascript_common:
timeout-minutes: 10
runs-on: ubuntu-20.04
needs:
- setup
- specs
if: ${{ always() && needs.setup.outputs.RUN_JS == 'true' }}
needs: setup
if: ${{ always() && needs.setup.outputs.RUN_JS_COMMON == 'true' }}
strategy:
matrix: ${{ fromJSON(needs.setup.outputs.JS_MATRIX) }}
matrix:
client:
- client-common
- requester-browser-xhr
- requester-node-http
steps:
- uses: actions/checkout@v2

- name: Restore cache
uses: ./.github/actions/cache
with:
job: client
spec: ${{ matrix.client.name }}

- name: Cache ${{ matrix.client.name }} client
- name: Cache ${{ matrix.client }} client
id: cache
uses: actions/cache@v2
with:
path: '/home/runner/work/api-clients-automation/api-clients-automation/${{ matrix.client.folder }}/dist'
key: ${{ runner.os }}-1-js-client-${{ matrix.client.name }}-${{ hashFiles(format('{0}/**', matrix.client.folder)) }}-${{ hashFiles(format('specs/bundled/{0}.yml', matrix.client.name)) }}

- name: Generate ${{ matrix.client.name }} client
if: steps.cache.outputs.cache-hit != 'true'
run: yarn generate javascript ${{ matrix.client.name }}

- name: Check diff with pushed client
if: steps.cache.outputs.cache-hit != 'true'
run: exit $(git status --porcelain ${{ matrix.client.folder }} | wc -l)
path: '/home/runner/work/api-clients-automation/api-clients-automation/clients/algoliasearch-client-javascript/packages/${{ matrix.client }}/dist'
key: ${{ runner.os }}-${{ env.CACHE_VERSION }}-js-${{ matrix.client }}-${{ hashFiles(format('clients/algoliasearch-client-javascript/packages/{0}/**', matrix.client)) }}

- name: Build ${{ matrix.client.name }} client
- name: Build ${{ matrix.client }} client
if: steps.cache.outputs.cache-hit != 'true'
run: yarn build:clients javascript ${{ matrix.client.name }}
run: yarn workspace algoliasearch-client-javascript build:utils ${{ matrix.client }}

client_javascript_common:
client_javascript:
timeout-minutes: 10
runs-on: ubuntu-20.04
needs:
- setup
- specs
if: ${{ always() && needs.setup.outputs.RUN_JS_COMMON == 'true' }}
- client_javascript_common
if: ${{ always() && needs.setup.outputs.RUN_JS == 'true' }}
strategy:
matrix:
client:
- client-common
- requester-browser-xhr
- requester-node-http
matrix: ${{ fromJSON(needs.setup.outputs.JS_MATRIX) }}
steps:
- uses: actions/checkout@v2

- name: Restore cache
uses: ./.github/actions/cache
with:
job: client
spec: ${{ matrix.client }}
job: javascript-client

- name: Cache ${{ matrix.client }} client
- name: Cache ${{ matrix.client.name }} client
id: cache
uses: actions/cache@v2
with:
path: '/home/runner/work/api-clients-automation/api-clients-automation/clients/algoliasearch-client-javascript/packages/${{ matrix.client }}/dist'
key: ${{ runner.os }}-1-js-${{ matrix.client }}-${{ hashFiles(format('clients/algoliasearch-client-javascript/packages/{0}/**', matrix.client)) }}
path: '/home/runner/work/api-clients-automation/api-clients-automation/${{ matrix.client.folder }}/dist'
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)) }}

- name: Build ${{ matrix.client }} client
- name: Generate ${{ matrix.client.name }} client
if: steps.cache.outputs.cache-hit != 'true'
run: yarn generate javascript ${{ matrix.client.name }}

- name: Check diff with pushed client
if: steps.cache.outputs.cache-hit != 'true'
run: yarn workspace @algolia/${{ matrix.client }} build
run: exit $(git status --porcelain ${{ matrix.client.folder }} | wc -l)

- name: Build ${{ matrix.client.name }} client
if: steps.cache.outputs.cache-hit != 'true'
run: yarn build:clients javascript ${{ matrix.client.name }}

client_java:
runs-on: ubuntu-20.04
Expand All @@ -149,14 +149,13 @@ jobs:
with:
job: client
language: java
spec: ${{ matrix.client.name }}

- name: Cache ${{ matrix.client.name }} client
id: cache
uses: actions/cache@v2
with:
path: '/home/runner/work/api-clients-automation/api-clients-automation/${{ matrix.client.folder }}/target'
key: ${{ runner.os }}-1-java-client-${{ matrix.client.name }}-${{ hashFiles(format('{0}/**', matrix.client.folder)) }}-${{ hashFiles(format('specs/bundled/{0}.yml', matrix.client.name)) }}
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)) }}

- name: Generate ${{ matrix.client.name }} client
if: steps.cache.outputs.cache-hit != 'true'
Expand Down Expand Up @@ -187,7 +186,6 @@ jobs:
with:
job: client
language: php
spec: ${{ matrix.client.name }}

- name: Generate ${{ matrix.client.name }} client
if: steps.cache.outputs.cache-hit != 'true'
Expand All @@ -206,10 +204,8 @@ jobs:
timeout-minutes: 20
needs:
- client_javascript
- client_javascript_common
- client_java
- client_php

if: ${{ always() && needs.setup.outputs.RUN_CTS == 'true' }}
steps:
- uses: actions/checkout@v2
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/process-release.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
name: Process release

on:
issues:
types:
- closed

env:
CACHE_VERSION: '5'

jobs:
build:
name: Release
Expand Down
2 changes: 1 addition & 1 deletion clients/algoliasearch-client-javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
],
"private": true,
"scripts": {
"build:utils": "BUILD_UTILS=true yarn rollup -c rollup.config.js",
"build:utils": "UTILS=${0:-all} yarn rollup -c rollup.config.js",
"build": "CLIENT=${0:-all} yarn rollup -c rollup.config.js",
"clean:utils": "yarn workspace @algolia/client-common clean && yarn workspace @algolia/requester-node-http clean && yarn workspace @algolia/requester-browser-xhr clean",
"clean": "rm -rf packages/*/dist",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"module": "dist/client-common.esm.node.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc",
"clean": "rm -rf dist/"
},
"engines": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"module": "dist/requester-node-http.esm.node.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc",
"clean": "rm -rf dist/"
},
"engines": {
Expand Down
12 changes: 9 additions & 3 deletions clients/algoliasearch-client-javascript/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { version } from './version';

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

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

function initPackagesConfig() {
if (onlyBuildUtils) {
if (utils) {
const commonOptions = {
input: 'index.ts',
formats: ['cjs-node', 'esm-node'],
external: [],
dependencies: [],
};

return [
const availableUtils = [
// Common
{
...commonOptions,
Expand All @@ -97,6 +97,12 @@ function initPackagesConfig() {
dependencies: ['@algolia/client-common'],
},
];

return utils === 'all'
? availableUtils
: availableUtils.filter(
(availableUtil) => availableUtil.package === utils
);
}

const availableClients = getAvailableClients();
Expand Down

0 comments on commit 4e63891

Please sign in to comment.