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(core): add include property specifying particular files for assets #26365

Closed
wants to merge 11 commits into from

Conversation

go-to-k
Copy link
Contributor

@go-to-k go-to-k commented Jul 14, 2023

This PR adds an include property including particular files for assets such as lambda.Code.fromAsset.

  • Add an include parameter to interface FileOptions with exclude.
  • Check for matching include along with ignores (actually exclude) in copyDirectory, where the actual file search is done.

Closes #26107.


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

chore: fingerprint

fix: comments

separate includes

chore: new line

chore: new line

chore: new line

feat: mkdir before symlinkSync
@github-actions github-actions bot added the valued-contributor [Pilot] contributed between 6-12 PRs to the CDK label Jul 14, 2023
@aws-cdk-automation aws-cdk-automation requested a review from a team July 14, 2023 11:41
@github-actions github-actions bot added effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 labels Jul 14, 2023
@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 Jul 14, 2023
@go-to-k go-to-k changed the title feat(core): add include property including particular files for assets feat(core): add include property specifying particular files for assets Jul 14, 2023
*
* @default - everything is included
*/
readonly include?: string[];

Choose a reason for hiding this comment

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

I think it would help to add some more detail here.

  1. How does this interact with exclude? That is, if a file matches something in include and exclude, what happens? My assumption is that exclude takes priority but it would be nice to mention that explicitly.
  2. How does this interact with symlinks when using a SymlinkFollowMode other than NEVER? That is, if I include the symlink but not its target, what happens?

It would also be good to add test cases for these points.

Copy link
Contributor Author

@go-to-k go-to-k Jul 18, 2023

Choose a reason for hiding this comment

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

@rittneje

Thanks! I added the docs and tests.

  1. exclude takes priority if both include and exclude are matched.
  2. If matching the symlink but not its target, it is included even if SymlinkFollowMode is NEVER or not. This is based on the same checking the exclude patterns.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

@tmokmss
Copy link
Contributor

tmokmss commented Jul 21, 2023

Can't we just use exclude with a negation pattern to get the behavior?

include: ['index.py'],
// this should be equivalent to the following
exclude: ['*', '!index.py']

I am not entirely convinced that it is a good idea to have both include and exclude properties, because it is not clear what the priority is between include and exclude, and how to handle files that do not match both include and exclude, which will confuse users.

@rittneje
Copy link

@tmokmss Negative exclusions aren't even documented. If that's going to be the solution (which I don't like because it's more confusing to have to think in terms of double negation), then the docs still should be amended.

@tmokmss
Copy link
Contributor

tmokmss commented Jul 21, 2023

@rittneje
It is deliberately supported even in glob patterns, so I don't see much reason not to use it :)

for (const pattern of this.patterns) {
const negate = pattern.startsWith('!');
const match = minimatch(relativePath, pattern, { matchBase: true, flipNegate: true });

I think using a negation in ignore files (like .gitignore or .dockerignore) is a common pattern, but yeah, we might need a clearer doc on this.

@go-to-k
Copy link
Contributor Author

go-to-k commented Jul 22, 2023

@tmokmss Hmmm, I was confused too, but you may be right! Then I would close this PR.

@go-to-k
Copy link
Contributor Author

go-to-k commented Jul 22, 2023

As for the document, I'll consider it in another PR.

@go-to-k
Copy link
Contributor Author

go-to-k commented Jul 22, 2023

I submitted the PR for the docs of exclude property using a negation.

mergify bot pushed a commit that referenced this pull request Jul 25, 2023
We discussed for the need to document `exclude` patterns using a negation in [the PR](#26365 (comment)).

I also could not find documentation for the `exclude` property itself, so I added them.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
bmoffatt pushed a commit to bmoffatt/aws-cdk that referenced this pull request Jul 29, 2023
We discussed for the need to document `exclude` patterns using a negation in [the PR](aws#26365 (comment)).

I also could not find documentation for the `exclude` property itself, so I added them.

----

*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
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. valued-contributor [Pilot] contributed between 6-12 PRs to the CDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

core: support specifying included files for Code.from_asset
4 participants