Skip to content

Commit 7e226c4

Browse files
authored
feat(scripts): add push to mcp-node on release (#4784)
1 parent 7fbb527 commit 7e226c4

File tree

36 files changed

+130
-29
lines changed

36 files changed

+130
-29
lines changed

.github/workflows/check.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ jobs:
161161
type: minimal
162162

163163
- name: Building specs
164-
run: yarn cli build specs
164+
run: yarn cli build specs -s
165165

166166
- name: Store bundled specs
167167
uses: actions/upload-artifact@v4
@@ -545,7 +545,7 @@ jobs:
545545
type: minimal
546546

547547
- name: Generate documentation specs with code snippets
548-
run: yarn cli build specs --docs
548+
run: yarn cli build specs --docs -s
549549

550550
- name: Read benchmark results
551551
id: benchmark

scripts/ci/codegen/pushToRepository.ts

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import fsp from 'fs/promises';
22
import path, { resolve } from 'path';
33

44
import {
5+
CLIENTS,
56
configureGitHubAuthor,
6-
ensureGitHubToken,
77
exists,
88
getOctokit,
99
gitBranchExists,
@@ -22,16 +22,45 @@ import { getClientsConfigField } from '../../config.ts';
2222
import { commitStartRelease } from './text.ts';
2323

2424
async function handleSpecFiles(spec: SpecsToPush, tempGitDir: string): Promise<void> {
25-
const pathToSpecs = toAbsolutePath(`${tempGitDir}/${spec.output}`);
26-
27-
await run(`cp ${toAbsolutePath('specs/bundled/README.md')} ${pathToSpecs}`);
28-
await run(`cp ${toAbsolutePath('specs/major-breaking-changes-rename.json')} ${pathToSpecs}`);
29-
await run(`cp ${toAbsolutePath('config/clients.config.json')} ${pathToSpecs}`);
30-
await run(`cp ${toAbsolutePath('docs/bundled/*.json')} ${pathToSpecs}`);
31-
await run(`cp ${toAbsolutePath('docs/bundled/*.yml')} ${pathToSpecs}`);
32-
await run(`cp ${toAbsolutePath('docs/versions-history-with-sla-and-support-policy.json')} ${pathToSpecs}`);
25+
const output = toAbsolutePath(`${tempGitDir}/${spec.output}`);
26+
27+
if (spec.includeSnippets) {
28+
await run(`cp ${toAbsolutePath('docs/bundled/*-snippets.json')} ${output}`);
29+
}
30+
31+
if (spec.includeSLA) {
32+
await run(`cp ${toAbsolutePath('specs/bundled/README.md')} ${output}`);
33+
await run(`cp ${toAbsolutePath('specs/major-breaking-changes-rename.json')} ${output}`);
34+
await run(`cp ${toAbsolutePath('config/clients.config.json')} ${output}`);
35+
await run(`cp ${toAbsolutePath('docs/versions-history-with-sla-and-support-policy.json')} ${output}`);
36+
}
37+
3338
// adblock extensions ban words like `analytics` so we use a different file name just so the doc dans render it
34-
await run(`mv ${pathToSpecs}/analytics.yml ${pathToSpecs}/searchstats.yml`);
39+
if (spec.ext === 'yml') {
40+
await run(`mv ${output}/analytics.yml ${output}/searchstats.yml`);
41+
}
42+
43+
for (const client of CLIENTS) {
44+
const pathToBundledSpec = toAbsolutePath(`docs/bundled/${client}.${spec.ext}`);
45+
46+
if (!(await exists(pathToBundledSpec))) {
47+
continue;
48+
}
49+
50+
const outputFile = `${output}/${client}.${spec.ext}`;
51+
52+
await run(`cp ${pathToBundledSpec} ${outputFile}`);
53+
54+
if (spec.placeholderVariables) {
55+
let file = await fsp.readFile(outputFile, 'utf8');
56+
57+
for (const [k, v] of Object.entries(spec.placeholderVariables)) {
58+
file = file.replace(k, v);
59+
}
60+
61+
await fsp.writeFile(outputFile, file);
62+
}
63+
}
3564
}
3665

3766
async function handleGuideFiles(guide: GuidesToPush, tempGitDir: string): Promise<void> {
@@ -80,8 +109,6 @@ async function handleGuideFiles(guide: GuidesToPush, tempGitDir: string): Promis
80109
}
81110

82111
async function pushToRepository(repository: string, config: RepositoryConfiguration): Promise<void> {
83-
const githubToken = ensureGitHubToken();
84-
85112
const lastCommitMessage = await run('git log -1 --format="%s"');
86113
const author = (await run('git log -1 --format="Co-authored-by: %an <%ae>"')).trim();
87114
const coAuthors = (await run('git log -1 --format="%(trailers:key=Co-authored-by)"'))
@@ -100,8 +127,7 @@ async function pushToRepository(repository: string, config: RepositoryConfigurat
100127
const tempGitDir = resolve(process.env.RUNNER_TEMP! || toAbsolutePath('foo/local/test'), repository);
101128
await fsp.rm(tempGitDir, { force: true, recursive: true });
102129

103-
const githubURL = `https://${githubToken}:${githubToken}@github.com/${OWNER}/${repository}`;
104-
await run(`git clone --depth 1 ${githubURL} ${tempGitDir}`);
130+
await run(`gh repo clone ${OWNER}/${repository} ${tempGitDir}`);
105131

106132
for (const task of config.tasks) {
107133
await run(`git checkout ${config.baseBranch}`, { cwd: tempGitDir });

scripts/ci/codegen/types.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,23 @@ export type GuidesToPush = {
1313
};
1414

1515
export type SpecsToPush = {
16+
// the type of changes to push to the repository
1617
type: 'specs';
18+
19+
// the ext of the specs to be pushed to the repository
20+
ext: 'json' | 'yml';
21+
22+
// whether we should include code snippets or not
23+
includeSnippets?: boolean;
24+
25+
// whether we should include SLA related informations or not
26+
includeSLA?: boolean;
27+
28+
// the name of the directory to push the files to
1729
output: string;
30+
31+
// a key-value of the fields to replace, with the name you'd like to use instead
32+
placeholderVariables?: Record<string, string>;
1833
};
1934

2035
type RepositoryTask = {
@@ -35,7 +50,7 @@ export type RepositoryConfiguration = {
3550
tasks: Array<RepositoryTask>;
3651
};
3752

38-
export const pushToRepositoryConfiguration: { [k in 'AlgoliaWeb' | 'doc']: RepositoryConfiguration } = {
53+
export const pushToRepositoryConfiguration: { [k in 'AlgoliaWeb' | 'doc' | 'mcp-node']: RepositoryConfiguration } = {
3954
AlgoliaWeb: {
4055
baseBranch: 'develop',
4156
tasks: [
@@ -72,7 +87,10 @@ export const pushToRepositoryConfiguration: { [k in 'AlgoliaWeb' | 'doc']: Repos
7287
commitMessage: 'feat: update specs and supported versions',
7388
files: {
7489
type: 'specs',
90+
ext: 'yml',
7591
output: 'app_data/api/specs',
92+
includeSnippets: true,
93+
includeSLA: true,
7694
},
7795
},
7896
{
@@ -85,4 +103,19 @@ export const pushToRepositoryConfiguration: { [k in 'AlgoliaWeb' | 'doc']: Repos
85103
},
86104
],
87105
},
106+
'mcp-node': {
107+
baseBranch: 'main',
108+
tasks: [
109+
{
110+
prBranch: 'feat/automated-update-for-specs',
111+
commitMessage: 'feat: update specs',
112+
files: {
113+
type: 'specs',
114+
ext: 'json',
115+
output: 'src/data',
116+
placeholderVariables: { appId: 'applicationId' },
117+
},
118+
},
119+
],
120+
},
88121
};

scripts/cli/index.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ buildCommand
139139
.option('-s, --skip-cache', 'skip cache checking to force building specs')
140140
.option('-j, --json', 'outputs the spec in JSON instead of yml')
141141
.option('-d, --docs', 'generates the doc specs with the code snippets')
142-
.action(async (clientArg: string[], { verbose, skipCache, outputJson, docs }) => {
142+
.action(async (clientArg: string[], { verbose, skipCache, json, docs }) => {
143143
const { client, clientList } = transformSelection({
144144
langArg: ALL,
145145
clientArg,
@@ -149,10 +149,20 @@ buildCommand
149149

150150
await buildSpecs({
151151
clients: client[0] === ALL ? clientList : client,
152-
outputFormat: outputJson ? 'json' : 'yml',
153-
docs: Boolean(docs),
152+
outputFormat: json ? 'json' : 'yml',
153+
docs: docs || json,
154154
useCache: !skipCache,
155155
});
156+
157+
// when building for the docs we generate both formats
158+
if (docs && !json) {
159+
await buildSpecs({
160+
clients: client[0] === ALL ? clientList : client,
161+
outputFormat: 'json',
162+
docs: true,
163+
useCache: !skipCache,
164+
});
165+
}
156166
});
157167

158168
const ctsCommand = program.command('cts').description('Generate and run the CTS tests');

scripts/specs/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@ const ALGOLIASEARCH_LITE_OPERATIONS = ['search', 'customPost', 'getRecommendatio
1919
async function buildLiteSpec({
2020
spec,
2121
bundledPath,
22+
outputFormat,
2223
docs,
2324
useCache,
24-
}: {
25+
}: BaseBuildSpecsOptions & {
2526
spec: string;
2627
bundledPath: string;
27-
docs: boolean;
28-
useCache: boolean;
2928
}): Promise<void> {
30-
await buildSpec({ spec: 'recommend', outputFormat: 'yml', docs, useCache });
29+
await buildSpec({ spec: 'recommend', outputFormat: outputFormat, docs, useCache });
3130

3231
const base = yaml.load(await fsp.readFile(toAbsolutePath(bundledPath), 'utf8')) as Spec;
3332
const recommend = yaml.load(
@@ -51,7 +50,7 @@ async function buildLiteSpec({
5150
await fsp.writeFile(bundledPath, yaml.dump(lite));
5251

5352
// remove unused components for the outputted light spec
54-
await run(`yarn openapi bundle ${bundledPath} -o ${bundledPath} --ext yml --remove-unused-components`);
53+
await run(`yarn redocly bundle ${bundledPath} -o ${bundledPath} --ext ${outputFormat} --remove-unused-components`);
5554

5655
await bundleSpecsForClient(bundledPath, spec);
5756
}
@@ -73,7 +72,7 @@ async function buildSpec({
7372

7473
// In case of lite we use a the `search` spec as a base because only its bundled form exists.
7574
const specBase = isLiteSpec ? 'search' : spec;
76-
const logSuffix = docs ? 'doc spec' : 'spec';
75+
const logSuffix = `${outputFormat} ${docs ? 'doc spec' : 'spec'}`;
7776
const basePath = docs ? 'docs/' : 'specs/';
7877
const deps = isLiteSpec ? ['search', 'recommend'] : [spec];
7978
const cache = new Cache({
@@ -102,7 +101,7 @@ async function buildSpec({
102101

103102
// Then bundle the file
104103
const bundledPath = toAbsolutePath(`${basePath}/bundled/${spec}.${outputFormat}`);
105-
await run(`yarn openapi bundle specs/${specBase}/spec.yml -o ${bundledPath} --ext ${outputFormat}`);
104+
await run(`yarn redocly bundle specs/${specBase}/spec.yml -o ${bundledPath} --ext ${outputFormat} `);
106105

107106
if (!(await exists(bundledPath))) {
108107
throw new Error(`Bundled file not found ${bundledPath}.`);
@@ -115,13 +114,14 @@ async function buildSpec({
115114
await buildLiteSpec({
116115
spec,
117116
bundledPath: toAbsolutePath(bundledPath),
117+
outputFormat,
118118
docs,
119119
useCache,
120120
});
121121
}
122122

123123
spinner.text = `validating '${spec}' ${logSuffix}`;
124-
await run(`yarn openapi lint ${bundledPath}`);
124+
await run(`yarn redocly lint ${bundledPath}`);
125125

126126
spinner.text = `linting '${spec}' ${logSuffix}`;
127127
await run(`yarn specs:fix ${basePath}/bundled/${spec}.${outputFormat}`);

specs/abtesting/paths/abtests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ get:
5757
tags:
5858
- abtest
5959
operationId: listABTests
60+
x-mcp-tool: true
6061
x-acl:
6162
- analytics
6263
summary: List all A/B tests

specs/abtesting/spec.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ servers:
6565
- url: https://analytics.{region}.algolia.com
6666
variables:
6767
region:
68+
description: The region where your Algolia application is hosted.
6869
enum:
6970
- us
7071
- de

specs/analytics/paths/search/getNoResultsRate.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ get:
22
tags:
33
- search
44
operationId: getNoResultsRate
5+
x-mcp-tool: true
56
x-acl:
67
- analytics
78
summary: Retrieve no results rate

specs/analytics/paths/search/getTopHits.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ get:
22
tags:
33
- search
44
operationId: getTopHits
5+
x-mcp-tool: true
56
x-acl:
67
- analytics
78
summary: Retrieve top search results

specs/analytics/paths/search/getTopSearches.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ get:
22
tags:
33
- search
44
operationId: getTopSearches
5+
x-mcp-tool: true
56
x-acl:
67
- analytics
78
summary: Retrieve top searches

specs/analytics/spec.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ servers:
7878
- url: https://analytics.{region}.algolia.com
7979
variables:
8080
region:
81+
description: The region where your Algolia application is hosted.
8182
enum:
8283
- us
8384
- de

specs/ingestion/paths/destinations/destinations.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ get:
44
summary: List destinations
55
description: Retrieves a list of destinations.
66
operationId: listDestinations
7+
x-mcp-tool: true
78
x-acl:
89
- addObject
910
- deleteIndex

specs/ingestion/paths/sources/sources.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ get:
44
summary: List sources
55
description: Retrieves a list of sources.
66
operationId: listSources
7+
x-mcp-tool: true
78
x-acl:
89
- addObject
910
- deleteIndex

specs/ingestion/paths/tasks/v2/tasks.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ get:
44
summary: List tasks
55
description: Retrieves a list of tasks.
66
operationId: listTasks
7+
x-mcp-tool: true
78
x-acl:
89
- addObject
910
- deleteIndex

specs/ingestion/paths/transformations/transformations.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ get:
44
summary: List transformations
55
description: Retrieves a list of transformations.
66
operationId: listTransformations
7+
x-mcp-tool: true
78
x-acl:
89
- addObject
910
- deleteIndex

specs/ingestion/spec.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ servers:
5252
- url: https://data.{region}.algolia.com
5353
variables:
5454
region:
55+
description: The region where your Algolia application is hosted.
5556
enum:
5657
- eu
5758
- us

specs/insights/spec.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ servers:
6666
- url: https://insights.{region}.algolia.io
6767
variables:
6868
region:
69+
description: The region where your Algolia application is hosted.
6970
enum:
7071
- us
7172
- de

specs/monitoring/paths/getClusterStatus.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ get:
22
summary: Retrieve cluster status
33
description: Retrieves the status of selected clusters.
44
operationId: getClusterStatus
5+
x-mcp-tool: true
56
tags:
67
- status
78
security: []

specs/monitoring/paths/getIncidents.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ get:
22
summary: Retrieve all incidents
33
description: Retrieves known incidents for all clusters.
44
operationId: getIncidents
5+
x-mcp-tool: true
56
security: []
67
tags:
78
- incidents

specs/personalization/spec.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ servers:
6767
- url: https://personalization.{region}.algolia.com
6868
variables:
6969
region:
70+
description: The region where your Algolia application is hosted.
7071
enum:
7172
- us
7273
- eu

specs/query-suggestions/paths/getConfigurationStatus.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ get:
22
tags:
33
- configurations
44
operationId: getConfigStatus
5+
x-mcp-tool: true
56
x-acl:
67
- settings
78
summary: Retrieve configuration status

specs/query-suggestions/paths/getLogFile.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ get:
22
tags:
33
- logs
44
operationId: getLogFile
5+
x-mcp-tool: true
56
x-acl:
67
- settings
78
summary: Retrieve logs

0 commit comments

Comments
 (0)