Skip to content

Commit

Permalink
Accept publisher output file path via CLI arg
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 587807940
Change-Id: I7461bc065b8bd9ea6bba4f6aff5db54093ca032e
  • Loading branch information
tonyjhuang authored and copybara-github committed Dec 4, 2023
1 parent 9258e33 commit a674df9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
8 changes: 7 additions & 1 deletion cmd/firebase/publisher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
var (
apphostingYAMLFilePath = flag.String("apphostingyaml_filepath", "", "File path to user defined apphosting.yaml")
outputBundleDir = flag.String("output_bundle_dir", "", "File path to root directory of build artifacts aka Output Bundle (including bundle.yaml)")
outputFilePath = flag.String("output_filepath", "", "File path to write publisher output data to")
)

func main() {
Expand All @@ -39,7 +40,12 @@ func main() {
log.Fatal("--output_bundle_dir flag not specified.")
}

_, err := publisher.Publish(*apphostingYAMLFilePath, filepath.Join(*outputBundleDir, "bundle.yaml"))
if *outputFilePath == "" {
log.Fatal("--output_filepath flag not specified.")
}

err := publisher.Publish(
*apphostingYAMLFilePath, filepath.Join(*outputBundleDir, "bundle.yaml"), *outputFilePath)
if err != nil {
log.Fatal(err)
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/firebase/publisher/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ func writeToFile(fileData []byte, outputFilePath string) error {
return nil
}

// Publish takes in the path to various required files such as apphosting.yaml, bundle.yaml, and other files (tbd) and merges them into one output that describes the
// desired Backend Service configuration before pushing this information to the control plane.
func Publish(appHostingYAMLPath string, outputFilePath string) error {
// Publish takes in the path to various required files such as apphosting.yaml, bundle.yaml, and
// other files (tbd) and merges them into one output that describes the desired Backend Service
// configuration before pushing this information to the control plane.
func Publish(appHostingYAMLPath string, bundleYAMLPath string, outputFilePath string) error {
// Read in apphosting.yaml
apphostingBuffer, err := os.ReadFile(appHostingYAMLPath)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/firebase/publisher/publisher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestPublish(t *testing.T) {

// Testing happy paths
for _, test := range testCasesHappy {
err := Publish(test.filePath, outputFilePath)
err := Publish(test.filePath, "", outputFilePath)
if err != nil {
t.Errorf("Error in test '%v'. Error was %v", test.desc, err)
}
Expand All @@ -85,7 +85,7 @@ func TestPublish(t *testing.T) {

// Testing error paths
for _, test := range testCasesError {
err := Publish(test.filePath, outputFilePath)
err := Publish(test.filePath, "", outputFilePath)
if err == nil {
t.Errorf("Calling Publish did not produce an error for test '%v'", test.desc)
}
Expand Down

0 comments on commit a674df9

Please sign in to comment.