Skip to content

Commit de541c0

Browse files
committed
add clients
1 parent 8eb4776 commit de541c0

File tree

2 files changed

+88
-3
lines changed

2 files changed

+88
-3
lines changed

.github/actions/setup/action.yml

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ runs:
3434
3535
echo "::set-output name=SCRIPTS_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- scripts | wc -l)"
3636
37+
echo "::set-output name=JS_CLIENT_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- clients/algoliasearch-client-javascript | wc -l)"
38+
echo "::set-output name=JS_TEMPLATE_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- templates/javascript | wc -l)"
39+
3740
- name: Compute specs matrix
3841
id: spec-matrix
3942
shell: bash
@@ -58,20 +61,58 @@ runs:
5861
if [[ $specs == "" ]]; then
5962
# client cannot be empty or the matrix will fail
6063
specs_matrix='{"client":["no-run"]}'
61-
run_specs=0
64+
run_specs="false"
6265
else
6366
specs_matrix=$((
6467
echo '{ "client" : ['
6568
echo $specs | xargs | sed 's/ /, /g' | xargs -n 1 echo | sed -r 's/^([^,]*)(,?)$/"\1"\2/'
6669
echo " ]}"
6770
) | jq -c .)
68-
run_specs=1
71+
run_specs="true"
6972
fi
7073
echo $specs_matrix
7174
echo "Run specs: $run_specs"
7275
echo ::set-output name=SPECS_MATRIX::$specs_matrix
7376
echo ::set-output name=RUN_SPECS::$run_specs
7477
78+
- name: Compute JS client build matrix
79+
id: js-matrix
80+
shell: bash
81+
run: |
82+
# Read from openapitools.json to get the clients and folders (not pretty jq)
83+
clients=$(cat openapitools.json | jq '."generator-cli".generators | with_entries(if (.key | test("javascript-.*")) then ({key:.key,value:.value}) else empty end) | to_entries | map({client:.key | sub("javascript-";""),folder:.value.output | sub("#{cwd}/";"")}) | .[]')
84+
85+
base_changed=${{ github.ref == 'refs/heads/main' || steps.diff.outputs.GITHUB_ACTIONS_CHANGED > 0 || steps.diff.outputs.COMMON_SPECS_CHANGED > 0 || steps.diff.outputs.SCRIPTS_CHANGED > 0 || steps.diff.outputs.JS_TEMPLATE_CHANGED > 0 }}
86+
87+
to_test='{"client": []}'
88+
for pair in "${clients[@]}"; do
89+
client=$(echo $pair | jq '.client')
90+
folder=$(echo $pair | jq '.folder')
91+
spec_changed=$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- specs/$client | wc -l)
92+
client_changed=$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- $folder | wc -l)
93+
if [[ $base_changed || $spec_changed > 0 || $client_changed > 0 ]]; then
94+
to_test="$to_test $client"
95+
fi
96+
done
97+
98+
# Convert the array to json for the matrix
99+
if [[ $to_test == "" ]]; then
100+
# client cannot be empty or the matrix will fail
101+
js_matrix='{"client":["no-run"]}'
102+
run_js="false"
103+
else
104+
js_matrix=$((
105+
echo '{ "client" : ['
106+
echo $to_test | xargs | sed 's/ /, /g' | xargs -n 1 echo | sed -r 's/^([^,]*)(,?)$/"\1"\2/'
107+
echo " ]}"
108+
) | jq -c .)
109+
run_js="true"
110+
fi
111+
echo $js_matrix
112+
echo "Run JS: $run_js"
113+
echo ::set-output name=JS_MATRIX::$js_matrix
114+
echo ::set-output name=RUN_JS::$run_js
115+
75116
outputs:
76117
RUN_SPECS:
77118
description: Whether to run specs or not
@@ -81,6 +122,14 @@ outputs:
81122
description: Generate the matrix for specs
82123
value: ${{ steps.spec-matrix.outputs.SPECS_MATRIX }}
83124

125+
RUN_JS:
126+
description: Whether to run specs or not
127+
value: ${{ steps.js-matrix.outputs.RUN_JS }}
128+
129+
JS_MATRIX:
130+
description: Generate the matrix for specs
131+
value: ${{ steps.js-matrix.outputs.JS_MATRIX }}
132+
84133
RUN_CTS:
85134
description: Determine if the `cts` job should run
86135
value: ${{ github.ref_name == 'main' || steps.diff.outputs.GITHUB_ACTIONS_CHANGED > 0 || steps.diff.outputs.SPECS_CHANGED > 0 || steps.diff.outputs.TESTS_CHANGED > 0 || steps.diff.outputs.JS_CLIENT_CHANGED > 0 || steps.diff.outputs.JS_TEMPLATE_CHANGED > 0 || steps.diff.outputs.JAVA_CLIENT_CHANGED > 0 || steps.diff.outputs.JAVA_TEMPLATE_CHANGED > 0 }}

.github/workflows/check.yml

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,15 @@ jobs:
3030
RUN_SPECS: ${{ steps.setup.outputs.RUN_SPECS }}
3131
SPECS_MATRIX: ${{ steps.setup.outputs.SPECS_MATRIX }}
3232

33+
RUN_JS: ${{ steps.setup.outputs.RUN_JS }}
34+
JS_MATRIX: ${{ steps.setup.outputs.JS_MATRIX }}
35+
3336
RUN_CTS: ${{ steps.setup.outputs.RUN_CTS }}
3437

3538
specs:
3639
runs-on: ubuntu-20.04
3740
needs: setup
38-
if: ${{ always() && needs.setup.outputs.RUN_SPECS > 0 }}
41+
if: ${{ always() && needs.setup.outputs.RUN_SPECS == "true" }}
3942
strategy:
4043
matrix: ${{ fromJSON(needs.setup.outputs.SPECS_MATRIX) }}
4144
steps:
@@ -49,3 +52,36 @@ jobs:
4952

5053
- name: Lint ${{ matrix.client }} specs
5154
run: yarn eslint --ext=yml specs/${{ matrix.client }}
55+
56+
client_javascript:
57+
runs-on: ubuntu-20.04
58+
needs: [specs]
59+
if: ${{ always() && needs.setup.outputs.RUN_JS == 'true' }}
60+
strategy:
61+
matrix: ${{ fromJSON(needs.setup.outputs.JS_MATRIX) }}
62+
steps:
63+
- uses: actions/checkout@v2
64+
65+
- name: Restore cache
66+
uses: ./.github/actions/cache
67+
68+
- name: Get client folder
69+
id: folder
70+
shell: bash
71+
run: |
72+
echo ::set-output name=CLIENT_FOLDER::$($(cat openapitools.json | jq '."generator-cli".generators."javascript-${{ matrix.client }}".output' | sed 's/#{cwd}\///g'))
73+
74+
- name: Cache ${{ matrix.client }} client
75+
id: cache
76+
uses: actions/cache@v2
77+
with:
78+
path: '/home/runner/work/api-clients-automation/api-clients-automation/${{ steps.folder.outputs.CLIENT_FOLDER }}/dist'
79+
key: ${{ runner.os }}-js-client-${{ matrix.client }}-${{ hashFiles(format('{0}/**', steps.folder.outputs.CLIENT_FOLDER)) }}
80+
81+
- name: Generate ${{ matrix.client }} client
82+
if: steps.cache.outputs.cache-hit != 'true'
83+
run: yarn generate javascript ${{ matrix.client }}
84+
85+
- name: Build ${{ matrix.client }} client
86+
if: steps.cache.outputs.cache-hit != 'true'
87+
run: yarn build:clients javascript ${{ matrix.client }}

0 commit comments

Comments
 (0)