Skip to content

Commit

Permalink
Merge branch 'main' into fix/java-common
Browse files Browse the repository at this point in the history
  • Loading branch information
millotp authored Apr 27, 2022
2 parents c721119 + acca4d2 commit e5a084f
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/.cache_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9.0
9.1
9 changes: 7 additions & 2 deletions .github/actions/cache/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@ inputs:
language:
description: The language to retrieve dependencies.
required: false
cache_hash:
description: The cache hash from github actions and scripts
required: false

runs:
using: composite
steps:
- name: Read current GitHub Actions cache version
shell: bash
run: echo "CACHE_VERSION=$(< .github/.cache_version)" >> $GITHUB_ENV
run: |
echo "CACHE_VERSION_YARN=$(< .github/.cache_version)" >> $GITHUB_ENV
echo "CACHE_VERSION=$(< .github/.cache_version)-${{ inputs.cache_hash }}" >> $GITHUB_ENV
# JavaScript setup
- name: Get yarn cache directory path
Expand All @@ -27,7 +32,7 @@ runs:
uses: actions/cache@v2
with:
path: ${{ steps.yarn-cache-dir.outputs.dir || '.yarn/cache' }}
key: node-cache-${{ env.CACHE_VERSION }}-yarn-${{ hashFiles('yarn.lock') }}
key: node-cache-${{ env.CACHE_VERSION_YARN }}-yarn-${{ hashFiles('yarn.lock') }}

# Java setup: used during 'java' generation or 'cts'
- name: Download Java formatter
Expand Down
8 changes: 6 additions & 2 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ runs:
node-version-file: .nvmrc
cache: yarn

- name: Restore cache
- name: Run yarn install and install java formatter
uses: ./.github/actions/cache
with:
# We want to load the java formatter
language: java

- name: Setting diff outputs variables
Expand All @@ -52,6 +51,11 @@ runs:
yarn workspace scripts setRunVariables "$origin"
- name: Compute cache common hash
if: inputs.type != 'minimal'
shell: bash
run: echo "CACHE_COMMON_HASH=${{ steps.diff.outputs.GITHUB_ACTIONS_CHANGED_HASH }}-${{ steps.diff.outputs.SCRIPTS_CHANGED_HASH }}" >> $GITHUB_ENV

- name: Compute specs matrix
if: inputs.type != 'minimal'
id: spec-matrix
Expand Down
24 changes: 22 additions & 2 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:
run: yarn eslint --ext=json .

outputs:
CACHE_COMMON_HASH: ${{ env.CACHE_COMMON_HASH }}
RUN_SCRIPTS: ${{ steps.setup.outputs.RUN_SCRIPTS }}

RUN_SPECS: ${{ steps.setup.outputs.RUN_SPECS }}
Expand Down Expand Up @@ -71,6 +72,8 @@ jobs:

- name: Restore cache
uses: ./.github/actions/cache
with:
cache_hash: ${{ needs.setup.outputs.CACHE_COMMON_HASH }}

- name: Check script linting
run: yarn scripts:lint
Expand All @@ -93,6 +96,8 @@ jobs:

- name: Restore cache
uses: ./.github/actions/cache
with:
cache_hash: ${{ needs.setup.outputs.CACHE_COMMON_HASH }}

- name: Cache '${{ matrix.client.name }}' bundled specs
id: cache
Expand Down Expand Up @@ -126,6 +131,8 @@ jobs:

- name: Restore cache
uses: ./.github/actions/cache
with:
cache_hash: ${{ needs.setup.outputs.CACHE_COMMON_HASH }}

- name: Cache '${{ matrix.client }}' client
id: cache
Expand Down Expand Up @@ -164,6 +171,7 @@ jobs:
with:
job: client
language: javascript
cache_hash: ${{ needs.setup.outputs.CACHE_COMMON_HASH }}

- name: Cache '${{ matrix.client.name }}' client
id: cache
Expand Down Expand Up @@ -215,6 +223,7 @@ jobs:
with:
job: client
language: java
cache_hash: ${{ needs.setup.outputs.CACHE_COMMON_HASH }}

- name: Cache '${{ matrix.client.name }}' client
id: cache
Expand Down Expand Up @@ -264,6 +273,7 @@ jobs:
with:
job: client
language: php
cache_hash: ${{ needs.setup.outputs.CACHE_COMMON_HASH }}

- name: Cache '${{ matrix.client.name }}' client
id: cache
Expand Down Expand Up @@ -295,7 +305,9 @@ jobs:
client_javascript_algoliasearch:
timeout-minutes: 10
runs-on: ubuntu-20.04
needs: client_javascript
needs:
- setup
- client_javascript
if: |
always() &&
needs.setup.outputs.RUN_JS_ALGOLIASEARCH == 'true' &&
Expand All @@ -309,6 +321,7 @@ jobs:
with:
job: codegen
language: javascript
cache_hash: ${{ needs.setup.outputs.CACHE_COMMON_HASH }}

- name: Cache 'algoliasearch' client
id: cache
Expand All @@ -331,7 +344,9 @@ jobs:
client_javascript_tests:
runs-on: ubuntu-20.04
timeout-minutes: 10
needs: client_javascript
needs:
- setup
- client_javascript
if: |
always() &&
needs.setup.outputs.RUN_JS_TESTS == 'true' &&
Expand All @@ -344,6 +359,7 @@ jobs:
uses: ./.github/actions/cache
with:
job: cts
cache_hash: ${{ needs.setup.outputs.CACHE_COMMON_HASH }}

- name: Run client-common tests
run: yarn workspace @experimental-api-clients-automation/client-common test
Expand All @@ -352,6 +368,7 @@ jobs:
runs-on: ubuntu-20.04
timeout-minutes: 20
needs:
- setup
- client_javascript
- client_java
- client_php
Expand All @@ -371,6 +388,7 @@ jobs:
uses: ./.github/actions/cache
with:
job: cts
cache_hash: ${{ needs.setup.outputs.CACHE_COMMON_HASH }}

- name: Push generated code to generated branch
id: pushGeneratedCode
Expand Down Expand Up @@ -398,6 +416,7 @@ jobs:
runs-on: ubuntu-20.04
timeout-minutes: 10
needs:
- setup
- cts
- client_javascript_tests
- client_javascript_algoliasearch
Expand All @@ -417,6 +436,7 @@ jobs:
uses: ./.github/actions/cache
with:
job: codegen
cache_hash: ${{ needs.setup.outputs.CACHE_COMMON_HASH }}

- name: Push generated code to main
id: pushGeneratedCode
Expand Down
25 changes: 24 additions & 1 deletion scripts/ci/setRunVariables.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/* eslint-disable no-console */
import type { HashElementOptions } from 'folder-hash';
import { hashElement } from 'folder-hash';

import { getNbGitDiff } from './utils';

const JS_CLIENT_FOLDER = 'clients/algoliasearch-client-javascript';
Expand All @@ -13,10 +16,20 @@ const JS_CLIENT_FOLDER = 'clients/algoliasearch-client-javascript';
*
* The variable will be accessible in the CI via `steps.diff.outputs.<name>`.
*/
const VARIABLES_TO_CHECK = [
const VARIABLES_TO_CHECK: Array<{
name: string;
path: string[];
needHash?: boolean;
hashOptions?: HashElementOptions;
}> = [
{
name: 'GITHUB_ACTIONS_CHANGED',
path: ['.github/actions', '.github/workflows', '.github/.cache_version'],
needHash: true,
hashOptions: {
folders: { include: ['.github/actions', '.github/workflows'] },
files: { include: ['.github/.cache_version'] },
},
},
{
name: 'SPECS_CHANGED',
Expand All @@ -33,6 +46,10 @@ const VARIABLES_TO_CHECK = [
{
name: 'SCRIPTS_CHANGED',
path: ['scripts'],
needHash: true,
hashOptions: {
folders: { include: ['scripts'] },
},
},
{
name: 'GENERATORS_CHANGED',
Expand Down Expand Up @@ -107,6 +124,12 @@ async function setRunVariables({

console.log(`Found ${diff} changes for '${check.name}'`);
console.log(`::set-output name=${check.name}::${diff}`);
if (diff && check.needHash) {
const hash = (
await hashElement('.', { encoding: 'hex', ...check.hashOptions })
).hash;
console.log(`::set-output name=${check.name}_HASH::${hash}`);
}
}

console.log(`::set-output name=ORIGIN_BRANCH::${originBranch}`);
Expand Down

0 comments on commit e5a084f

Please sign in to comment.