Skip to content

Commit

Permalink
feat: add support for fetching a greeting CTA as part of the update f…
Browse files Browse the repository at this point in the history
…low 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
  • Loading branch information
nirinchev authored Feb 12, 2025
1 parent 33f85ff commit 80fc072
Show file tree
Hide file tree
Showing 22 changed files with 837 additions and 86 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/update-cta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Update greeting CTA
on:
push:
branches:
- main
paths:
- config/cta.conf.js
workflow_dispatch:
inputs:
dry-run:
description: Run the script without updating the CTA
type: boolean
required: false
default: false
environment:
description: The environment to run the script in - must have the DOWNLOAD_CENTER_AWS_KEY and DOWNLOAD_CENTER_AWS_SECRET secrets configured
type: environment
required: true
default: CTA-Production

permissions:
contents: read

jobs:
dry-run:
name: Update greeting CTA
runs-on: ubuntu-latest
environment: ${{ github.event.inputs.environment || 'CTA-Production'}}
env:
npm_config_loglevel: verbose
npm_config_foreground_scripts: "true"
PUPPETEER_SKIP_DOWNLOAD: "true"
DOWNLOAD_CENTER_AWS_KEY: ${{ secrets.DOWNLOAD_CENTER_AWS_KEY }}
DOWNLOAD_CENTER_AWS_SECRET: ${{ secrets.DOWNLOAD_CENTER_AWS_SECRET }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ^20.x
cache: "npm"

- name: Install Dependencies and Compile
run: |
npm ci
npm run compile
- name: Update greeting CTA
run: |
npm run update-cta ${{ github.event.inputs.dry-run && '-- --dry-run' || '' }}
6 changes: 6 additions & 0 deletions config/build.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ const MANPAGE_NAME = 'mongosh.1.gz'
*/
const PACKAGE_VARIANT = process.env.PACKAGE_VARIANT;

const CTA_CONFIG = require(path.join(ROOT, 'config', 'cta-config.json'));

const CTA_CONFIG_SCHEMA = require(path.join(ROOT, 'config', 'cta-config.schema.json'));

/**
* Export the configuration for the build.
*/
Expand Down Expand Up @@ -194,4 +198,6 @@ module.exports = {
downloadPath: path.resolve(TMP_DIR, 'manpage'),
fileName: MANPAGE_NAME,
},
ctaConfig: CTA_CONFIG,
ctaConfigSchema: CTA_CONFIG_SCHEMA,
};
3 changes: 3 additions & 0 deletions config/cta-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"$schema": "./cta-config.schema.json"
}
94 changes: 94 additions & 0 deletions config/cta-config.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"$id": "https://mongodb.com/schemas/mongosh/cta-config",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "CTAConfig",
"type": "object",
"properties": {
"*": {
"$ref": "#/definitions/GreetingCTADetails",
"description": "The default CTA for all versions that don't have an explicit one defined."
},
"$schema": {
"type": "string"
}
},
"patternProperties": {
"^(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-]+)*))?$": {
"$ref": "#/definitions/GreetingCTADetails",
"description": "The CTA for a specific version.",
"$comment": "The property name must be a valid semver string."
}
},
"additionalProperties": false,
"definitions": {
"GreetingCTADetails": {
"type": "object",
"additionalProperties": false,
"properties": {
"chunks": {
"description": "The chunks that make up the CTA. They will be combined sequentially with no additional spacing added.",
"items": {
"properties": {
"style": {
"description": "The style to apply to the text. It must match the values from clr.ts/StyleDefinition.",
"enum": [
"reset",
"bold",
"italic",
"underline",
"fontDefault",
"font2",
"font3",
"font4",
"font5",
"font6",
"imageNegative",
"imagePositive",
"black",
"red",
"green",
"yellow",
"blue",
"magenta",
"cyan",
"white",
"grey",
"gray",
"bg-black",
"bg-red",
"bg-green",
"bg-yellow",
"bg-blue",
"bg-magenta",
"bg-cyan",
"bg-white",
"bg-grey",
"bg-gray",
"mongosh:warning",
"mongosh:error",
"mongosh:section-header",
"mongosh:uri",
"mongosh:filename",
"mongosh:additional-error-info"
],
"type": "string"
},
"text": {
"type": "string",
"description": "The text in the chunk."
}
},
"type": "object",
"required": [
"text"
]
},
"type": "array"
}
},
"required": [
"chunks"
]
}
}
}
23 changes: 23 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"compile-all": "npm run compile-compass && npm run compile-exec",
"evergreen-release": "cd packages/build && npm run evergreen-release --",
"release": "cd packages/build && npm run release --",
"update-cta": "cd packages/build && npm run update-cta --",
"report-missing-help": "npm run report-missing-help --workspace @mongosh/shell-api",
"report-supported-api": "npm run report-supported-api --workspace @mongosh/shell-api",
"post-process-nyc": "ts-node scripts/nyc/post-process-nyc-output.ts",
Expand Down
4 changes: 3 additions & 1 deletion packages/build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"publish": "ts-node src/index.ts publish",
"bump-auxiliary": "ts-node src/index.ts bump --auxiliary",
"publish-auxiliary": "ts-node src/index.ts publish --auxiliary",
"reformat": "npm run prettier -- --write . && npm run eslint --fix"
"reformat": "npm run prettier -- --write . && npm run eslint --fix",
"update-cta": "ts-node src/index.ts update-cta"
},
"license": "Apache-2.0",
"publishConfig": {
Expand Down Expand Up @@ -69,6 +70,7 @@
"@mongodb-js/monorepo-tools": "^1.1.16",
"@mongodb-js/signing-utils": "^0.3.7",
"@octokit/rest": "^17.9.0",
"ajv": "^8.17.1",
"aws-sdk": "^2.674.0",
"boxednode": "^2.4.3",
"command-exists": "^1.2.9",
Expand Down
18 changes: 18 additions & 0 deletions packages/build/src/config/config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Schema } from 'ajv';
import type { PackageInformationProvider } from '../packaging/package';
import type { PackageVariant } from './build-variant';

Expand All @@ -7,6 +8,21 @@ interface ManPageConfig {
fileName: string;
}

// This needs to match the interface in cli-repl/update-notification-manager.ts
export interface GreetingCTADetails {
chunks: {
text: string;
// This is actually cli-repl/clr.ts/StyleDefinition, but we can't import it here.
// The correct type is already enforced in json schema, so treating it as a generic
// string is fine.
style?: string;
}[];
}

export type CTAConfig = {
[version: string | '*']: GreetingCTADetails;
};

/**
* Defines the configuration interface for the build system.
*/
Expand Down Expand Up @@ -47,4 +63,6 @@ export interface Config {
manpage?: ManPageConfig;
isDryRun?: boolean;
useAuxiliaryPackagesOnly?: boolean;
ctaConfig: CTAConfig;
ctaConfigSchema: Schema;
}
Loading

0 comments on commit 80fc072

Please sign in to comment.