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

fix(integ-runner): Fix call to spawnSync for hooks commands #22429

Merged
merged 22 commits into from
Oct 19, 2022

Conversation

arewa
Copy link
Contributor

@arewa arewa commented Oct 8, 2022

Fixes the issue #22344

I reworked the approach of calling exec by splitting each command in hook to the command itself and it's arguments. All hooks were affected: preDeploy, postDeploy, preDestroy, postDestroy.


All Submissions:

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@gitpod-io
Copy link

gitpod-io bot commented Oct 8, 2022

@github-actions github-actions bot added the repeat-contributor [Pilot] contributed between 3-5 PRs to the CDK label Oct 8, 2022
@aws-cdk-automation aws-cdk-automation requested a review from a team October 8, 2022 17:04
@github-actions github-actions bot added the p2 label Oct 8, 2022
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

@arewa arewa marked this pull request as draft October 8, 2022 17:07
@arewa arewa marked this pull request as ready for review October 8, 2022 17:11
@arewa arewa marked this pull request as draft October 11, 2022 12:44
@arewa arewa marked this pull request as ready for review October 11, 2022 14:14
@aws-cdk-automation aws-cdk-automation dismissed their stale review October 11, 2022 14:15

✅ Updated pull request passes all PRLinter validations. Dissmissing previous PRLinter review.

@@ -0,0 +1,7 @@
import { App, Stack } from '@aws-cdk/core';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't testing anything. Why is this here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheRealAmazonKendra, I can actually remove this I added it to avoid the linter issue saying PR must have at least one integration test update. But integ-runner doesn't have its own integration tests that's why I added this small test. And with this test integ-tests/package.json will also be reverted.

@@ -52,7 +52,8 @@
"compat": "cdk-compat",
"rosetta:extract": "yarn --silent jsii-rosetta extract",
"build+extract": "yarn build && yarn rosetta:extract",
"build+test+extract": "yarn build+test && yarn rosetta:extract"
"build+test+extract": "yarn build+test && yarn rosetta:extract",
"integ": "integ-runner"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't needed in this package.

@@ -65,6 +66,7 @@
"@aws-cdk/cdk-build-tools": "0.0.0",
"@aws-cdk/cx-api": "0.0.0",
"@aws-cdk/pkglint": "0.0.0",
"@aws-cdk/integ-runner": "0.0.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nor this.

@mergify mergify bot dismissed TheRealAmazonKendra’s stale review October 14, 2022 18:52

Pull request has been modified.

@arewa arewa requested review from TheRealAmazonKendra and removed request for aws-cdk-automation October 14, 2022 18:55
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

let chunks = command.split(/\s+/);
const cmd = chunks.shift();
if (cmd !== undefined) {
return [cmd, chunks.join(' ')];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be return chunks instead?

For example if I had

hooks: {
  preDeploy: ['npx cdk deploy'],
}

I would want it to return ['npx', 'cdk', 'deploy'] right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@corymhall, thank you for the comment, for the command you mentioned it could be like that. But for example for the command echo "preDeploy hook" if we just split it by space it will result in ['echo', '"preDeploy', 'hook"'] which seems to be not the correct input for exec.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could do something like this instead in order to keep quoted sections together.

let chunks = command.match(/(?:[^\s"]+|"[^"]*")+/g)
// ['echo', '"preDeploy hook"']

I think if you use arguments with spawnSync each argument to the command needs to be its own element in the list.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, make sense, I updated the solution. Thank you again for the review.

@arewa arewa requested review from corymhall and TheRealAmazonKendra and removed request for TheRealAmazonKendra and corymhall October 19, 2022 11:58
Copy link
Contributor

@corymhall corymhall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! just one minor nit and then we are good to go!

*/
export function chunks(command: string): string[] {
const result = command.match(/(?:[^\s"]+|"[^"]*")+/g);
if (result !== null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

return result ?? [];

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly, updated ))

@corymhall corymhall added the pr-linter/exempt-integ-test The PR linter will not require integ test changes label Oct 19, 2022
@aws-cdk-automation aws-cdk-automation dismissed their stale review October 19, 2022 19:47

✅ Updated pull request passes all PRLinter validations. Dissmissing previous PRLinter review.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 5c93451
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify
Copy link
Contributor

mergify bot commented Oct 19, 2022

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit 9139ca9 into aws:main Oct 19, 2022
madeline-k pushed a commit that referenced this pull request Oct 21, 2022
Fixes the issue #22344

I reworked the approach of calling `exec` by splitting each command in hook to the command itself and it's arguments. All hooks were affected: preDeploy, postDeploy, preDestroy, postDestroy.

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
mrgrain pushed a commit to mrgrain/aws-cdk that referenced this pull request Oct 24, 2022
Fixes the issue aws#22344

I reworked the approach of calling `exec` by splitting each command in hook to the command itself and it's arguments. All hooks were affected: preDeploy, postDeploy, preDestroy, postDestroy.

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p2 pr-linter/exempt-integ-test The PR linter will not require integ test changes repeat-contributor [Pilot] contributed between 3-5 PRs to the CDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants