Skip to content

Commit 3e2e83d

Browse files
authored
Write a release script (#337)
* Write a release script * Fix issues * Create a draft release * Disable release on random branch
1 parent 73b06dc commit 3e2e83d

File tree

3 files changed

+70
-3
lines changed

3 files changed

+70
-3
lines changed

.github/workflows/equinox.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
env:
2222
EQUINOX_API_TOKEN: ${{ secrets.EQUINOX_API_TOKEN }}
2323
EQUINOX_SIGNING_KEY: ${{ secrets.EQUINOX_SIGNING_KEY }}
24-
run: equinox release --channel devel --version=$GITHUB_SHA --draft --platforms=darwin_amd64 --app=app_i4iCp1SuYfZ --token=$EQUINOX_API_TOKEN ./cmd/sqlc
24+
run: go run scripts/release.go -draft devel darwin_amd64
2525

2626
linux:
2727
name: Build on Linux
@@ -39,6 +39,6 @@ jobs:
3939
env:
4040
EQUINOX_API_TOKEN: ${{ secrets.EQUINOX_API_TOKEN }}
4141
EQUINOX_SIGNING_KEY: ${{ secrets.EQUINOX_SIGNING_KEY }}
42-
run: ./equinox release --channel devel --version=$GITHUB_SHA --platforms=linux_amd64 --app=app_i4iCp1SuYfZ --token=$EQUINOX_API_TOKEN ./cmd/sqlc
42+
run: go run scripts/release.go devel linux_amd64
4343

4444

internal/cmd/cmd.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,17 @@ func Do(args []string, stdin io.Reader, stdout io.Writer, stderr io.Writer) int
3737
return 1
3838
}
3939

40+
var version string
41+
4042
var versionCmd = &cobra.Command{
4143
Use: "version",
4244
Short: "Print the sqlc version number",
4345
Run: func(cmd *cobra.Command, args []string) {
44-
fmt.Println("v0.0.1")
46+
if version == "" {
47+
fmt.Printf("%s\n", "SNAPSHOT")
48+
} else {
49+
fmt.Printf("%s\n", version)
50+
}
4551
},
4652
}
4753

scripts/release.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"fmt"
6+
"log"
7+
"os"
8+
"os/exec"
9+
"strings"
10+
)
11+
12+
func main() {
13+
draft := flag.Bool("draft", false, "create a draft release")
14+
flag.Parse()
15+
16+
sha := os.Getenv("GITHUB_SHA")
17+
cmd := exec.Command("git", "show", "--no-patch", "--no-notes", "--pretty=%ci", sha)
18+
out, err := cmd.CombinedOutput()
19+
if err != nil {
20+
log.Fatal(err)
21+
}
22+
23+
var date string
24+
parts := strings.Split(string(out), " ")
25+
date = strings.Replace(parts[0]+parts[1], "-", "", -1)
26+
date = strings.Replace(date, ":", "", -1)
27+
version := fmt.Sprintf("v0.0.0-%s-%s", date, sha[:12])
28+
29+
x := "-X github.com/kyleconroy/sqlc/internal/cmd.version=" + version
30+
log.Printf("Releasing %s on channel %s", flag.Arg(1), flag.Arg(0))
31+
32+
xname := "./equinox"
33+
if _, err := os.Stat("./equinox"); os.IsNotExist(err) {
34+
xname = "equinox"
35+
}
36+
37+
args := []string{"release",
38+
"--channel", flag.Arg(0),
39+
"--version", version,
40+
}
41+
42+
if *draft {
43+
args = append(args, "--draft")
44+
}
45+
46+
args = append(args, []string{
47+
"--platforms", flag.Arg(1),
48+
"--app", "app_i4iCp1SuYfZ",
49+
"--token", os.Getenv("EQUINOX_API_TOKEN"),
50+
"--",
51+
"-ldflags", x, "./cmd/sqlc",
52+
}...)
53+
54+
cmd = exec.Command(xname, args...)
55+
cmd.Env = os.Environ()
56+
out, err = cmd.CombinedOutput()
57+
log.Println(strings.TrimSpace(string(out)))
58+
if err != nil {
59+
log.Fatal(err)
60+
}
61+
}

0 commit comments

Comments
 (0)