Skip to content

Commit

Permalink
fix cache maybe
Browse files Browse the repository at this point in the history
  • Loading branch information
millotp committed Apr 15, 2022
1 parent 457c4c3 commit 16ea65f
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 96 deletions.
2 changes: 1 addition & 1 deletion .github/.cache_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.0.3.1
8.0.4
55 changes: 24 additions & 31 deletions .github/actions/cache/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,9 @@ runs:
if: ${{ inputs.job == 'cts' || inputs.job == 'codegen' }}
uses: actions/cache@v2
with:
path: clients/algoliasearch-client-java-2
path: |
clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/SearchApi.java
clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/search/**
key: |
${{ env.CACHE_VERSION }}-${{
hashFiles(
Expand All @@ -393,7 +395,9 @@ runs:
if: ${{ inputs.job == 'cts' || inputs.job == 'codegen' }}
uses: actions/cache@v2
with:
path: clients/algoliasearch-client-java-2
path: |
clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/RecommendApi.java
clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/recommend/**
key: |
${{ env.CACHE_VERSION }}-${{
hashFiles(
Expand All @@ -406,7 +410,9 @@ runs:
if: ${{ inputs.job == 'cts' || inputs.job == 'codegen' }}
uses: actions/cache@v2
with:
path: clients/algoliasearch-client-java-2
path: |
clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/PersonalizationApi.java
clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/personalization/**
key: |
${{ env.CACHE_VERSION }}-${{
hashFiles(
Expand All @@ -419,7 +425,9 @@ runs:
if: ${{ inputs.job == 'cts' || inputs.job == 'codegen' }}
uses: actions/cache@v2
with:
path: clients/algoliasearch-client-java-2
path: |
clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/AnalyticsApi.java
clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/analytics/**
key: |
${{ env.CACHE_VERSION }}-${{
hashFiles(
Expand All @@ -432,7 +440,9 @@ runs:
if: ${{ inputs.job == 'cts' || inputs.job == 'codegen' }}
uses: actions/cache@v2
with:
path: clients/algoliasearch-client-java-2
path: |
clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/InsightsApi.java
clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/insights/**
key: |
${{ env.CACHE_VERSION }}-${{
hashFiles(
Expand All @@ -445,12 +455,12 @@ runs:
if: ${{ inputs.job == 'cts' || inputs.job == 'codegen' }}
uses: actions/cache@v2
with:
path: clients/algoliasearch-client-java-2
path: |
clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/AbtestingApi.java
clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/abtesting/**
key: |
${{ env.CACHE_VERSION }}-${{
hashFiles(
'clients/algoliasearch-client-java-2/api/AbtestingApi.java',
'clients/algoliasearch-client-java-2/model/abtesting/**',
'specs/bundled/abtesting.yml',
'templates/java/**',
'generators/src/**'
Expand All @@ -460,7 +470,9 @@ runs:
if: ${{ inputs.job == 'cts' || inputs.job == 'codegen' }}
uses: actions/cache@v2
with:
path: clients/algoliasearch-client-java-2
path: |
clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/QuerySuggestionsApi.java
clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/querySuggestions/**
key: |
${{ env.CACHE_VERSION }}-${{
hashFiles(
Expand All @@ -473,7 +485,9 @@ runs:
if: ${{ inputs.job == 'cts' || inputs.job == 'codegen' }}
uses: actions/cache@v2
with:
path: clients/algoliasearch-client-java-2
path: |
clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/api/PredictApi.java
clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/predict/**
key: |
${{ env.CACHE_VERSION }}-${{
hashFiles(
Expand All @@ -493,9 +507,6 @@ runs:
key: |
${{ env.CACHE_VERSION }}-${{
hashFiles(
'clients/algoliasearch-client-php/lib/Api/SearchApi.php',
'clients/algoliasearch-client-php/lib/Configuration/SearchConfig.php',
'clients/algoliasearch-client-php/lib/Model/Search/**',
'specs/bundled/search.yml',
'templates/php/**',
'generators/src/**'
Expand All @@ -511,9 +522,6 @@ runs:
key: |
${{ env.CACHE_VERSION }}-${{
hashFiles(
'clients/algoliasearch-client-php/lib/Api/RecommendApi.php',
'clients/algoliasearch-client-php/lib/Configuration/RecommendConfig.php',
'clients/algoliasearch-client-php/lib/Model/Recommend/**',
'specs/bundled/recommend.yml',
'templates/php/**',
'generators/src/**'
Expand All @@ -529,9 +537,6 @@ runs:
key: |
${{ env.CACHE_VERSION }}-${{
hashFiles(
'clients/algoliasearch-client-php/lib/Api/PersonalizationApi.php',
'clients/algoliasearch-client-php/lib/Configuration/PersonalizationConfig.php',
'clients/algoliasearch-client-php/lib/Model/Personalization/**',
'specs/bundled/personalization.yml',
'templates/php/**',
'generators/src/**'
Expand All @@ -547,9 +552,6 @@ runs:
key: |
${{ env.CACHE_VERSION }}-${{
hashFiles(
'clients/algoliasearch-client-php/lib/Api/AnalyticsApi.php',
'clients/algoliasearch-client-php/lib/Configuration/AnalyticsConfig.php',
'clients/algoliasearch-client-php/lib/Model/Analytics/**',
'specs/bundled/analytics.yml',
'templates/php/**',
'generators/src/**'
Expand All @@ -565,9 +567,6 @@ runs:
key: |
${{ env.CACHE_VERSION }}-${{
hashFiles(
'clients/algoliasearch-client-php/lib/Api/InsightsApi.php',
'clients/algoliasearch-client-php/lib/Configuration/InsightsConfig.php',
'clients/algoliasearch-client-php/lib/Model/Insights/**',
'specs/bundled/insights.yml',
'templates/php/**',
'generators/src/**'
Expand All @@ -583,9 +582,6 @@ runs:
key: |
${{ env.CACHE_VERSION }}-${{
hashFiles(
'clients/algoliasearch-client-php/lib/Api/AbtestingApi.php',
'clients/algoliasearch-client-php/lib/Configuration/AbtestingConfig.php',
'clients/algoliasearch-client-php/lib/Model/Abtesting/**',
'specs/bundled/abtesting.yml',
'templates/php/**',
'generators/src/**'
Expand All @@ -601,9 +597,6 @@ runs:
key: |
${{ env.CACHE_VERSION }}-${{
hashFiles(
'clients/algoliasearch-client-php/lib/Api/QuerySuggestionsApi.php',
'clients/algoliasearch-client-php/lib/Configuration/QuerySuggestionsConfig.php',
'clients/algoliasearch-client-php/lib/Model/QuerySuggestions/**',
'specs/bundled/query-suggestions.yml',
'templates/php/**',
'generators/src/**'
Expand Down
13 changes: 6 additions & 7 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ jobs:
id: cache
uses: actions/cache@v2
with:
path: ${{ matrix.client.bundledPath }}
path: ${{ format('specs/bundled/{0}.yml', matrix.client) }}
key: |
${{ env.CACHE_VERSION }}-${{
hashFiles(
Expand Down Expand Up @@ -220,7 +220,9 @@ jobs:
id: cache
uses: actions/cache@v2
with:
path: ${{ matrix.client.path }}
path: |
${{ format('{0}/algoliasearch-core/com/algolia/api/{1}.java', matrix.client.path, matrix.client.clientFileName) }}
${{ format('{0}/{1}/**', matrix.client.path, matrix.client.modelFolderPath) }}
key: |
${{ env.CACHE_VERSION }}-${{
hashFiles(
Expand Down Expand Up @@ -268,14 +270,11 @@ jobs:
uses: actions/cache@v2
with:
path: |
${{ format('{0}/lib/Api/{1}.php', matrix.client.folder, matrix.client.api) }}
${{ format('{0}/lib/Model/{1}/**', matrix.client.folder, matrix.client.capitalizedName) }}
${{ format('{0}/lib/Api/{1}.php', matrix.client.path, matrix.client.clientFileName) }}
${{ format('{0}/{1}/**', matrix.client.path, matrix.client.modelFolderPath) }}
key: |
${{ env.CACHE_VERSION }}-${{
hashFiles(
format('{0}/lib/Api/{1}.php', matrix.client.folder, matrix.client.api),
format('{0}/lib/Configuration/{1}.php', matrix.client.folder, matrix.client.config),
format('{0}/lib/Model/{1}/**', matrix.client.folder, matrix.client.capitalizedName),
format('specs/bundled/{0}.yml', matrix.client.name),
'templates/php/**',
'generators/src/**'
Expand Down
49 changes: 16 additions & 33 deletions scripts/ci/createMatrix.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { CLIENTS, GENERATORS } from '../common';
import { createClientName } from '../cts/utils';
import { getLanguageModelFolder } from '../config';
import { createClientName, createModelFolderName } from '../cts/utils';
import type { Language } from '../types';

import { getNbGitDiff } from './utils';

type CreateMatrix = {
baseChanged: boolean;
baseBranch: string;
language?: Language;
forLanguage?: Language;
};

type BaseMatrix = {
Expand All @@ -16,14 +17,11 @@ type BaseMatrix = {
};

type ClientMatrix = BaseMatrix & {
config?: string;
api?: string;
capitalizedName?: string;
clientFileName?: string;
modelFolderPath?: string;
};

type SpecMatrix = BaseMatrix & {
bundledPath: string;
};
type SpecMatrix = BaseMatrix;

type Matrix<TMatrix> = {
client: TMatrix[];
Expand All @@ -33,23 +31,15 @@ type Matrix<TMatrix> = {
const EMPTY_MATRIX = JSON.stringify({ client: ['no-run'] });

async function getClientMatrix({
language,
forLanguage,
baseBranch,
baseChanged,
}: CreateMatrix): Promise<Matrix<ClientMatrix>> {
const matrix: Matrix<ClientMatrix> = { client: [] };

for (const {
client,
output,
additionalProperties,
...options
} of Object.values(GENERATORS)) {
if (
options.language !== language ||
// `algoliasearch` is an aggregation of clients
client === 'algoliasearch'
) {
for (const { language, client, output } of Object.values(GENERATORS)) {
// `algoliasearch` is an aggregation of clients
if (forLanguage !== language || client === 'algoliasearch') {
continue;
}

Expand All @@ -71,16 +61,10 @@ async function getClientMatrix({
path: output,
};

// Extra informations for the PHP matrix in order to properly scope the
// GitHub action cache
if (language === 'php') {
matchedGenerator.config = additionalProperties.configClassname;
matchedGenerator.api = additionalProperties.configClassname.replace(
'Config',
'Api'
);
matchedGenerator.capitalizedName = createClientName(client, 'php');
}
matchedGenerator.clientFileName = createClientName(client, language);
matchedGenerator.modelFolderPath = `${getLanguageModelFolder(
language
)}/${createModelFolderName(client, language)}`;

matrix.client.push(matchedGenerator);
}
Expand All @@ -107,7 +91,6 @@ async function getSpecMatrix({
const spec = {
name: client,
path: `specs/${client}`,
bundledPath: `specs/bundled/${client}.yml`,
};

// The `algoliasearch-lite` spec is created by the `search` spec
Expand All @@ -130,7 +113,7 @@ async function getSpecMatrix({
* Creates a matrix for the CI jobs based on the files that changed.
*/
async function createMatrix(opts: CreateMatrix): Promise<void> {
const matrix = opts.language
const matrix = opts.forLanguage
? await getClientMatrix(opts)
: await getSpecMatrix(opts);

Expand All @@ -146,6 +129,6 @@ if (require.main === module) {
createMatrix({
baseChanged: args[0] === 'true',
baseBranch: args[1],
language: args[2] as Language,
forLanguage: args[2] as Language,
});
}
2 changes: 1 addition & 1 deletion scripts/cts/client/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export async function generateClientTests(
template,
{
import: packageName,
client: `${createClientName(client, language)}Api`,
client: createClientName(client, language),
blocks: modifyForMustache(testsBlocks),
hasRegionalHost: hasRegionalHost ? true : undefined,
},
Expand Down
14 changes: 8 additions & 6 deletions scripts/cts/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,22 @@ describe('utils', () => {

describe('createClientName', () => {
it('does not capitalize every part for JavaScript', () => {
expect(createClientName('search', 'javascript')).toEqual('search');
expect(createClientName('search', 'javascript')).toEqual('searchApi');
expect(createClientName('search-client', 'javascript')).toEqual(
'searchClient'
'searchClientApi'
);
expect(createClientName('search-cli!nt-complex', 'javascript')).toEqual(
'searchCli!ntComplex'
'searchCli!ntComplexApi'
);
});

it('capitalize every part for other languages', () => {
expect(createClientName('search', 'java')).toEqual('Search');
expect(createClientName('search-client', 'java')).toEqual('SearchClient');
expect(createClientName('search', 'java')).toEqual('SearchApi');
expect(createClientName('search-client', 'java')).toEqual(
'SearchClientApi'
);
expect(createClientName('search-cli!nt-complex', 'java')).toEqual(
'SearchCli!ntComplex'
'SearchCli!ntComplexApi'
);
});
});
Expand Down
30 changes: 20 additions & 10 deletions scripts/cts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,29 @@ export function capitalize(str: string): string {
return str.charAt(0).toUpperCase() + str.slice(1);
}

export function createClientName(client: string, language: string): string {
const clientName = client
export function createModelFolderName(
client: string,
language: string
): string {
const modelFolder = client
.split('-')
.map((part, i) => {
if (language === 'javascript' && i === 0) {
return part;
}

return capitalize(part);
})
.map((part, i) => (i === 0 ? part : capitalize(part)))
.join('');

return clientName;
if (language === 'php') {
return capitalize(modelFolder);
}

return modelFolder;
}

export function createClientName(client: string, language: string): string {
const clientName = createModelFolderName(client, language);

if (language === 'javascript') {
return `${clientName}Api`;
}
return `${capitalize(clientName)}Api`;
}

export async function createOutputDir({
Expand Down
Loading

0 comments on commit 16ea65f

Please sign in to comment.