From 34d1961d6e90a1fb11246d9cdcec530b89f0ac5a Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Tue, 11 Feb 2020 20:40:42 -0800 Subject: [PATCH 1/4] Write a release script --- .github/workflows/equinox.yml | 5 ++-- internal/cmd/cmd.go | 8 ++++++- scripts/release.go | 45 +++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 3 deletions(-) create mode 100755 scripts/release.go diff --git a/.github/workflows/equinox.yml b/.github/workflows/equinox.yml index 5b80884db1..300f0e5f84 100644 --- a/.github/workflows/equinox.yml +++ b/.github/workflows/equinox.yml @@ -4,6 +4,7 @@ on: push: branches: - master + - release-test jobs: @@ -21,7 +22,7 @@ jobs: env: EQUINOX_API_TOKEN: ${{ secrets.EQUINOX_API_TOKEN }} EQUINOX_SIGNING_KEY: ${{ secrets.EQUINOX_SIGNING_KEY }} - run: equinox release --channel devel --version=$GITHUB_SHA --draft --platforms=darwin_amd64 --app=app_i4iCp1SuYfZ --token=$EQUINOX_API_TOKEN ./cmd/sqlc + run: go run scripts/release.go devel darwin_amd64 linux: name: Build on Linux @@ -39,6 +40,6 @@ jobs: env: EQUINOX_API_TOKEN: ${{ secrets.EQUINOX_API_TOKEN }} EQUINOX_SIGNING_KEY: ${{ secrets.EQUINOX_SIGNING_KEY }} - run: ./equinox release --channel devel --version=$GITHUB_SHA --platforms=linux_amd64 --app=app_i4iCp1SuYfZ --token=$EQUINOX_API_TOKEN ./cmd/sqlc + run: go run scripts/release.go devel linux_amd64 diff --git a/internal/cmd/cmd.go b/internal/cmd/cmd.go index 4f25d9523e..4108e28365 100644 --- a/internal/cmd/cmd.go +++ b/internal/cmd/cmd.go @@ -37,11 +37,17 @@ func Do(args []string, stdin io.Reader, stdout io.Writer, stderr io.Writer) int return 1 } +var version string + var versionCmd = &cobra.Command{ Use: "version", Short: "Print the sqlc version number", Run: func(cmd *cobra.Command, args []string) { - fmt.Println("v0.0.1") + if version == "" { + fmt.Printf("%s\n", "SNAPSHOT") + } else { + fmt.Printf("%s\n", version) + } }, } diff --git a/scripts/release.go b/scripts/release.go new file mode 100755 index 0000000000..4210632d8c --- /dev/null +++ b/scripts/release.go @@ -0,0 +1,45 @@ +package main + +import ( + "flag" + "fmt" + "log" + "os" + "os/exec" + "strings" +) + +func main() { + flag.Parse() + + sha := os.Getenv("GITHUB_SHA") + cmd := exec.Command("git", "show", "--no-patch", "--no-notes", "--pretty=%ci", sha) + out, err := cmd.CombinedOutput() + if err != nil { + log.Fatal(err) + } + + var date string + parts := strings.Split(string(out), " ") + date = strings.Replace(parts[0]+parts[1], "-", "", -1) + date = strings.Replace(date, ":", "", -1) + version := fmt.Sprintf("v0.0.0-%s-%s", date, sha[:12]) + + x := "-X github.com/kyleconroy/sqlc/internal/cmd.version=" + version + log.Printf("Releasing %s on channel %s", flag.Arg(1), flag.Arg(0)) + cmd = exec.Command("./equinox", "release", + "--channel", flag.Arg(0), + "--version", version, + "--platforms", flag.Arg(1), + "--app", "app_i4iCp1SuYfZ", + "--token", os.Getenv("EQUINOX_API_TOKEN"), + "--", + "-ldflags", x, "./cmd/sqlc", + ) + cmd.Env = os.Environ() + out, err = cmd.CombinedOutput() + if err != nil { + log.Fatal(err) + } + log.Println(out) +} From 1a5e1419b3bff7edcfbefad00ba4bdfb1c4a6ded Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Tue, 11 Feb 2020 21:08:45 -0800 Subject: [PATCH 2/4] Fix issues --- scripts/release.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/scripts/release.go b/scripts/release.go index 4210632d8c..c088203d45 100755 --- a/scripts/release.go +++ b/scripts/release.go @@ -27,7 +27,13 @@ func main() { x := "-X github.com/kyleconroy/sqlc/internal/cmd.version=" + version log.Printf("Releasing %s on channel %s", flag.Arg(1), flag.Arg(0)) - cmd = exec.Command("./equinox", "release", + + xname := "./equinox" + if _, err := os.Stat("./equinox"); os.IsNotExist(err) { + xname = "equinox" + } + + cmd = exec.Command(xname, "release", "--channel", flag.Arg(0), "--version", version, "--platforms", flag.Arg(1), @@ -38,8 +44,8 @@ func main() { ) cmd.Env = os.Environ() out, err = cmd.CombinedOutput() + log.Println(strings.TrimSpace(string(out))) if err != nil { log.Fatal(err) } - log.Println(out) } From fd7fe4c2bcbc109ecf2820fc0e0004fef10d2051 Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Tue, 11 Feb 2020 21:18:14 -0800 Subject: [PATCH 3/4] Create a draft release --- .github/workflows/equinox.yml | 2 +- scripts/release.go | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/workflows/equinox.yml b/.github/workflows/equinox.yml index 300f0e5f84..be49f7344c 100644 --- a/.github/workflows/equinox.yml +++ b/.github/workflows/equinox.yml @@ -22,7 +22,7 @@ jobs: env: EQUINOX_API_TOKEN: ${{ secrets.EQUINOX_API_TOKEN }} EQUINOX_SIGNING_KEY: ${{ secrets.EQUINOX_SIGNING_KEY }} - run: go run scripts/release.go devel darwin_amd64 + run: go run scripts/release.go -draft devel darwin_amd64 linux: name: Build on Linux diff --git a/scripts/release.go b/scripts/release.go index c088203d45..f2e468abeb 100755 --- a/scripts/release.go +++ b/scripts/release.go @@ -10,6 +10,7 @@ import ( ) func main() { + draft := flag.Bool("draft", false, "create a draft release") flag.Parse() sha := os.Getenv("GITHUB_SHA") @@ -33,15 +34,24 @@ func main() { xname = "equinox" } - cmd = exec.Command(xname, "release", + args := []string{"release", "--channel", flag.Arg(0), "--version", version, + } + + if *draft { + args = append(args, "--draft") + } + + args = append(args, []string{ "--platforms", flag.Arg(1), "--app", "app_i4iCp1SuYfZ", "--token", os.Getenv("EQUINOX_API_TOKEN"), "--", "-ldflags", x, "./cmd/sqlc", - ) + }...) + + cmd = exec.Command(xname, args...) cmd.Env = os.Environ() out, err = cmd.CombinedOutput() log.Println(strings.TrimSpace(string(out))) From 4342fb7af01050250ffe99e30acd5b731428bab5 Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Tue, 11 Feb 2020 21:21:39 -0800 Subject: [PATCH 4/4] Disable release on random branch --- .github/workflows/equinox.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/equinox.yml b/.github/workflows/equinox.yml index be49f7344c..bf9d2e9f3f 100644 --- a/.github/workflows/equinox.yml +++ b/.github/workflows/equinox.yml @@ -4,7 +4,6 @@ on: push: branches: - master - - release-test jobs: