Skip to content

guides: add new generator #3837

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

Merged
merged 31 commits into from
Oct 2, 2024
Merged

guides: add new generator #3837

merged 31 commits into from
Oct 2, 2024

Conversation

millotp
Copy link
Collaborator

@millotp millotp commented Sep 26, 2024

🧭 What and Why

🎟 JIRA Ticket: https://algolia.atlassian.net/browse/DI-2974 https://algolia.atlassian.net/browse/DI-2975 https://algolia.atlassian.net/browse/DI-2976

Changes included:

supersede #3836

this PR adds a new generator in order to be able to generate guides.

Context

The onboarding team creates guides using the API client plus some other external libraries (e.g. fetch) in order to showcase how to push data to Algolia.

Today they only provide snippets for JavaScript, and it requires us manual intervention, manual testing, linting etc.

They'd like to be able to keep their guides up to dates with our API clients, and at some point, provide guides for more languages than just JavaScript.

In their initial RFC, they were proposing to create a CI that does exactly what we do, so in order to platformize a bit more our repository, @shortcuts suggested to leverage our tooling to generate their guides

How does it work

This PR is not complete, we are missing a few things that will be tackled in https://algolia.atlassian.net/browse/DI-2984 and https://algolia.atlassian.net/browse/DI-2985 but the goal is simple

From a mustache file (located in templates/${language}/guides/${api}), and a guide definition (located in tests/CTS/guides/${api}), generate a fully working guide, self contained file, for every available clients.

Example

I create my templates/go/guides/search/saveObjectsWithSofa.mustache file:

{{> snippets/import}}

{{> snippets/init}}

// do boilerplate stuff with sofa
return {{#dynamicSnippet}}saveObjectsWithSofa{{/dynamicSnippet}}

The dynamic snippet template will read the tests/CTS/guides/search/snippets.json:

{
  "saveObjectsWithSofa": {
    "method": "saveObjects",
    "parameters": {
      "indexName": "sofaaa",
      "objects": [
        {
          "$var": "objects"
        }
      ]
    }
  }
}

The key that has been passed to the dynamic template (saveObjectsWithSofa) is there and contains the method to find in the spec, and the parameters to feed it. The parametersWithDataType logic is the same as for the tests and snippets generator, as well as for the mustaches file.

You can now write for example templates/php/guides/search/saveObjectsWithSofa.mustache, the process will be the same.

Other changes

We don't need to have the snippets folder/files anymore, just the JSON file output for the documentation. So we removed it from the repo, and ignored it, it now only lives on the CI

@millotp millotp self-assigned this Sep 26, 2024
@algolia-bot
Copy link
Collaborator

algolia-bot commented Sep 26, 2024

✔️ Code generated!

Name Link
🪓 Triggered by d1a7b547f0e4b90316534ceb461edaea657dbb88
🍃 Generated commit 5cab092ff18bbe36ba091384a400775b5e285e7b
🌲 Generated branch generated/feat/guides-gen
📊 Benchmark results

Benchmarks performed on the method using a mock server, the results might not reflect the real-world performance.

Language Req/s
javascript 1663
go 1591
php 1460
csharp 1349
java 1129
python 1029
ruby 888
swift 755

@shortcuts shortcuts self-assigned this Sep 26, 2024
@millotp millotp changed the title feat(guides): generate guides feat(snippets): generate guides Sep 26, 2024
@millotp millotp changed the title feat(snippets): generate guides feat(guides): generate guides Sep 26, 2024
@shortcuts shortcuts changed the title feat(guides): generate guides guides: generate guides Sep 26, 2024
Comment on lines 18 to 33
"prout": {
"method": "prout",
"parameters": {
"indexName": "cts_e2e_saveObjects_${{language}}",
"objects": [
{
"objectID": "1",
"name": "Adam"
},
{
"objectID": "2",
"name": "Benoit"
}
]
}
}
Copy link
Member

Choose a reason for hiding this comment

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

yes

@shortcuts shortcuts marked this pull request as ready for review September 26, 2024 15:08
@shortcuts shortcuts requested a review from a team as a code owner September 26, 2024 15:08
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.

i've rarely seen a pr this perfect

Copy link

github-actions bot commented Sep 26, 2024

@shortcuts
Copy link
Member

of course it's perfect

@shortcuts shortcuts changed the title guides: generate guides guides: add new generator Sep 27, 2024
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.

This is wonderful

@millotp millotp merged commit b694837 into main Oct 2, 2024
28 checks passed
@millotp millotp deleted the feat/guides-gen branch October 2, 2024 16:03
algolia-bot added a commit that referenced this pull request Oct 2, 2024
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.

4 participants