Skip to content

Commit 80fc072

Browse files
authored
feat: add support for fetching a greeting CTA as part of the update flow MONGOSH-1897 (#2254)
* feat: add support for fetching a greeting CTA as part of the update flow * Add a comment * Wire up some basic cli commands for updating the cta * Add a test * Add more tests, github workflow * Rework cta validations * CR comments * fix lint
1 parent 33f85ff commit 80fc072

File tree

22 files changed

+837
-86
lines changed

22 files changed

+837
-86
lines changed

.github/workflows/update-cta.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Update greeting CTA
2+
on:
3+
push:
4+
branches:
5+
- main
6+
paths:
7+
- config/cta.conf.js
8+
workflow_dispatch:
9+
inputs:
10+
dry-run:
11+
description: Run the script without updating the CTA
12+
type: boolean
13+
required: false
14+
default: false
15+
environment:
16+
description: The environment to run the script in - must have the DOWNLOAD_CENTER_AWS_KEY and DOWNLOAD_CENTER_AWS_SECRET secrets configured
17+
type: environment
18+
required: true
19+
default: CTA-Production
20+
21+
permissions:
22+
contents: read
23+
24+
jobs:
25+
dry-run:
26+
name: Update greeting CTA
27+
runs-on: ubuntu-latest
28+
environment: ${{ github.event.inputs.environment || 'CTA-Production'}}
29+
env:
30+
npm_config_loglevel: verbose
31+
npm_config_foreground_scripts: "true"
32+
PUPPETEER_SKIP_DOWNLOAD: "true"
33+
DOWNLOAD_CENTER_AWS_KEY: ${{ secrets.DOWNLOAD_CENTER_AWS_KEY }}
34+
DOWNLOAD_CENTER_AWS_SECRET: ${{ secrets.DOWNLOAD_CENTER_AWS_SECRET }}
35+
steps:
36+
- uses: actions/checkout@v4
37+
- uses: actions/setup-node@v4
38+
with:
39+
node-version: ^20.x
40+
cache: "npm"
41+
42+
- name: Install Dependencies and Compile
43+
run: |
44+
npm ci
45+
npm run compile
46+
47+
- name: Update greeting CTA
48+
run: |
49+
npm run update-cta ${{ github.event.inputs.dry-run && '-- --dry-run' || '' }}

config/build.conf.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ const MANPAGE_NAME = 'mongosh.1.gz'
7575
*/
7676
const PACKAGE_VARIANT = process.env.PACKAGE_VARIANT;
7777

78+
const CTA_CONFIG = require(path.join(ROOT, 'config', 'cta-config.json'));
79+
80+
const CTA_CONFIG_SCHEMA = require(path.join(ROOT, 'config', 'cta-config.schema.json'));
81+
7882
/**
7983
* Export the configuration for the build.
8084
*/
@@ -194,4 +198,6 @@ module.exports = {
194198
downloadPath: path.resolve(TMP_DIR, 'manpage'),
195199
fileName: MANPAGE_NAME,
196200
},
201+
ctaConfig: CTA_CONFIG,
202+
ctaConfigSchema: CTA_CONFIG_SCHEMA,
197203
};

config/cta-config.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"$schema": "./cta-config.schema.json"
3+
}

config/cta-config.schema.json

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
{
2+
"$id": "https://mongodb.com/schemas/mongosh/cta-config",
3+
"$schema": "http://json-schema.org/draft-07/schema#",
4+
"title": "CTAConfig",
5+
"type": "object",
6+
"properties": {
7+
"*": {
8+
"$ref": "#/definitions/GreetingCTADetails",
9+
"description": "The default CTA for all versions that don't have an explicit one defined."
10+
},
11+
"$schema": {
12+
"type": "string"
13+
}
14+
},
15+
"patternProperties": {
16+
"^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$": {
17+
"$ref": "#/definitions/GreetingCTADetails",
18+
"description": "The CTA for a specific version.",
19+
"$comment": "The property name must be a valid semver string."
20+
}
21+
},
22+
"additionalProperties": false,
23+
"definitions": {
24+
"GreetingCTADetails": {
25+
"type": "object",
26+
"additionalProperties": false,
27+
"properties": {
28+
"chunks": {
29+
"description": "The chunks that make up the CTA. They will be combined sequentially with no additional spacing added.",
30+
"items": {
31+
"properties": {
32+
"style": {
33+
"description": "The style to apply to the text. It must match the values from clr.ts/StyleDefinition.",
34+
"enum": [
35+
"reset",
36+
"bold",
37+
"italic",
38+
"underline",
39+
"fontDefault",
40+
"font2",
41+
"font3",
42+
"font4",
43+
"font5",
44+
"font6",
45+
"imageNegative",
46+
"imagePositive",
47+
"black",
48+
"red",
49+
"green",
50+
"yellow",
51+
"blue",
52+
"magenta",
53+
"cyan",
54+
"white",
55+
"grey",
56+
"gray",
57+
"bg-black",
58+
"bg-red",
59+
"bg-green",
60+
"bg-yellow",
61+
"bg-blue",
62+
"bg-magenta",
63+
"bg-cyan",
64+
"bg-white",
65+
"bg-grey",
66+
"bg-gray",
67+
"mongosh:warning",
68+
"mongosh:error",
69+
"mongosh:section-header",
70+
"mongosh:uri",
71+
"mongosh:filename",
72+
"mongosh:additional-error-info"
73+
],
74+
"type": "string"
75+
},
76+
"text": {
77+
"type": "string",
78+
"description": "The text in the chunk."
79+
}
80+
},
81+
"type": "object",
82+
"required": [
83+
"text"
84+
]
85+
},
86+
"type": "array"
87+
}
88+
},
89+
"required": [
90+
"chunks"
91+
]
92+
}
93+
}
94+
}

package-lock.json

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"compile-all": "npm run compile-compass && npm run compile-exec",
4040
"evergreen-release": "cd packages/build && npm run evergreen-release --",
4141
"release": "cd packages/build && npm run release --",
42+
"update-cta": "cd packages/build && npm run update-cta --",
4243
"report-missing-help": "npm run report-missing-help --workspace @mongosh/shell-api",
4344
"report-supported-api": "npm run report-supported-api --workspace @mongosh/shell-api",
4445
"post-process-nyc": "ts-node scripts/nyc/post-process-nyc-output.ts",

packages/build/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
"publish": "ts-node src/index.ts publish",
3131
"bump-auxiliary": "ts-node src/index.ts bump --auxiliary",
3232
"publish-auxiliary": "ts-node src/index.ts publish --auxiliary",
33-
"reformat": "npm run prettier -- --write . && npm run eslint --fix"
33+
"reformat": "npm run prettier -- --write . && npm run eslint --fix",
34+
"update-cta": "ts-node src/index.ts update-cta"
3435
},
3536
"license": "Apache-2.0",
3637
"publishConfig": {
@@ -69,6 +70,7 @@
6970
"@mongodb-js/monorepo-tools": "^1.1.16",
7071
"@mongodb-js/signing-utils": "^0.3.7",
7172
"@octokit/rest": "^17.9.0",
73+
"ajv": "^8.17.1",
7274
"aws-sdk": "^2.674.0",
7375
"boxednode": "^2.4.3",
7476
"command-exists": "^1.2.9",

packages/build/src/config/config.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { Schema } from 'ajv';
12
import type { PackageInformationProvider } from '../packaging/package';
23
import type { PackageVariant } from './build-variant';
34

@@ -7,6 +8,21 @@ interface ManPageConfig {
78
fileName: string;
89
}
910

11+
// This needs to match the interface in cli-repl/update-notification-manager.ts
12+
export interface GreetingCTADetails {
13+
chunks: {
14+
text: string;
15+
// This is actually cli-repl/clr.ts/StyleDefinition, but we can't import it here.
16+
// The correct type is already enforced in json schema, so treating it as a generic
17+
// string is fine.
18+
style?: string;
19+
}[];
20+
}
21+
22+
export type CTAConfig = {
23+
[version: string | '*']: GreetingCTADetails;
24+
};
25+
1026
/**
1127
* Defines the configuration interface for the build system.
1228
*/
@@ -47,4 +63,6 @@ export interface Config {
4763
manpage?: ManPageConfig;
4864
isDryRun?: boolean;
4965
useAuxiliaryPackagesOnly?: boolean;
66+
ctaConfig: CTAConfig;
67+
ctaConfigSchema: Schema;
5068
}

0 commit comments

Comments
 (0)