-
-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: use a pre-commit hook to set a .version file instead of using git
This ensures that the flake, go get and goreleaser deployments all have the same version number, since the version number will come from the git repo instead.
- Loading branch information
Showing
7 changed files
with
50 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.2.418-next |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.2.418-next |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"log" | ||
"os/exec" | ||
"strings" | ||
) | ||
|
||
var fileFlag = flag.String("file", ".version", "Set the name of the file to modify") | ||
|
||
func main() { | ||
gitPath, err := exec.LookPath("git") | ||
if err != nil { | ||
log.Fatalf("failed to find git on path: %v", err) | ||
} | ||
|
||
cmd := exec.Command(gitPath, "rev-list", "main", "--count") | ||
output, err := cmd.Output() | ||
if err != nil { | ||
log.Fatalf("failed to run git: %v", err) | ||
} | ||
count := strings.TrimSpace(string(output)) | ||
|
||
var dirty string | ||
cmd = exec.Command(gitPath, "diff", "--quiet") | ||
if cmd.Run() != nil { | ||
dirty = "-next" | ||
} | ||
|
||
fmt.Printf("0.2.%s%s", count, dirty) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#!/bin/sh | ||
export VERSION=`git rev-list --count HEAD`; | ||
echo Adding git tag with version v0.2.${VERSION}; | ||
git tag v0.2.${VERSION}; | ||
git push origin v0.2.${VERSION}; | ||
export VERSION=`cat .version` | ||
echo Adding git tag with version v${VERSION}; | ||
git tag v${VERSION}; | ||
git push origin v${VERSION}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
package templ | ||
|
||
// Binary builds set this version string. goreleaser sets the value using Go build ldflags. | ||
import _ "embed" | ||
|
||
//go:embed .version | ||
var Version string |