From d72ae626ea69e9ab8b47cd945c2550e12531b9dc Mon Sep 17 00:00:00 2001 From: Sean McGrail Date: Thu, 20 May 2021 00:08:14 +0000 Subject: [PATCH] Carve out `internal/ini` into a seperate module (#1265) * Detect Module Carving Out * internal/ini: Carve out ini parser as stand-alone module --- .../016af652b95e472f960ded9a2e976e11.json | 4 +- .../01afcb6e5f9d44c9ab76d3e414115636.json | 8 + .../45284b57bcdd4cd6935b5275c15b1861.json | 8 + .../f2c891806ed64485bdbee78723db3a88.json | 8 - config/go.mod | 3 + example/service/s3/listObjects/go.mod | 2 + example/service/s3/usingPrivateLink/go.mod | 2 + feature/s3/manager/go.mod | 2 + internal/ini/LICENSE.txt | 202 ++++++++++++++++++ internal/ini/dependency.go | 6 + internal/ini/go.mod | 7 + internal/ini/go.sum | 10 + internal/ini/go_module_metadata.go | 6 + internal/repotools/git/git.go | 21 +- internal/repotools/gomod/diff.go | 13 +- internal/repotools/release/calculate.go | 71 +++++- internal/repotools/release/calculate_test.go | 75 +++++++ service/internal/integrationtest/go.mod | 2 + service/s3/internal/configtesting/go.mod | 2 + 19 files changed, 433 insertions(+), 19 deletions(-) create mode 100644 .changelog/01afcb6e5f9d44c9ab76d3e414115636.json create mode 100644 .changelog/45284b57bcdd4cd6935b5275c15b1861.json delete mode 100644 .changelog/f2c891806ed64485bdbee78723db3a88.json create mode 100644 internal/ini/LICENSE.txt create mode 100644 internal/ini/dependency.go create mode 100644 internal/ini/go.mod create mode 100644 internal/ini/go.sum create mode 100644 internal/ini/go_module_metadata.go create mode 100644 internal/repotools/release/calculate_test.go diff --git a/.changelog/016af652b95e472f960ded9a2e976e11.json b/.changelog/016af652b95e472f960ded9a2e976e11.json index 8d7dc036853..f1edb4328f1 100644 --- a/.changelog/016af652b95e472f960ded9a2e976e11.json +++ b/.changelog/016af652b95e472f960ded9a2e976e11.json @@ -1,7 +1,7 @@ { "id": "016af652-b95e-472f-960d-ed9a2e976e11", - "type": "bugfix", - "description": "`internal/ini`: Disable normalization of config profile names", + "type": "feature", + "description": "`internal/ini`: This package has been migrated to a separate module at `github.com/aws/aws-sdk-go-v2/internal/ini`.", "modules": [ "." ] diff --git a/.changelog/01afcb6e5f9d44c9ab76d3e414115636.json b/.changelog/01afcb6e5f9d44c9ab76d3e414115636.json new file mode 100644 index 00000000000..e148173c71f --- /dev/null +++ b/.changelog/01afcb6e5f9d44c9ab76d3e414115636.json @@ -0,0 +1,8 @@ +{ + "id": "01afcb6e-5f9d-44c9-ab76-d3e414115636", + "type": "release", + "description": "The `github.com/aws/aws-sdk-go-v2/internal/ini` package is now a Go Module.", + "modules": [ + "internal/ini" + ] +} \ No newline at end of file diff --git a/.changelog/45284b57bcdd4cd6935b5275c15b1861.json b/.changelog/45284b57bcdd4cd6935b5275c15b1861.json new file mode 100644 index 00000000000..a51d7f00827 --- /dev/null +++ b/.changelog/45284b57bcdd4cd6935b5275c15b1861.json @@ -0,0 +1,8 @@ +{ + "id": "45284b57-bcdd-4cd6-935b-5275c15b1861", + "type": "bugfix", + "description": "Profile names were incorrectly normalized to lower-case, which could result in unexpected profile configurations.", + "modules": [ + "config" + ] +} diff --git a/.changelog/f2c891806ed64485bdbee78723db3a88.json b/.changelog/f2c891806ed64485bdbee78723db3a88.json deleted file mode 100644 index d9d4be28ea2..00000000000 --- a/.changelog/f2c891806ed64485bdbee78723db3a88.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "id": "f2c89180-6ed6-4485-bdbe-e78723db3a88", - "type": "bugfix", - "description": "Fixed a bug that caused configuration profile names to be incorrectly normalized, which could cause incorrect profile loading in certain cases. ([#1204](https://github.com/aws/aws-sdk-go-v2/issues/1204))", - "modules": [ - "config" - ] -} \ No newline at end of file diff --git a/config/go.mod b/config/go.mod index cdc7078814e..cf7e8aed52d 100644 --- a/config/go.mod +++ b/config/go.mod @@ -6,6 +6,7 @@ require ( github.com/aws/aws-sdk-go-v2 v1.5.0 github.com/aws/aws-sdk-go-v2/credentials v1.2.0 github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.1.0 + github.com/aws/aws-sdk-go-v2/internal/ini v0.0.0-00010101000000-000000000000 github.com/aws/aws-sdk-go-v2/service/sso v1.2.0 github.com/aws/aws-sdk-go-v2/service/sts v1.4.0 github.com/aws/smithy-go v1.4.0 @@ -18,6 +19,8 @@ replace github.com/aws/aws-sdk-go-v2/credentials => ../credentials/ replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../feature/ec2/imds/ +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../internal/ini/ + replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../service/internal/presigned-url/ replace github.com/aws/aws-sdk-go-v2/service/sso => ../service/sso/ diff --git a/example/service/s3/listObjects/go.mod b/example/service/s3/listObjects/go.mod index 806c5bcda75..d49ada64c07 100644 --- a/example/service/s3/listObjects/go.mod +++ b/example/service/s3/listObjects/go.mod @@ -15,6 +15,8 @@ replace github.com/aws/aws-sdk-go-v2/credentials => ../../../../credentials/ replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../../../feature/ec2/imds/ +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../../../internal/ini/ + replace github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding => ../../../../service/internal/accept-encoding/ replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../../../service/internal/presigned-url/ diff --git a/example/service/s3/usingPrivateLink/go.mod b/example/service/s3/usingPrivateLink/go.mod index 27dad180e95..3ee4cd81a7d 100644 --- a/example/service/s3/usingPrivateLink/go.mod +++ b/example/service/s3/usingPrivateLink/go.mod @@ -17,6 +17,8 @@ replace github.com/aws/aws-sdk-go-v2/credentials => ../../../../credentials/ replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../../../feature/ec2/imds/ +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../../../internal/ini/ + replace github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding => ../../../../service/internal/accept-encoding/ replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../../../service/internal/presigned-url/ diff --git a/feature/s3/manager/go.mod b/feature/s3/manager/go.mod index 74e2e1583e9..53c49d358a0 100644 --- a/feature/s3/manager/go.mod +++ b/feature/s3/manager/go.mod @@ -18,6 +18,8 @@ replace github.com/aws/aws-sdk-go-v2/credentials => ../../../credentials/ replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../../feature/ec2/imds/ +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../../internal/ini/ + replace github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding => ../../../service/internal/accept-encoding/ replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../../service/internal/presigned-url/ diff --git a/internal/ini/LICENSE.txt b/internal/ini/LICENSE.txt new file mode 100644 index 00000000000..d6456956733 --- /dev/null +++ b/internal/ini/LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/internal/ini/dependency.go b/internal/ini/dependency.go new file mode 100644 index 00000000000..f5ebe52e1a5 --- /dev/null +++ b/internal/ini/dependency.go @@ -0,0 +1,6 @@ +package ini + +import ( + // internal/ini module was carved out of this module + _ "github.com/aws/aws-sdk-go-v2" +) diff --git a/internal/ini/go.mod b/internal/ini/go.mod new file mode 100644 index 00000000000..67eceade182 --- /dev/null +++ b/internal/ini/go.mod @@ -0,0 +1,7 @@ +module github.com/aws/aws-sdk-go-v2/internal/ini + +go 1.15 + +require github.com/aws/aws-sdk-go-v2 v1.5.0 + +replace github.com/aws/aws-sdk-go-v2 => ../../ diff --git a/internal/ini/go.sum b/internal/ini/go.sum new file mode 100644 index 00000000000..a2f91da2f3c --- /dev/null +++ b/internal/ini/go.sum @@ -0,0 +1,10 @@ +github.com/aws/smithy-go v1.4.0/go.mod h1:SObp3lf9smib00L/v3U2eAKG8FyQ7iLrJnQiAmR5n+E= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= +github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/internal/ini/go_module_metadata.go b/internal/ini/go_module_metadata.go new file mode 100644 index 00000000000..deb0e79d8d0 --- /dev/null +++ b/internal/ini/go_module_metadata.go @@ -0,0 +1,6 @@ +// Code generated by internal/repotools/cmd/updatemodulemeta DO NOT EDIT. + +package ini + +// goModuleVersion is the tagged release for this module +const goModuleVersion = "tip" diff --git a/internal/repotools/git/git.go b/internal/repotools/git/git.go index 7f934dfe404..8675bc59593 100644 --- a/internal/repotools/git/git.go +++ b/internal/repotools/git/git.go @@ -2,16 +2,33 @@ package git import ( "fmt" - "github.com/aws/aws-sdk-go-v2/internal/repotools/semver" - "golang.org/x/mod/module" "os" "os/exec" "path" "sort" "strconv" "strings" + + "github.com/aws/aws-sdk-go-v2/internal/repotools/semver" + "golang.org/x/mod/module" ) +// LsTree lists the files present in the tree-ish for the repository. An optional set of one or more paths can be +// provided to limit the output file paths. +func LsTree(repository, tree string, path ...string) ([]string, error) { + arguments := []string{"ls-tree", "-r", "--name-only", tree} + if len(path) > 0 { + arguments = append(arguments, path...) + } + + output, err := Git(repository, arguments...) + if err != nil { + return nil, err + } + + return splitOutput(string(output)), nil +} + // Tags returns a slice of Git tags at the repository located at path func Tags(path string) ([]string, error) { output, err := Git(path, "tag", "-l") diff --git a/internal/repotools/gomod/diff.go b/internal/repotools/gomod/diff.go index e53863dbbcd..0674c84ad6c 100644 --- a/internal/repotools/gomod/diff.go +++ b/internal/repotools/gomod/diff.go @@ -28,10 +28,10 @@ func IsModuleChanged(moduleDir string, submodules []string, changes []string) (b continue } - if len(dir) == 0 && IsGoSource(fileName) { + if len(dir) == 0 && (IsGoSource(fileName) || IsGoMod(fileName)) { hasChanges = true continue - } else if !IsGoSource(fileName) { + } else if !(IsGoSource(fileName) || IsGoMod(fileName)) { continue } dir = path.Clean(dir) @@ -56,7 +56,12 @@ func IsModuleChanged(moduleDir string, submodules []string, changes []string) (b return hasChanges, nil } -// IsGoSource returns whether a given file name is a Go source code file ending in `.go` or if the file is `go.mod`. +// IsGoSource returns whether a given file name is a Go source code file ending in `.go` func IsGoSource(name string) bool { - return !strings.HasPrefix(name, ".") && strings.HasSuffix(name, ".go") || name == "go.mod" + return !strings.HasPrefix(name, ".") && strings.HasSuffix(name, ".go") +} + +// IsGoMod returns whether a given file name is `go.mod`. +func IsGoMod(name string) bool { + return name == "go.mod" } diff --git a/internal/repotools/release/calculate.go b/internal/repotools/release/calculate.go index a6ddeca1082..33e5d85a747 100644 --- a/internal/repotools/release/calculate.go +++ b/internal/repotools/release/calculate.go @@ -2,13 +2,13 @@ package release import ( "fmt" - "log" - "path/filepath" - "github.com/aws/aws-sdk-go-v2/internal/repotools" "github.com/aws/aws-sdk-go-v2/internal/repotools/changelog" "github.com/aws/aws-sdk-go-v2/internal/repotools/git" "github.com/aws/aws-sdk-go-v2/internal/repotools/gomod" + "log" + "path" + "path/filepath" ) // ModuleFinder is a type that @@ -67,6 +67,29 @@ func Calculate(finder ModuleFinder, tags git.ModuleTags, config repotools.Config if err != nil { return nil, fmt.Errorf("failed to determine module changes: %w", err) } + + if !hasChanges { + // Check if any of the submodules have been "carved out" of this module since the last tagged release + for _, subModuleDir := range repositoryModules[moduleDir] { + if _, ok := tags.Latest(subModuleDir); ok { + continue + } + + treeFiles, err := git.LsTree(rootDir, latestVersion, subModuleDir) + if err != nil { + return nil, fmt.Errorf("failed to list git tree: %v", err) + } + + carvedOut, err := isModuleCarvedOut(treeFiles, repositoryModules[subModuleDir]) + if err != nil { + return nil, err + } + if carvedOut { + hasChanges = true + break + } + } + } } var changeReason ModuleChange @@ -98,3 +121,45 @@ func Calculate(finder ModuleFinder, tags git.ModuleTags, config repotools.Config return modules, nil } + +// isModuleCarvedOut takes a list of files for a (new) submodule directory. The list of files are the files that are located +// in the submodule directory path from the parent's previous tagged release. Returns true the new submodule has been +// carved out of the parent module directory it is located under. This is determined by looking through the file list +// and determining if Go source is present but no `go.mod` file existed. +func isModuleCarvedOut(files []string, subModules []string) (bool, error) { + hasGoSource := false + hasGoMod := false + + isChildPathCache := make(map[string]bool) + + for _, file := range files { + dir, fileName := path.Split(file) + dir = path.Clean(dir) + + isGoMod := gomod.IsGoMod(fileName) + isGoSource := gomod.IsGoSource(fileName) + + if !(isGoMod || isGoSource) { + continue + } + + if isChild, ok := isChildPathCache[dir]; (isChild && ok) || (!ok && gomod.IsSubmodulePath(dir, subModules)) { + isChildPathCache[dir] = true + continue + } else { + isChildPathCache[dir] = false + } + + if isGoSource { + hasGoSource = true + } else if isGoMod { + hasGoMod = true + } + + if hasGoMod && hasGoSource { + break + } + } + + return !hasGoMod && hasGoSource, nil +} diff --git a/internal/repotools/release/calculate_test.go b/internal/repotools/release/calculate_test.go new file mode 100644 index 00000000000..c18e16bf166 --- /dev/null +++ b/internal/repotools/release/calculate_test.go @@ -0,0 +1,75 @@ +package release + +import ( + "testing" +) + +func Test_isModuleCarvedOut1(t *testing.T) { + tests := map[string]struct { + files []string + subModules []string + want bool + wantErr bool + }{ + "no submodules, has go.mod, has go source": { + files: []string{ + "a/go.mod", + "a/foo.go", + }, + want: false, + }, + "no submodules, no go.mod, has go source": { + files: []string{ + "a/foo.go", + }, + want: true, + }, + "no submodules, no files": { + want: false, + }, + "submodules, no go.mod, no go source": { + files: []string{ + "a/b/go.mod", + "a/b/foo.go", + "a/c/go.mod", + "a/c/bar.go", + }, + subModules: []string{"a/b", "a/c"}, + want: false, + }, + "submodules, has go.mod, no go source": { + files: []string{ + "a/b/go.mod", + "a/b/foo.go", + "a/c/go.mod", + "a/c/bar.go", + "a/go.mod", + }, + subModules: []string{"a/b", "a/c"}, + want: false, + }, + "submodules, no go.mod, has go source": { + files: []string{ + "a/b/go.mod", + "a/b/foo.go", + "a/c/go.mod", + "a/c/bar.go", + "a/foo.go", + }, + subModules: []string{"a/b", "a/c"}, + want: true, + }, + } + for name, tt := range tests { + t.Run(name, func(t *testing.T) { + got, err := isModuleCarvedOut(tt.files, tt.subModules) + if (err != nil) != tt.wantErr { + t.Errorf("isModuleCarvedOut() error = %v, wantErr %v", err, tt.wantErr) + return + } + if got != tt.want { + t.Errorf("isModuleCarvedOut() got = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/service/internal/integrationtest/go.mod b/service/internal/integrationtest/go.mod index 393287e8910..cfdc893f027 100644 --- a/service/internal/integrationtest/go.mod +++ b/service/internal/integrationtest/go.mod @@ -98,6 +98,8 @@ replace github.com/aws/aws-sdk-go-v2/credentials => ../../../credentials/ replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../../feature/ec2/imds/ +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../../internal/ini/ + replace github.com/aws/aws-sdk-go-v2/service/acm => ../../../service/acm/ replace github.com/aws/aws-sdk-go-v2/service/apigateway => ../../../service/apigateway/ diff --git a/service/s3/internal/configtesting/go.mod b/service/s3/internal/configtesting/go.mod index 270fc2f28d9..a0d0534baf2 100644 --- a/service/s3/internal/configtesting/go.mod +++ b/service/s3/internal/configtesting/go.mod @@ -15,6 +15,8 @@ replace github.com/aws/aws-sdk-go-v2/credentials => ../../../../credentials/ replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../../../feature/ec2/imds/ +replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../../../internal/ini/ + replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../../../service/internal/presigned-url/ replace github.com/aws/aws-sdk-go-v2/service/internal/s3shared => ../../../../service/internal/s3shared/