diff --git a/.github/workflows/bintray.yml b/.github/workflows/bintray.yml new file mode 100644 index 0000000000..308c071a71 --- /dev/null +++ b/.github/workflows/bintray.yml @@ -0,0 +1,47 @@ +name: bintray + +on: + push: + branches: + - master + +jobs: + + macos: + name: release --platforms darwin + runs-on: macos-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: '1.15' + - uses: jfrog/setup-jfrog-cli@v1 + - id: gobuild + run: go run scripts/build/main.go + - run: echo ${{steps.gobuild.outputs.version}} + - run: zip -X -j sqlc-devel-darwin-amd64.zip ./sqlc + - run: tar -zcvf sqlc-devel-darwin-amd64.tar.gz ./sqlc + - run: jfrog bt upload --user kyleconroy --key "$BINTRAY_API_KEY" --publish --override "sqlc-devel-darwin-amd64.*" sqlc/devel/sqlc/${{steps.gobuild.outputs.version}} ${{steps.gobuild.outputs.version}}/ + + env: + BINTRAY_API_KEY: ${{ secrets.BINTRAY_API_KEY }} + + linux: + name: release --platforms linux + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: '1.15' + - uses: jfrog/setup-jfrog-cli@v1 + - id: gobuild + run: go run scripts/build/main.go + - run: echo ${{steps.gobuild.outputs.version}} + - run: zip -X -j sqlc-devel-linux-amd64.zip ./sqlc + - run: tar -zcvf sqlc-devel-linux-amd64.tar.gz ./sqlc + - run: jfrog bt upload --user kyleconroy --key "$BINTRAY_API_KEY" --publish --override "sqlc-devel-linux-amd64.*" sqlc/devel/sqlc/${{steps.gobuild.outputs.version}} ${{steps.gobuild.outputs.version}}/ + env: + BINTRAY_API_KEY: ${{ secrets.BINTRAY_API_KEY }} diff --git a/scripts/build/main.go b/scripts/build/main.go new file mode 100755 index 0000000000..3f217deb25 --- /dev/null +++ b/scripts/build/main.go @@ -0,0 +1,45 @@ +package main + +import ( + "fmt" + "log" + "os" + "os/exec" + "strings" +) + +func main() { + version := os.Getenv("VERSION") + sha := os.Getenv("GITHUB_SHA") + + if version == "" { + cmd := exec.Command("git", "show", "--no-patch", "--no-notes", "--pretty=%ci", sha) + out, err := cmd.CombinedOutput() + if err != nil { + log.Println(strings.TrimSpace(string(out))) + 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]) + } + + fmt.Printf("::set-output name=version::%s\n", version) + + x := "-X github.com/kyleconroy/sqlc/internal/cmd.version=" + version + args := []string{ + "build", + "-ldflags", x, + "-o", "./sqlc", + "./cmd/sqlc", + } + cmd := exec.Command("go", args...) + cmd.Env = os.Environ() + out, err := cmd.CombinedOutput() + if err != nil { + log.Println(strings.TrimSpace(string(out))) + log.Fatal(err) + } +}