Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
kachick committed Sep 25, 2023
1 parent 05602a9 commit 7d2b121
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cmd/replace-with-commands/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ $ replace-with-commands --prefix='# @updator:' --list .github/workflows/*.yml

for _, path := range flag.Args() {
newLines := []string{}
isDirty := false

file, err := os.Create(path)
if err != nil {
Expand Down Expand Up @@ -100,11 +101,14 @@ $ replace-with-commands --prefix='# @updator:' --list .github/workflows/*.yml
log.Fatalf("%+v", xerrors.Errorf("%s:%d: Executing %s with bash has been failed: %w", path, lineNumber, definition.Command, err))
}
replaced := re.ReplaceAllString(head, strings.TrimSuffix(string(out), "\n"))
if replaced != head {
isDirty = true
}
newLines = append(newLines, replaced+match+tail)
}
}

if !isListMode {
if isDirty {
err = os.WriteFile(path, []byte(strings.Join(newLines, "\n")), os.ModePerm)
if err != nil {
log.Fatalf("%+v", xerrors.Errorf("%s: %w", path, err))
Expand Down

0 comments on commit 7d2b121

Please sign in to comment.