Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(script): variadic parameters #472

Merged
merged 6 commits into from
May 5, 2022
Merged

feat(script): variadic parameters #472

merged 6 commits into from
May 5, 2022

Conversation

shortcuts
Copy link
Member

🧭 What and Why

🎟 JIRA Ticket: https://algolia.atlassian.net/browse/DI-238

Allow variadic parameters in the CLI, to reduce the number of jobs/complexity of the CI.

Changes included:

(Sorry for the huge PR, it was hard not to break things here and there)

The goal of this PR is to remove any logic of the client path at the CI level, which what makes it extremely verbose.

New CLI usage:

  • before: yarn docker generate javascript search && yarn docker generate javascript recommend
  • now: yarn docker generate javascript search recommend

This change allow us to scope every clients at their base folder level.

Side effects:

  • Kind of use Language type in the CLI https://algolia.atlassian.net/browse/APIC-385
  • Remove double run of eslint for JavaScript client (hyphen issue in jsdoc)
  • Remove common spec bundling before each jobs
  • Remove JS utils bundling before each jobs
  • Single gen matrix (size of Language)
  • Matrix on CTS (size of Language)

🧪 Test

CI :D

@shortcuts shortcuts self-assigned this May 5, 2022
@netlify
Copy link

netlify bot commented May 5, 2022

Deploy Preview for api-clients-automation canceled.

Name Link
🔨 Latest commit 56614ef
🔍 Latest deploy log https://app.netlify.com/sites/api-clients-automation/deploys/6273ec14c449f6000842f5b6

@shortcuts shortcuts force-pushed the feat/cli-variadic branch from e21c23b to 88ce6dc Compare May 5, 2022 10:49
@algolia-bot
Copy link
Collaborator

algolia-bot commented May 5, 2022

✗ The generated branch has been deleted.

If the PR has been merged, you can check the generated code on the main branch.

@shortcuts shortcuts changed the title feat(cli): variadic parameters feat(script): variadic parameters May 5, 2022
@shortcuts shortcuts force-pushed the feat/cli-variadic branch from 88ce6dc to b45fd07 Compare May 5, 2022 11:10
@shortcuts shortcuts requested review from a team, eunjae-lee and millotp and removed request for a team May 5, 2022 11:35
@shortcuts shortcuts marked this pull request as ready for review May 5, 2022 11:35
Copy link
Collaborator

@millotp millotp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing ! One obvious improvement would be to run the CTS directly after a gen is done, we don't have to wait for all languages, but it's already a huge upgrade !

This composite restore all of our artifacts, at their right path.

inputs:
type:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we go full circle with the cache ahah

.github/actions/restore-artifacts/action.yml Outdated Show resolved Hide resolved
.github/actions/restore-artifacts/action.yml Show resolved Hide resolved
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
run: git --no-pager diff
run: yarn cli build specs ${{ matrix.client.toRun }}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should remove the matrix and just use $ {{ fromJSON(needs.setup.outputs.SPECS_MATRIX).client.toRun }}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's more verbose I'm not a fan of it for readability purposes D:

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that way we don't have to click on the CI to see the details !

return clientsConfig[language]?.tests?.extension;
}

export function getTestOutputFolder(language: string): string | undefined {
export function getTestOutputFolder(language: string): string {
return clientsConfig[language]?.tests?.outputFolder;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how is this correct ? ? will return undefined

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The types are really wrong in some places, we need to fix that in a later PR 6920796

if (language === 'all') {
langsTodo = LANGUAGES;
}
if (client === 'all') {
if (client[0] === 'all') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe throw if the first client is all and the length is more than one

scripts/index.ts Outdated Show resolved Hide resolved
scripts/index.ts Outdated Show resolved Hide resolved
scripts/index.ts Outdated Show resolved Hide resolved
Comment on lines +53 to +63
const matrix = LANGUAGES.reduce(
(curr, lang) => ({
...curr,
[lang]: {
path: getLanguageFolder(lang),
toRun: [],
cacheToCompute: [],
},
}),
{} as Record<Language, ToRunMatrix>
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const matrix = LANGUAGES.reduce(
(curr, lang) => ({
...curr,
[lang]: {
path: getLanguageFolder(lang),
toRun: [],
cacheToCompute: [],
},
}),
{} as Record<Language, ToRunMatrix>
);
const matrix: Record<string, ToRunMatrix> = Object.fromEntries(
LANGUAGES.map((lang) => [
lang,
{
path: getLanguageFolder(lang),
toRun: [],
cacheToCompute: [],
},
])
);

There is no good way to do it and keep the type correct without casting, I don't know which one is more readable

@shortcuts
Copy link
Member Author

One obvious improvement would be to run the CTS directly after a gen is done, we don't have to wait for all languages, but it's already a huge upgrade !

Good idea!!

@shortcuts shortcuts requested a review from millotp May 5, 2022 13:45
@shortcuts shortcuts enabled auto-merge (squash) May 5, 2022 15:13
Copy link
Collaborator

@millotp millotp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good ! It's weird that the size of the artifacts is the uncompressed size at upload and download, but when I actually download an artifacts it's the correct size


inputs:
type:
description: Type of artifacts to restore (`all` | `specs` | `javascript` | `js-utils` | `java` | `php`)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove 'java' and 'php' if they are not used ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

@shortcuts shortcuts requested a review from millotp May 5, 2022 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants