Skip to content

Commit 81045f0

Browse files
authored
Copy generator.yaml to apis/version directory (#109)
Part of aws-controllers-k8s/community#835 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. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 4b8891c commit 81045f0

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

cmd/ack-generate/command/apis.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
generate "github.com/aws-controllers-k8s/code-generator/pkg/generate"
2525
ackgenerate "github.com/aws-controllers-k8s/code-generator/pkg/generate/ack"
2626
"github.com/aws-controllers-k8s/code-generator/pkg/model"
27+
"github.com/aws-controllers-k8s/code-generator/pkg/util"
2728
)
2829

2930
type contentType int
@@ -65,7 +66,19 @@ func saveGeneratedMetadata(cmd *cobra.Command, args []string) error {
6566
optAWSSDKGoVersion,
6667
optGeneratorConfigPath,
6768
)
68-
return err
69+
if err != nil {
70+
return fmt.Errorf("cannot create generation metadata file: %v", err)
71+
}
72+
73+
copyDest := filepath.Join(
74+
optOutputPath, "apis", optGenVersion, "generator.yaml",
75+
)
76+
err = util.CopyFile(optGeneratorConfigPath, copyDest)
77+
if err != nil {
78+
return fmt.Errorf("cannot copy generator configuration file: %v", err)
79+
}
80+
81+
return nil
6982
}
7083

7184
// generateAPIs generates the Go files for each resource in the AWS service

pkg/util/file.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,40 @@
1313

1414
package util
1515

16-
import "os"
16+
import (
17+
"io"
18+
"os"
19+
)
1720

1821
// FileExists returns True if the supplied file path exists, false otherwise
1922
func FileExists(path string) bool {
2023
_, err := os.Stat(path)
2124
return !os.IsNotExist(err)
2225
}
26+
27+
// CopyFile copies a file from a source path to a destination path.
28+
func CopyFile(src, dest string) error {
29+
srcFile, err := os.Open(src)
30+
if err != nil {
31+
return err
32+
}
33+
defer srcFile.Close()
34+
35+
destFile, err := os.Create(dest)
36+
if err != nil {
37+
return err
38+
}
39+
defer destFile.Close()
40+
41+
_, err = io.Copy(destFile, srcFile)
42+
if err != nil {
43+
return err
44+
}
45+
46+
err = destFile.Sync()
47+
if err != nil {
48+
return err
49+
}
50+
51+
return nil
52+
}

0 commit comments

Comments
 (0)