Skip to content

Commit d138552

Browse files
author
David Cavazos
committed
use log.Fatalf
1 parent fba5bc6 commit d138552

File tree

1 file changed

+8
-13
lines changed
  • .github/workflows/samples-tools/cmd

1 file changed

+8
-13
lines changed

.github/workflows/samples-tools/cmd/main.go

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package main
1919
import (
2020
"encoding/json"
2121
"fmt"
22+
"log"
2223
"os"
2324
"samples-tools/pkg/utils"
2425
"strings"
@@ -95,34 +96,29 @@ func printUsage(f *os.File) {
9596
func affectedCmd(configFile string, diffsFile string) {
9697
config, err := utils.LoadConfig(configFile)
9798
if err != nil {
98-
fmt.Fprintf(os.Stderr, "❌ error loading the config file: %v\n%v\n", configFile, err)
99-
os.Exit(1)
99+
log.Fatalf("❌ error loading the config file: %v\n%v\n", configFile, err)
100100
}
101101

102102
diffs, err := readDiffs(diffsFile)
103103
if err != nil {
104-
fmt.Fprintf(os.Stderr, "❌ error getting the diffs: %v\n%v\n", diffsFile, err)
105-
os.Exit(1)
104+
log.Fatalf("❌ error getting the diffs: %v\n%v\n", diffsFile, err)
106105
}
107106

108107
packages, err := affected(config, diffs)
109108
if err != nil {
110-
fmt.Fprintf(os.Stderr, "❌ error finding the affected packages.\n%v\n", err)
111-
os.Exit(1)
109+
log.Fatalf("❌ error finding the affected packages.\n%v\n", err)
112110
}
113111
if len(packages) > 256 {
114-
fmt.Fprintf(os.Stderr,
112+
log.Fatalf(
115113
"❌ Error: GitHub Actions only supports up to 256 packages, got %v packages, for more details see:\n%v\n",
116114
len(packages),
117115
"https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/running-variations-of-jobs-in-a-workflow",
118116
)
119-
os.Exit(1)
120117
}
121118

122119
packagesJson, err := json.Marshal(packages)
123120
if err != nil {
124-
fmt.Fprintf(os.Stderr, "❌ error marshaling packages to JSON.\n%v\n", err)
125-
os.Exit(1)
121+
log.Fatalf("❌ error marshaling packages to JSON.\n%v\n", err)
126122
}
127123

128124
fmt.Println(string(packagesJson))
@@ -131,8 +127,7 @@ func affectedCmd(configFile string, diffsFile string) {
131127
func runAllCmd(configFile string, script string) {
132128
config, err := utils.LoadConfig(configFile)
133129
if err != nil {
134-
fmt.Fprintf(os.Stderr, "❌ error loading the config file: %v\n%v\n", configFile, err)
135-
os.Exit(1)
130+
log.Fatalf("❌ error loading the config file: %v\n%v\n", configFile, err)
136131
}
137132

138133
packages, err := utils.FindAllPackages(".", config)
@@ -148,6 +143,6 @@ func runAllCmd(configFile string, script string) {
148143
fmt.Printf("Failed tests: %v\n", failed)
149144

150145
if failed > 0 {
151-
os.Exit(1)
146+
log.Fatalf("❌ some tests failed, exit with code 1.")
152147
}
153148
}

0 commit comments

Comments
 (0)