Skip to content

Commit

Permalink
Copy generator.yaml to apis/version directory
Browse files Browse the repository at this point in the history
Adding some logic to create copies of the `generator.yaml` within the
apis versions directories. These generator.yaml files we be reused by
the conversion webhook generator to understand the difference between
each two different API versions.

This patch Also adds a new utility function to copy files from a
source to a destination path.
  • Loading branch information
a-hilaly committed Jun 25, 2021
1 parent 4b8891c commit f926ca3
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
16 changes: 15 additions & 1 deletion cmd/ack-generate/command/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
generate "github.com/aws-controllers-k8s/code-generator/pkg/generate"
ackgenerate "github.com/aws-controllers-k8s/code-generator/pkg/generate/ack"
"github.com/aws-controllers-k8s/code-generator/pkg/model"
"github.com/aws-controllers-k8s/code-generator/pkg/util"
)

type contentType int
Expand Down Expand Up @@ -65,7 +66,20 @@ func saveGeneratedMetadata(cmd *cobra.Command, args []string) error {
optAWSSDKGoVersion,
optGeneratorConfigPath,
)
return err
if err != nil {
return fmt.Errorf("cannot create generation metadata file: %v", err)
}

copyDest := filepath.Join(
optOutputPath, "apis", optGenVersion, "generator.yaml",
)
err = util.CopyFile(optGeneratorConfigPath, copyDest)
if err != nil {
return fmt.Errorf("cannot copy generator configuration file: %v", err)
}

fmt.Println("copied to", copyDest)
return nil
}

// generateAPIs generates the Go files for each resource in the AWS service
Expand Down
32 changes: 31 additions & 1 deletion pkg/util/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,40 @@

package util

import "os"
import (
"io"
"os"
)

// FileExists returns True if the supplied file path exists, false otherwise
func FileExists(path string) bool {
_, err := os.Stat(path)
return !os.IsNotExist(err)
}

// CopyFile copies a file from a source path to a destination path.
func CopyFile(src, dest string) error {
srcFile, err := os.Open(src)
if err != nil {
return err
}
defer srcFile.Close()

destFile, err := os.Create(dest)
if err != nil {
return err
}
defer destFile.Close()

_, err = io.Copy(destFile, srcFile)
if err != nil {
return err
}

err = destFile.Sync()
if err != nil {
return err
}

return nil
}

0 comments on commit f926ca3

Please sign in to comment.