-
Notifications
You must be signed in to change notification settings - Fork 76
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
adds check command #2452
Open
ykethan
wants to merge
3
commits into
aws-amplify:main
Choose a base branch
from
ykethan:checkcmd
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.
+220
−0
Open
adds check command #2452
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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,6 @@ | ||
--- | ||
'@aws-amplify/backend-deployer': minor | ||
'@aws-amplify/backend-cli': minor | ||
--- | ||
|
||
adds check command |
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
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,72 @@ | ||
import { BackendDeployer } from '@aws-amplify/backend-deployer'; | ||
import { format, printer } from '@aws-amplify/cli-core'; | ||
import assert from 'node:assert'; | ||
import { beforeEach, describe, it, mock } from 'node:test'; | ||
import { CheckCommand } from './check_command.js'; | ||
|
||
void describe('check command', () => { | ||
const deployMock = mock.fn<typeof backendDeployerMock.deploy>(); | ||
const backendDeployerMock = { | ||
deploy: deployMock, | ||
} as unknown as BackendDeployer; | ||
|
||
const printerMock = { | ||
print: mock.fn(), | ||
indicateProgress: mock.fn( | ||
async (message: string, action: () => Promise<void>) => { | ||
await action(); | ||
} | ||
), | ||
}; | ||
|
||
mock.method(printer, 'print', printerMock.print); | ||
mock.method(printer, 'indicateProgress', printerMock.indicateProgress); | ||
|
||
beforeEach(() => { | ||
deployMock.mock.resetCalls(); | ||
printerMock.print.mock.resetCalls(); | ||
printerMock.indicateProgress.mock.resetCalls(); | ||
}); | ||
|
||
void it('runs type checking and CDK synthesis without deployment', async () => { | ||
const command = new CheckCommand(backendDeployerMock); | ||
const synthesisTime = 1.23; | ||
|
||
deployMock.mock.mockImplementation(async () => ({ | ||
deploymentTimes: { | ||
synthesisTime, | ||
}, | ||
})); | ||
|
||
await command.handler(); | ||
|
||
// Verify deploy was called with correct arguments | ||
assert.strictEqual(deployMock.mock.callCount(), 1); | ||
assert.deepStrictEqual(deployMock.mock.calls[0].arguments[0], { | ||
namespace: 'sandbox', | ||
name: 'dev', | ||
type: 'sandbox', | ||
}); | ||
assert.deepStrictEqual(deployMock.mock.calls[0].arguments[1], { | ||
validateAppSources: true, | ||
dryRun: true, | ||
}); | ||
|
||
// Verify progress indicator was shown | ||
assert.strictEqual(printerMock.indicateProgress.mock.callCount(), 1); | ||
assert.strictEqual( | ||
printerMock.indicateProgress.mock.calls[0].arguments[0], | ||
'Running type checks and CDK synthesis...' | ||
); | ||
|
||
// Verify success message was printed | ||
assert.strictEqual(printerMock.print.mock.callCount(), 1); | ||
assert.strictEqual( | ||
printerMock.print.mock.calls[0].arguments[0], | ||
format.success( | ||
`✔ Type checking and CDK synthesis completed successfully ` + | ||
format.highlight(`(${synthesisTime}s)`) | ||
) | ||
); | ||
}); | ||
}); |
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,48 @@ | ||
import { BackendDeployer } from '@aws-amplify/backend-deployer'; | ||
import { format, printer } from '@aws-amplify/cli-core'; | ||
import { BackendIdentifier } from '@aws-amplify/plugin-types'; | ||
import { Argv, CommandModule } from 'yargs'; | ||
|
||
/** | ||
* Command that runs type checking and CDK synthesis without deployment | ||
*/ | ||
export class CheckCommand implements CommandModule { | ||
command = 'check'; | ||
describe = 'Run type checking and CDK synthesis without deployment'; | ||
|
||
/** | ||
* Creates a new instance of CheckCommand | ||
* @param backendDeployer - The deployer used to run CDK synthesis | ||
*/ | ||
constructor(private readonly backendDeployer: BackendDeployer) {} | ||
|
||
handler = async () => { | ||
const backendId: BackendIdentifier = { | ||
namespace: 'sandbox', | ||
name: 'dev', | ||
type: 'sandbox', | ||
}; | ||
|
||
let result: { deploymentTimes: { synthesisTime?: number } } = { | ||
deploymentTimes: {}, | ||
}; | ||
await printer.indicateProgress( | ||
'Running type checks and CDK synthesis...', | ||
async () => { | ||
result = await this.backendDeployer.deploy(backendId, { | ||
validateAppSources: true, | ||
dryRun: true, | ||
}); | ||
} | ||
); | ||
|
||
printer.print( | ||
format.success( | ||
`✔ Type checking and CDK synthesis completed successfully ` + | ||
format.highlight(`(${result.deploymentTimes.synthesisTime ?? 0}s)`) | ||
) | ||
); | ||
}; | ||
|
||
builder = (yargs: Argv) => yargs; | ||
} |
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,16 @@ | ||
import { BackendDeployerFactory } from '@aws-amplify/backend-deployer'; | ||
import { PackageManagerControllerFactory, format } from '@aws-amplify/cli-core'; | ||
import { CheckCommand } from './check_command.js'; | ||
|
||
/** | ||
* Creates Check command. | ||
*/ | ||
export const createCheckCommand = (): CheckCommand => { | ||
const packageManagerControllerFactory = new PackageManagerControllerFactory(); | ||
const backendDeployerFactory = new BackendDeployerFactory( | ||
packageManagerControllerFactory.getPackageManagerController(), | ||
format | ||
); | ||
const backendDeployer = backendDeployerFactory.getInstance(); | ||
return new CheckCommand(backendDeployer); | ||
}; |
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
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.
Not a big fan of the command name
check
. It's more closely related tobuild
and perhaps--dryRun
isn't bad either for the existingsandbox
command. This way customers can utilize thewatch
nature of sandbox for builds as well.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.
I agree that it's more of a "build", though the
check
name was inspired by other projects that provide similar functionality with the intent of a sort of "preflight" task before merging changes. There is another request to provide a "diff" function and integrate cdk-nag to perform diagnostics and/or highlight best practices that I think would fit nicely with the "check" themehttps://docs.astro.build/en/reference/cli-reference/#astro-check
https://svelte.dev/docs/cli/sv-check
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.
There is definitely overlap between
check
andbuild
. We might be slightly different in the sense that we "synth" as well. We discussed offline to do an API review of this change will all the proposals.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.
Have you considered the option of
synth
too?I was looking for both
diff
andsynth
commands as a long time user of CDK alongside Amplify gen1. Given that CDK does type checking with tsc during synth too it seems functionally similar, and perhaps nice to have consistency in naming across the two services.