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

chore(cts): update dependencies on cts generation for javascript #490

Merged
merged 16 commits into from
May 16, 2022

Conversation

eunjae-lee
Copy link
Contributor

@eunjae-lee eunjae-lee commented May 10, 2022

🧭 What and Why

🎟 JIRA Ticket: https://algolia.atlassian.net/browse/APIC-453

Changes included:

cts generate command now always updates the dependencies in tests/output/javascript/package.json.

I will probably send a separate PR for java and php. I'd like to get this javascript validated first before moving onto other languages.

@netlify
Copy link

netlify bot commented May 10, 2022

Deploy Preview for api-clients-automation canceled.

Name Link
🔨 Latest commit 70fdd86
🔍 Latest deploy log https://app.netlify.com/sites/api-clients-automation/deploys/6282211162e76c000954484a

@algolia-bot
Copy link
Collaborator

algolia-bot commented May 10, 2022

✗ The generated branch has been deleted.

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

@eunjae-lee eunjae-lee changed the title chore(cts): accept an option to update versions chore(cts): update dependencies on cts generation for javascript May 11, 2022
@eunjae-lee eunjae-lee marked this pull request as ready for review May 11, 2022 14:45
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.

Looks good !

},
"dependencies": {
{{#packageVersionMap}}
"@experimental-api-clients-automation/algoliasearch-lite": "{{@experimental-api-clients-automation/algoliasearch-lite}}",
Copy link
Collaborator

Choose a reason for hiding this comment

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

you could iterate on a array of object, and have "{{packageName}}": "{{packageVersion}}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about it, but just left it like that, to be explicit about which dependencies we use for the package. WDTY?

Copy link
Collaborator

Choose a reason for hiding this comment

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

we can be as explicit but in the generator :)

@@ -84,6 +84,12 @@ public void processOpts() {
clientName + testConfig.extension
)
);

if (language.equals("javascript")) {
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 make this generic with a class that will add the correct supporting files and and data ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you give me an example of what the class would look like?

Copy link
Collaborator

Choose a reason for hiding this comment

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

interface VersionManager {
  void addSupportingFiles(...);
  void addData(...);
}

class JavascriptVersionManager implements VersionManager {
//your code
}

And instanciate the correct one in AlgoliaCtsGenerator.java based on the language.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 coming soon

Copy link
Contributor Author

Choose a reason for hiding this comment

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

e532455

@millotp what do you think?

@@ -149,4 +153,15 @@ public static void generateServer(
System.exit(1);
}
}

public static JsonNode readJsonFile(String filePath) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Very cool ! can you replace other instance of the code where we load a json by this method ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -5,17 +5,17 @@
"test": "jest"
Copy link
Member

Choose a reason for hiding this comment

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

We should maybe sort those deps otherwise it will be sorted locally and then unsorted when bumped etc

Copy link
Member

Choose a reason for hiding this comment

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

ah or maybe just the yarn install that will come after will sort them actually

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I was going to ask this question, but why aren't this deps sorted automatically? I thought formatting after the generation would do it, but didn't.

Copy link
Member

Choose a reason for hiding this comment

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

I believe it's yarn that sorts the dependencies in the package.json

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just found it:

After the cts generation, it runs this formatter: https://github.com/algolia/api-clients-automation/blob/7c434506d7d6f23f044841024b0dbc8e9af26514/scripts/formatter.ts#L16:L16

and it runs:

yarn eslint --ext=ts tests/output/javascript/src --fix --no-error-on-unmatched-pattern

that's why tests/output/javascript/package.json is being excluded from the eslint.

Copy link
Member

Choose a reason for hiding this comment

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

ahhh yes we can maybe add an extra line for the package.json if it works then

Copy link
Contributor Author

Choose a reason for hiding this comment

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

d3c14dc

What do you think?

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.

Beautiful ! The version logic has changed a little bit on main but it should make it easier here, you can add utils the same way as in js

@@ -63,31 +67,34 @@ public void processOpts() {
language = (String) additionalProperties.get("language");
client = (String) additionalProperties.get("client");
packageName = (String) additionalProperties.get("packageName");
ctsManager = CtsManagerFactory.getManager(language);
Copy link
Collaborator

Choose a reason for hiding this comment

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

fancy !

@eunjae-lee eunjae-lee marked this pull request as draft May 12, 2022 14:45
@eunjae-lee
Copy link
Contributor Author

I'll mark it as ready for review once I make the CI pass.

@eunjae-lee eunjae-lee marked this pull request as ready for review May 12, 2022 14:57
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.

A last few comments 😅 also can you add the package.json of the test to generation.config.json ?

Comment on lines 157 to 158
bundle.put("packageDependencies", ctsManager.getPackageDependencies());
ctsManager.addExtraToBundle(bundle);
Copy link
Collaborator

Choose a reason for hiding this comment

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

it would be clearer to combine those into one like addSupportingData(bundle), and let the manager add what it wants

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it makes sense 0303223

if (!additionalProperties.has("packageVersion")) {
continue;
}
String packageName = additionalProperties.get("packageName").asText();
Copy link
Collaborator

Choose a reason for hiding this comment

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

packageName is a lie, it's not used for anything other than js because it doesn't change, unless we know other languages that will be split in clients, I think we can remove this notion from the CTS, and remove them from clients.config.json (but keep them for js)

Copy link
Collaborator

Choose a reason for hiding this comment

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

And have this code that his specific to JS in the JavascriptCtsManager

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Bonne idée 2d04ade

Copy link
Member

@shortcuts shortcuts left a comment

Choose a reason for hiding this comment

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

Looks clean!! Pierre said most of it, just one comment more :D

Comment on lines 19 to 30
"@experimental-api-clients-automation/algoliasearch-lite",
"@experimental-api-clients-automation/client-abtesting",
"@experimental-api-clients-automation/client-analytics",
"@experimental-api-clients-automation/client-common",
"@experimental-api-clients-automation/client-insights",
"@experimental-api-clients-automation/client-personalization",
"@experimental-api-clients-automation/client-predict",
"@experimental-api-clients-automation/client-query-suggestions",
"@experimental-api-clients-automation/client-search",
"@experimental-api-clients-automation/client-sources",
"@experimental-api-clients-automation/recommend",
"@experimental-api-clients-automation/requester-node-http"
Copy link
Member

Choose a reason for hiding this comment

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

Maybe this list can be guessed from the packageName in openapitools.json?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done here 2d04ade

@millotp
Copy link
Collaborator

millotp commented May 16, 2022

also can you add the package.json of the test to generation.config.json ?

pls

@eunjae-lee
Copy link
Contributor Author

also can you add the package.json of the test to generation.config.json ?

pls

Oh I missed that part. 70fdd86

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.

None yet

4 participants