release.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "log"
  6. "os"
  7. "os/exec"
  8. "strings"
  9. )
  10. func main() {
  11. draft := flag.Bool("draft", false, "create a draft release")
  12. docker := flag.Bool("docker", false, "create a docker release")
  13. flag.Parse()
  14. version := os.Getenv("VERSION")
  15. sha := os.Getenv("GITHUB_SHA")
  16. ref := os.Getenv("GITHUB_REF")
  17. if version == "" {
  18. cmd := exec.Command("git", "show", "--no-patch", "--no-notes", "--pretty=%ci", sha)
  19. out, err := cmd.CombinedOutput()
  20. if err != nil {
  21. log.Println(strings.TrimSpace(string(out)))
  22. log.Fatal(err)
  23. }
  24. var date string
  25. parts := strings.Split(string(out), " ")
  26. date = strings.Replace(parts[0]+parts[1], "-", "", -1)
  27. date = strings.Replace(date, ":", "", -1)
  28. version = fmt.Sprintf("v0.0.0-%s-%s", date, sha[:12])
  29. }
  30. if *docker {
  31. x := "-extldflags \"-static\" -X github.com/kyleconroy/sqlc/internal/cmd.version=" + version
  32. args := []string{
  33. "build",
  34. "-a",
  35. "-ldflags", x,
  36. "-o", "/workspace/sqlc",
  37. "./cmd/sqlc",
  38. }
  39. cmd := exec.Command("go", args...)
  40. cmd.Env = os.Environ()
  41. out, err := cmd.CombinedOutput()
  42. if err != nil {
  43. log.Println(strings.TrimSpace(string(out)))
  44. log.Fatal(err)
  45. }
  46. return
  47. }
  48. arch := flag.Arg(0)
  49. if arch == "" {
  50. log.Fatalf("missing platform_arch argument")
  51. }
  52. xname := "./equinox"
  53. if _, err := os.Stat("./equinox"); os.IsNotExist(err) {
  54. xname = "equinox"
  55. }
  56. channel := "devel"
  57. if strings.HasPrefix(ref, "refs/tags/") {
  58. channel = "stable"
  59. version = strings.TrimPrefix(ref, "refs/tags/")
  60. }
  61. args := []string{"release",
  62. "--channel", channel,
  63. "--version", version,
  64. }
  65. if *draft {
  66. args = append(args, "--draft")
  67. }
  68. x := "-X github.com/kyleconroy/sqlc/internal/cmd.version=" + version
  69. args = append(args, []string{
  70. "--platforms", flag.Arg(0),
  71. "--app", "app_i4iCp1SuYfZ",
  72. "--token", os.Getenv("EQUINOX_API_TOKEN"),
  73. "--",
  74. "-ldflags", x, "./cmd/sqlc",
  75. }...)
  76. log.Printf("Releasing %s on channel %s", flag.Arg(0), channel)
  77. cmd := exec.Command(xname, args...)
  78. cmd.Env = os.Environ()
  79. out, err := cmd.CombinedOutput()
  80. if err != nil {
  81. log.Println(strings.TrimSpace(string(out)))
  82. log.Fatal(err)
  83. }
  84. }