Skip to content
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: apply multiple overlays on deploy #619

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Or, with Yarn via
yarn global add bump-cli
```

### Add Bump.sh to your node project
### Add Bump.sh to your Node project

As our CLI is a node package, you can easily embed it into your project by adding the package to your `package.json` file, either with NPM

Expand All @@ -74,7 +74,7 @@ You can then use any Bump.sh commands with `npx` (same as `npm exec`)
npx bump --help
```

### How should I do if I'm not using npm ?
### Can I install Bump.sh CLI without using NodeJS?

Unfortunately, at the moment we only support the Node environment. However, you can download a standalone package directly from the [latest Github release](https://github.com/bump-sh/cli/releases) assets which you can run as a standalone binary. Or you can push your documentation using [our API](https://developers.bump.sh/) (advanced usage only).

Expand Down Expand Up @@ -267,7 +267,7 @@ To redirect the output of the command to a new file you can run the following:
bump overlay api-document.yaml overlay-file.yaml > api-overlayed-document.yaml
```

_**Note:** you can also apply the overlay during the [`bump deploy` command]((#bump-deploy-file)) with the new `--overlay` flag:_
_Note: you can also apply overlays during the [`bump deploy` command]((#bump-deploy-file)) with the `--overlay` flag (which can be used multiples times):_

```shell
bump deploy api-document.yaml --doc my-doc --token my-token --overlay overlay-file.yaml
Expand Down
11 changes: 11 additions & 0 deletions examples/valid/overlay2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
overlay: 1.0.0
info:
title: Add Feedback Link
version: 0.0.1
actions:
- target: '$.info'
description: Add a feedback link to the API
update:
x-feedbackLink:
label: Submit Feedback
url: https://github.com/bump-sh-examples/train-travel-api/issues/new
2 changes: 1 addition & 1 deletion src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
token: flagsBuilder.token(),
}

protected async deployDirectory(

Check warning on line 70 in src/commands/deploy.ts

View workflow job for this annotation

GitHub Actions / Node 23 - x64 on ubuntu-latest

Async method 'deployDirectory' has too many parameters (9). Maximum allowed is 4

Check warning on line 70 in src/commands/deploy.ts

View workflow job for this annotation

GitHub Actions / Node latest - x64 on ubuntu-latest

Async method 'deployDirectory' has too many parameters (9). Maximum allowed is 4

Check warning on line 70 in src/commands/deploy.ts

View workflow job for this annotation

GitHub Actions / Node 20 - x64 on ubuntu-latest

Async method 'deployDirectory' has too many parameters (9). Maximum allowed is 4

Check warning on line 70 in src/commands/deploy.ts

View workflow job for this annotation

GitHub Actions / Node 20 - x64 on macos-latest

Async method 'deployDirectory' has too many parameters (9). Maximum allowed is 4

Check warning on line 70 in src/commands/deploy.ts

View workflow job for this annotation

GitHub Actions / Node latest - x64 on macos-latest

Async method 'deployDirectory' has too many parameters (9). Maximum allowed is 4

Check warning on line 70 in src/commands/deploy.ts

View workflow job for this annotation

GitHub Actions / Node latest - x64 on windows-latest

Async method 'deployDirectory' has too many parameters (9). Maximum allowed is 4

Check warning on line 70 in src/commands/deploy.ts

View workflow job for this annotation

GitHub Actions / Node 23 - x64 on macos-latest

Async method 'deployDirectory' has too many parameters (9). Maximum allowed is 4

Check warning on line 70 in src/commands/deploy.ts

View workflow job for this annotation

GitHub Actions / Node 23 - x64 on windows-latest

Async method 'deployDirectory' has too many parameters (9). Maximum allowed is 4

Check warning on line 70 in src/commands/deploy.ts

View workflow job for this annotation

GitHub Actions / Node 20 - x64 on windows-latest

Async method 'deployDirectory' has too many parameters (9). Maximum allowed is 4
dir: string,
dryRun: boolean,
token: string,
Expand Down Expand Up @@ -137,7 +137,7 @@
}
}

protected async deploySingleFile(

Check warning on line 140 in src/commands/deploy.ts

View workflow job for this annotation

GitHub Actions / Node 23 - x64 on ubuntu-latest

Async method 'deploySingleFile' has too many parameters (9). Maximum allowed is 4

Check warning on line 140 in src/commands/deploy.ts

View workflow job for this annotation

GitHub Actions / Node latest - x64 on ubuntu-latest

Async method 'deploySingleFile' has too many parameters (9). Maximum allowed is 4

Check warning on line 140 in src/commands/deploy.ts

View workflow job for this annotation

GitHub Actions / Node 20 - x64 on ubuntu-latest

Async method 'deploySingleFile' has too many parameters (9). Maximum allowed is 4

Check warning on line 140 in src/commands/deploy.ts

View workflow job for this annotation

GitHub Actions / Node 20 - x64 on macos-latest

Async method 'deploySingleFile' has too many parameters (9). Maximum allowed is 4

Check warning on line 140 in src/commands/deploy.ts

View workflow job for this annotation

GitHub Actions / Node latest - x64 on macos-latest

Async method 'deploySingleFile' has too many parameters (9). Maximum allowed is 4

Check warning on line 140 in src/commands/deploy.ts

View workflow job for this annotation

GitHub Actions / Node latest - x64 on windows-latest

Async method 'deploySingleFile' has too many parameters (9). Maximum allowed is 4

Check warning on line 140 in src/commands/deploy.ts

View workflow job for this annotation

GitHub Actions / Node 23 - x64 on macos-latest

Async method 'deploySingleFile' has too many parameters (9). Maximum allowed is 4

Check warning on line 140 in src/commands/deploy.ts

View workflow job for this annotation

GitHub Actions / Node 23 - x64 on windows-latest

Async method 'deploySingleFile' has too many parameters (9). Maximum allowed is 4

Check warning on line 140 in src/commands/deploy.ts

View workflow job for this annotation

GitHub Actions / Node 20 - x64 on windows-latest

Async method 'deploySingleFile' has too many parameters (9). Maximum allowed is 4
api: API,
dryRun: boolean,
documentation: string,
Expand All @@ -146,7 +146,7 @@
autoCreate: boolean,
documentationName: string | undefined,
branch: string | undefined,
overlay?: string | undefined,
overlay?: string[] | undefined,
): Promise<void> {
ux.action.status = `...a new version to your ${documentation} documentation`

Expand Down
10 changes: 8 additions & 2 deletions src/core/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
return debug(`bump-cli:core:deploy`)(formatter, ...args)
}

public async run(

Check warning on line 42 in src/core/deploy.ts

View workflow job for this annotation

GitHub Actions / Node 23 - x64 on ubuntu-latest

Async method 'run' has too many parameters (9). Maximum allowed is 4

Check warning on line 42 in src/core/deploy.ts

View workflow job for this annotation

GitHub Actions / Node latest - x64 on ubuntu-latest

Async method 'run' has too many parameters (9). Maximum allowed is 4

Check warning on line 42 in src/core/deploy.ts

View workflow job for this annotation

GitHub Actions / Node 20 - x64 on ubuntu-latest

Async method 'run' has too many parameters (9). Maximum allowed is 4

Check warning on line 42 in src/core/deploy.ts

View workflow job for this annotation

GitHub Actions / Node 20 - x64 on macos-latest

Async method 'run' has too many parameters (9). Maximum allowed is 4

Check warning on line 42 in src/core/deploy.ts

View workflow job for this annotation

GitHub Actions / Node latest - x64 on macos-latest

Async method 'run' has too many parameters (9). Maximum allowed is 4

Check warning on line 42 in src/core/deploy.ts

View workflow job for this annotation

GitHub Actions / Node latest - x64 on windows-latest

Async method 'run' has too many parameters (9). Maximum allowed is 4

Check warning on line 42 in src/core/deploy.ts

View workflow job for this annotation

GitHub Actions / Node 23 - x64 on macos-latest

Async method 'run' has too many parameters (9). Maximum allowed is 4

Check warning on line 42 in src/core/deploy.ts

View workflow job for this annotation

GitHub Actions / Node 23 - x64 on windows-latest

Async method 'run' has too many parameters (9). Maximum allowed is 4

Check warning on line 42 in src/core/deploy.ts

View workflow job for this annotation

GitHub Actions / Node 20 - x64 on windows-latest

Async method 'run' has too many parameters (9). Maximum allowed is 4
api: API,
dryRun: boolean,
documentation: string,
Expand All @@ -48,11 +48,17 @@
autoCreate: boolean,
documentationName: string | undefined,
branch: string | undefined,
overlay?: string | undefined,
overlay?: string[] | undefined,
): Promise<VersionResponse | undefined> {
let version: VersionResponse | undefined
if (overlay) {
await api.applyOverlay(overlay)
/* eslint-disable no-await-in-loop */
// Alternatively we can apply all overlays in parallel
// https://stackoverflow.com/questions/48957022/unexpected-await-inside-a-loop-no-await-in-loop
for (const overlayFile of overlay) {
await api.applyOverlay(overlayFile)
}
/* eslint-enable no-await-in-loop */
}

const [definition, references] = api.extractDefinition()
Expand Down
3 changes: 2 additions & 1 deletion src/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,13 @@ class API {
public async applyOverlay(overlayPath: string): Promise<void> {
const overlay = await API.load(overlayPath)
const overlayDefinition = overlay.definition
const currentDefinition = this.overlayedDefinition || this.definition

if (!API.isOpenAPIOverlay(overlayDefinition)) {
throw new Error(`${overlayPath} does not look like an OpenAPI overlay`)
}

this.overlayedDefinition = await new Overlay().run(this.definition, overlayDefinition)
this.overlayedDefinition = await new Overlay().run(currentDefinition, overlayDefinition)
}

public extractDefinition(outputPath?: string): [string, APIReference[]] {
Expand Down
9 changes: 3 additions & 6 deletions src/flags.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {Flags, Interfaces} from '@oclif/core'
// import * as Parser from '@oclif/parser';

// Re-export oclif flags https://oclif.io/docs/flags
// export * from '@oclif/command/lib/flags';

// Custom flags for bump-cli
const doc = Flags.custom<string>({
Expand Down Expand Up @@ -131,9 +127,10 @@ const out = Flags.custom<string>({
description: 'Output file path',
})

const overlay = Flags.custom<string>({
const overlay = Flags.custom<string[]>({
char: 'o',
description: 'Path or URL of an overlay file to apply before deploying',
description: 'Path or URL of overlay file(s) to apply before deploying',
multiple: true,
})

export {
Expand Down
33 changes: 33 additions & 0 deletions test/commands/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,39 @@ describe('deploy subcommand', () => {
})
})

describe('Successful runs with overlays', () => {
it('sends new version to Bump', async () => {
nock('https://bump.sh')
.post(
'/api/v1/versions',
(body) =>
body.documentation === 'coucou' &&
!body.branch_name &&
body.definition.includes('Submit Feedback') &&
body.definition.includes("Protect Earth's Tree Tracker"),
)
.reply(201, {doc_public_url: 'http://localhost/doc/123-with-overlays'})

const {stderr, stdout} = await runCommand(
[
'deploy',
'examples/valid/openapi.v3.json',
'--doc',
'coucou',
'--overlay',
'examples/valid/overlay.yaml',
'--overlay',
'examples/valid/overlay2.yaml',
].join(' '),
)
expect(stderr).to.contain("Let's deploy on Bump.sh... done\n")
expect(stdout).to.contain(
'Your coucou documentation...has received a new deployment which will soon be ready at:',
)
expect(stdout).to.contain('http://localhost/doc/123-with-overlays')
})
})

describe('Server errors', () => {
describe('Authentication error', () => {
it("Doesn't create a deployed version", async () => {
Expand Down
Loading