-
Notifications
You must be signed in to change notification settings - Fork 67
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
feat: add support for fetching a greeting CTA as part of the update flow MONGOSH-1897 #2254
Open
nirinchev
wants to merge
7
commits into
main
Choose a base branch
from
ni/cta
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0549169
feat: add support for fetching a greeting CTA as part of the update flow
nirinchev 43efe22
Add a comment
nirinchev 2a0955f
Wire up some basic cli commands for updating the cta
nirinchev 0c60796
Add a test
nirinchev 3f62f0c
Merge branch 'main' into ni/cta
nirinchev 156a2cf
Add more tests, github workflow
nirinchev 9d87c8d
Merge branch 'main' into ni/cta
nirinchev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
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 | ||
|
||
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' || '' }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
awsAccessKeyId: process.env.DOWNLOAD_CENTER_AWS_KEY, | ||
awsSecretAccessKey: process.env.DOWNLOAD_CENTER_AWS_SECRET, | ||
ctas: { | ||
// Define the ctas per version here. '*' is the default cta which will be shown if there's no specific cta | ||
// for the current version. | ||
// '*': { | ||
// chunks: [ | ||
// { text: 'Example', style: 'bold' }, | ||
// ] | ||
// }, | ||
// '1.2.3': { | ||
// chunks: [ | ||
// { text: 'Example', style: 'mongosh:uri' }, | ||
// ] | ||
// } | ||
}, | ||
isDryRun: false, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,9 @@ import { | |
getUpdatedDownloadCenterConfig, | ||
createAndPublishDownloadCenterConfig, | ||
createJsonFeedEntry, | ||
updateJsonFeedCTA, | ||
UpdateCTAConfig, | ||
JsonFeed, | ||
} from './config'; | ||
import { promises as fs } from 'fs'; | ||
import path from 'path'; | ||
|
@@ -529,4 +532,225 @@ describe('DownloadCenter config', function () { | |
expect(serverTargets).to.include(target); | ||
}); | ||
}); | ||
|
||
describe('updateJsonFeedCTA', function () { | ||
let dlCenter: any; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. very nit: also a |
||
let uploadConfig: sinon.SinonStub; | ||
let downloadConfig: sinon.SinonStub; | ||
let uploadAsset: sinon.SinonStub; | ||
let downloadAsset: sinon.SinonStub; | ||
|
||
const existingUploadedJsonFeed = require(path.resolve( | ||
__dirname, | ||
'..', | ||
'..', | ||
'test', | ||
'fixtures', | ||
'cta-versions.json' | ||
)) as JsonFeed; | ||
|
||
const getConfig = (ctas: UpdateCTAConfig['ctas']): UpdateCTAConfig => { | ||
return { | ||
ctas, | ||
isDryRun: false, | ||
awsAccessKeyId: 'accessKey', | ||
awsSecretAccessKey: 'secretKey', | ||
}; | ||
}; | ||
|
||
const getUploadedJsonFeed = (): JsonFeed => { | ||
return JSON.parse(uploadAsset.lastCall.args[1]) as JsonFeed; | ||
}; | ||
|
||
beforeEach(function () { | ||
uploadConfig = sinon.stub(); | ||
downloadConfig = sinon.stub(); | ||
uploadAsset = sinon.stub(); | ||
downloadAsset = sinon.stub(); | ||
dlCenter = sinon.stub(); | ||
|
||
downloadAsset.returns(JSON.stringify(existingUploadedJsonFeed)); | ||
|
||
dlCenter.returns({ | ||
downloadConfig, | ||
uploadConfig, | ||
uploadAsset, | ||
downloadAsset, | ||
}); | ||
}); | ||
|
||
for (let dryRun of [false, true]) { | ||
it(`when dryRun is ${dryRun}, does ${ | ||
dryRun ? 'not ' : '' | ||
}upload the updated json feed`, async function () { | ||
const config = getConfig({ | ||
'1.10.3': { | ||
chunks: [{ text: 'Foo' }], | ||
}, | ||
'*': { | ||
chunks: [{ text: 'Bar' }], | ||
}, | ||
}); | ||
|
||
config.isDryRun = dryRun; | ||
|
||
await updateJsonFeedCTA(config, dlCenter); | ||
if (dryRun) { | ||
expect(uploadAsset).to.not.have.been.called; | ||
} else { | ||
expect(uploadAsset).to.have.been.called; | ||
|
||
const updatedJsonFeed = getUploadedJsonFeed(); | ||
expect(updatedJsonFeed.cta?.chunks).to.deep.equal([{ text: 'Bar' }]); | ||
expect( | ||
updatedJsonFeed.versions.filter((v) => v.version === '1.10.3')[0] | ||
.cta?.chunks | ||
).to.deep.equal([{ text: 'Foo' }]); | ||
expect( | ||
updatedJsonFeed.versions.filter((v) => v.version === '1.10.4')[0] | ||
.cta | ||
).to.be.undefined; | ||
} | ||
}); | ||
} | ||
|
||
it('cannot add new versions', async function () { | ||
expect( | ||
existingUploadedJsonFeed.versions.filter((v) => v.version === '1.10.5') | ||
).to.have.lengthOf(0); | ||
|
||
const config = getConfig({ | ||
'1.10.5': { | ||
chunks: [{ text: 'Foo' }], | ||
}, | ||
}); | ||
|
||
await updateJsonFeedCTA(config, dlCenter); | ||
|
||
const updatedJsonFeed = getUploadedJsonFeed(); | ||
|
||
expect( | ||
updatedJsonFeed.versions.filter((v) => v.version === '1.10.5') | ||
).to.have.lengthOf(0); | ||
}); | ||
|
||
it('can remove global cta', async function () { | ||
// Preserve existing CTAs, but omit the global one | ||
const ctas = (existingUploadedJsonFeed.versions as any[]).reduce( | ||
(acc, current) => { | ||
acc[current.version] = current.cta; | ||
return acc; | ||
}, | ||
{} | ||
); | ||
const config = getConfig(ctas); | ||
|
||
expect(config.ctas['*']).to.be.undefined; | ||
await updateJsonFeedCTA(config, dlCenter); | ||
|
||
const updatedJsonFeed = getUploadedJsonFeed(); | ||
|
||
expect(updatedJsonFeed.cta).to.be.undefined; | ||
}); | ||
|
||
it('can remove version specific cta', async function () { | ||
expect( | ||
existingUploadedJsonFeed.versions.map((v) => v.cta).filter((cta) => cta) | ||
).to.have.length.greaterThan(0); | ||
|
||
const config = getConfig({ | ||
'*': existingUploadedJsonFeed.cta!, | ||
}); | ||
|
||
await updateJsonFeedCTA(config, dlCenter); | ||
|
||
const updatedJsonFeed = getUploadedJsonFeed(); | ||
expect(updatedJsonFeed.cta).to.not.be.undefined; | ||
expect( | ||
updatedJsonFeed.versions.map((v) => v.cta).filter((cta) => cta) | ||
).to.have.lengthOf(0); | ||
}); | ||
|
||
it('can update global cta', async function () { | ||
const config = getConfig({ | ||
'*': { | ||
chunks: [{ text: "It's a beautiful day", style: 'imagePositive' }], | ||
}, | ||
}); | ||
|
||
await updateJsonFeedCTA(config, dlCenter); | ||
|
||
const updatedJsonFeed = getUploadedJsonFeed(); | ||
|
||
expect(updatedJsonFeed.cta).to.deep.equal({ | ||
chunks: [{ text: "It's a beautiful day", style: 'imagePositive' }], | ||
}); | ||
}); | ||
|
||
it('can update version-specific cta', async function () { | ||
const config = getConfig({ | ||
'1.10.3': { | ||
chunks: [{ text: "It's a beautiful day", style: 'imagePositive' }], | ||
}, | ||
}); | ||
|
||
await updateJsonFeedCTA(config, dlCenter); | ||
|
||
const updatedJsonFeed = getUploadedJsonFeed(); | ||
|
||
expect( | ||
updatedJsonFeed.versions.filter((v) => v.version === '1.10.3')[0].cta | ||
).to.deep.equal({ | ||
chunks: [{ text: "It's a beautiful day", style: 'imagePositive' }], | ||
}); | ||
}); | ||
|
||
it('can add global cta', async function () { | ||
// Remove the existing cta | ||
existingUploadedJsonFeed.cta = undefined; | ||
|
||
const config = getConfig({ | ||
'*': { | ||
chunks: [ | ||
{ text: 'Go outside and enjoy the sun', style: 'imagePositive' }, | ||
], | ||
}, | ||
}); | ||
|
||
await updateJsonFeedCTA(config, dlCenter); | ||
|
||
const updatedJsonFeed = getUploadedJsonFeed(); | ||
|
||
expect(updatedJsonFeed.cta).to.deep.equal({ | ||
chunks: [ | ||
{ text: 'Go outside and enjoy the sun', style: 'imagePositive' }, | ||
], | ||
}); | ||
}); | ||
|
||
it('can add version-specific cta', async function () { | ||
// Remove the existing cta | ||
existingUploadedJsonFeed.cta = undefined; | ||
|
||
const config = getConfig({ | ||
'1.10.4': { | ||
chunks: [ | ||
{ text: 'Go outside and enjoy the sun', style: 'imagePositive' }, | ||
], | ||
}, | ||
}); | ||
|
||
await updateJsonFeedCTA(config, dlCenter); | ||
|
||
const updatedJsonFeed = getUploadedJsonFeed(); | ||
|
||
expect( | ||
updatedJsonFeed.versions.filter((v) => v.version === '1.10.4')[0].cta | ||
).to.deep.equal({ | ||
chunks: [ | ||
{ text: 'Go outside and enjoy the sun', style: 'imagePositive' }, | ||
], | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just going to mention that I think that this is on almost everywhere in our repos and that hasn't been a major issue for the most part
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't have strong feelings but agree
// eslint-disable-next-line no-non-null-assertion
or a forced type case i.e.
??? as unknown as ...
could be better for case by case?