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(codepipeline-actions): support commands action #31667

Merged
merged 45 commits into from
Feb 7, 2025

Conversation

go-to-k
Copy link
Contributor

@go-to-k go-to-k commented Oct 5, 2024

Issue # (if applicable)

Closes #31666.

Reason for this change

AWS CodePipeline introduces new general purpose compute action: Commands action.

CFn docs:

Description of changes

Added CommandsAction class and changed other files.

The ActionCategory for this action is a new category Compute, so added ActionCategory.COMPUTE.

Description of how you validated changes

Both unit and integ tests

Checklist


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

@github-actions github-actions bot added feature-request A feature should be added or improved. p2 labels Oct 5, 2024
@aws-cdk-automation aws-cdk-automation requested a review from a team October 5, 2024 17:19
@github-actions github-actions bot added the distinguished-contributor [Pilot] contributed 50+ PRs to the CDK label Oct 5, 2024
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.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@@ -13,6 +13,7 @@ export enum ActionCategory {
APPROVAL = 'Approval',
DEPLOY = 'Deploy',
INVOKE = 'Invoke',
COMPUTE = 'Compute',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines 86 to 90
// To put the logs in the log group
// see: https://docs.aws.amazon.com/codepipeline/latest/userguide/action-reference-Commands.html#action-reference-Commands-policy
'logs:CreateLogGroup',
'logs:CreateLogStream',
'logs:PutLogEvents',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines 91 to 93
// To view the logs in the Commands action on the CodePipeline console
// see: https://docs.aws.amazon.com/codepipeline/latest/userguide/security-iam-permissions-console-logs.html
'logs:GetLogEvents',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines +108 to +121

/**
* Shell commands for the Commands action to run.
*
* @default - no commands
*/
readonly commands?: string[];

/**
* The names of the variables in your environment that you want to export.
*
* @default - no output variables
*/
readonly outputVariables?: string[];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines 14 to 17
* @param files file paths that you want to export as output artifacts for the action. (can only be used in artifacts for `CommandAction`)
*/
public static artifact(name: string): Artifact {
return new Artifact(name);
public static artifact(name: string, files?: string[]): Artifact {
return new Artifact(name, files);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@go-to-k
Copy link
Contributor Author

go-to-k commented Oct 5, 2024

The CodeBuild run under the CommandsAction. But I don't automatically add the permissions for source services with CODEBUILD_CLONE_REF (codeBuildCloneOutput=true).

https://github.com/aws/aws-cdk/blob/v2.161.0/packages/aws-cdk-lib/aws-codepipeline-actions/lib/codebuild/build-action.ts#L189-L211

https://github.com/aws/aws-cdk/blob/v2.161.0/packages/aws-cdk-lib/aws-codepipeline-actions/lib/codestar-connections/source-action.ts#L158-L159

Because an error occurred in the CommandsAction with CODEBUILD_CLONE_REF.

clone-ref

@github-actions github-actions bot added the effort/medium Medium work item – several days of effort label Oct 6, 2024
@go-to-k go-to-k changed the title feat(codepipeline-actions): support Commands action feat(codepipeline-actions): support commands action Oct 6, 2024
GavinZZ
GavinZZ previously requested changes Feb 6, 2025
Copy link
Contributor

@GavinZZ GavinZZ left a comment

Choose a reason for hiding this comment

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

Thank you as always for the contribution! Just curious on the design decision.

provider: 'Commands',
artifactBounds: { minInputs: 1, maxInputs: 10, minOutputs: 0, maxOutputs: 1 },
inputs: [props.input, ...props.extraInputs || []],
outputs: props.output ? [props.output] : [],
Copy link
Contributor

Choose a reason for hiding this comment

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

since CFN L1 resource can take a list of items as outputs, I'm curious on the design decision on output being one item instead of a list of artifacts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The number of output artifacts can only be 0 to 1 on the Commands action.

Output artifacts
Number of artifacts: 0 to 1

https://docs.aws.amazon.com/codepipeline/latest/userguide/action-reference-Commands.html#action-reference-Commands-output

So I made it output as an optional param that can be 0 to 1.

Various actions including the commands action use the same CFn type, so it seems the CFn needs to get an array type.

@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Feb 6, 2025
Copy link
Contributor Author

@go-to-k go-to-k left a comment

Choose a reason for hiding this comment

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

@GavinZZ

Thanks for your review! I have replied and hope you take a look at it.

provider: 'Commands',
artifactBounds: { minInputs: 1, maxInputs: 10, minOutputs: 0, maxOutputs: 1 },
inputs: [props.input, ...props.extraInputs || []],
outputs: props.output ? [props.output] : [],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The number of output artifacts can only be 0 to 1 on the Commands action.

Output artifacts
Number of artifacts: 0 to 1

https://docs.aws.amazon.com/codepipeline/latest/userguide/action-reference-Commands.html#action-reference-Commands-output

So I made it output as an optional param that can be 0 to 1.

Various actions including the commands action use the same CFn type, so it seems the CFn needs to get an array type.

@mergify mergify bot dismissed GavinZZ’s stale review February 7, 2025 04:06

Pull request has been modified.

Copy link

codecov bot commented Feb 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.83%. Comparing base (873233b) to head (bfaa773).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #31667   +/-   ##
=======================================
  Coverage   80.83%   80.83%           
=======================================
  Files         236      236           
  Lines       14251    14251           
  Branches     2490     2490           
=======================================
  Hits        11520    11520           
  Misses       2446     2446           
  Partials      285      285           
Flag Coverage Δ
suite.unit 80.83% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
packages/aws-cdk 79.56% <ø> (ø)
packages/aws-cdk-lib/core 82.20% <ø> (ø)

@go-to-k
Copy link
Contributor Author

go-to-k commented Feb 7, 2025

@GavinZZ

I am not sure if the document has changed since I saw it or if I was mistaken, but I have changed the policies to match the document.

8b8c5d7

ref-1: https://docs.aws.amazon.com/codepipeline/latest/userguide/action-reference-Commands.html#action-reference-Commands-policy

ref-2: https://docs.aws.amazon.com/codepipeline/latest/userguide/security-iam-permissions-console-logs.html

Also, the integ test was slightly modified.

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.

(This review is outdated)

@go-to-k
Copy link
Contributor Author

go-to-k commented Feb 7, 2025

I'm investigating the CI failure because it creates differences in snapshots.

It seems to have been fixed after full build with the latest commit in main branch, soI will run CI again.

@aws-cdk-automation aws-cdk-automation dismissed their stale review February 7, 2025 09:56

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

@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Feb 7, 2025
@go-to-k
Copy link
Contributor Author

go-to-k commented Feb 7, 2025

@GavinZZ
CI has succeeded.
Could you please check it again?

@go-to-k go-to-k requested a review from GavinZZ February 7, 2025 12:09
Copy link
Contributor

mergify bot commented Feb 7, 2025

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).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

Copy link
Contributor

mergify bot commented Feb 7, 2025

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 2637d46 into aws:main Feb 7, 2025
19 of 20 checks passed
Copy link

github-actions bot commented Feb 7, 2025

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 7, 2025
@go-to-k go-to-k deleted the cp-action-commands branch February 8, 2025 00:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
distinguished-contributor [Pilot] contributed 50+ PRs to the CDK effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

codepipeline-actions: support Commands action
3 participants