1
0

main.go 986 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "os"
  6. "os/exec"
  7. "strings"
  8. )
  9. func main() {
  10. version := os.Getenv("VERSION")
  11. sha := os.Getenv("GITHUB_SHA")
  12. if version == "" {
  13. cmd := exec.Command("git", "show", "--no-patch", "--no-notes", "--pretty=%ci", sha)
  14. out, err := cmd.CombinedOutput()
  15. if err != nil {
  16. log.Println(strings.TrimSpace(string(out)))
  17. log.Fatal(err)
  18. }
  19. var date string
  20. parts := strings.Split(string(out), " ")
  21. date = strings.Replace(parts[0]+parts[1], "-", "", -1)
  22. date = strings.Replace(date, ":", "", -1)
  23. version = fmt.Sprintf("v0.0.0-%s-%s", date, sha[:12])
  24. }
  25. fmt.Printf("::set-output name=version::%s\n", version)
  26. x := "-X github.com/sqlc-dev/sqlc/internal/cmd.version=" + version
  27. args := []string{
  28. "build",
  29. "-ldflags", x,
  30. "-o", "./sqlc",
  31. "./cmd/sqlc",
  32. }
  33. cmd := exec.Command("go", args...)
  34. cmd.Env = os.Environ()
  35. out, err := cmd.CombinedOutput()
  36. if err != nil {
  37. log.Println(strings.TrimSpace(string(out)))
  38. log.Fatal(err)
  39. }
  40. }