Skip to content
This repository has been archived by the owner on Aug 6, 2023. It is now read-only.

Commit

Permalink
Do not touch if no change occured
Browse files Browse the repository at this point in the history
  • Loading branch information
kachick committed Jun 16, 2023
1 parent b8415ad commit 73f17a6
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions nix-headbump.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"bytes"
"encoding/json"
"flag"
"fmt"
Expand Down Expand Up @@ -52,7 +53,7 @@ type Response struct {
}

func bump(path string) error {
bytes, err := os.ReadFile(path)
origin, err := os.ReadFile(path)
if err != nil {
return err
}
Expand All @@ -74,6 +75,10 @@ func bump(path string) error {
if json.Unmarshal(body, jsonRes) != nil {
return err
}
replaced := re.ReplaceAll(bytes, []byte("${1}"+jsonRes.Commit.Sha+"${2}"))
replaced := re.ReplaceAll(origin, []byte("${1}"+jsonRes.Commit.Sha+"${2}"))
if bytes.Equal(origin, replaced) {
return nil
}

return os.WriteFile(path, replaced, os.ModePerm)
}

0 comments on commit 73f17a6

Please sign in to comment.