Skip to content

Commit

Permalink
fix: skips submodule metdata autogen if readme isn't present (#1428)
Browse files Browse the repository at this point in the history
Co-authored-by: Awais Malik <awmalik@google.com>
  • Loading branch information
g-awmalik and g-awmalik committed Mar 8, 2023
1 parent a7dcc74 commit a87b654
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cli/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
SHELL := /bin/bash

# Changing this value will trigger a new release
VERSION=v0.5.4
VERSION=v0.5.5
BINARY=bin/cft
GITHUB_REPO=github.com/GoogleCloudPlatform/cloud-foundation-toolkit
PLATFORMS := linux windows darwin
Expand Down
22 changes: 19 additions & 3 deletions cli/bpmetadata/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,16 @@ func generate(cmd *cobra.Command, args []string) error {

var allBpPaths []string
currBpPath := path.Join(wdPath, mdFlags.path)
allBpPaths = append(allBpPaths, currBpPath)
_, err = os.Stat(path.Join(currBpPath, readmeFileName))

// throw an error and exit if root level readme.md doesn't exist
if err != nil {
return fmt.Errorf("Top-level module does not have a readme. Details: %w\n", err)
}

allBpPaths = append(allBpPaths, currBpPath)
var errors []string

// if nested, check if modules/ exists and create paths
// for submodules
if mdFlags.nested {
Expand All @@ -77,8 +84,17 @@ func generate(cmd *cobra.Command, args []string) error {
}
}

for _, path := range allBpPaths {
err = generateMetadataForBpPath(path)
for _, modPath := range allBpPaths {
// check if module path has readme.md
_, err := os.Stat(path.Join(modPath, readmeFileName))

// log info if a sub-module doesn't have a readme.md and continue
if err != nil {
Log.Info("Skipping metadata for sub-module identified as an internal module", "Path:", modPath)
continue
}

err = generateMetadataForBpPath(modPath)
if err != nil {
errors = append(errors, err.Error())
}
Expand Down

0 comments on commit a87b654

Please sign in to comment.