From 756a0b2baff8730da72b88fd36eeb7ebe8998a40 Mon Sep 17 00:00:00 2001 From: Han Qiao Date: Mon, 26 Feb 2024 18:49:28 +0800 Subject: [PATCH] fix: update release process to create PR (#1991) --- .github/workflows/release-beta.yml | 17 +++++ .goreleaser.yml | 31 -------- tools/publish/main.go | 49 ++++++++++--- tools/publish/templates/supabase.json | 11 ++- tools/publish/templates/supabase.rb | 100 +++++++++++++------------- 5 files changed, 114 insertions(+), 94 deletions(-) diff --git a/.github/workflows/release-beta.yml b/.github/workflows/release-beta.yml index 21bdac0c0..3b67f4a36 100644 --- a/.github/workflows/release-beta.yml +++ b/.github/workflows/release-beta.yml @@ -56,6 +56,23 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + commit: + name: Publish Brew and Scoop + needs: + - release + - goreleaser + if: needs.release.outputs.new-release-published == 'true' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + cache: true + - run: go run tools/publish/main.go --beta "${GITHUB_REF_NAME#v}" + env: + GITHUB_TOKEN: ${{ secrets.GH_PAT }} + publish: name: Publish NPM needs: diff --git a/.goreleaser.yml b/.goreleaser.yml index 20ce8aa0b..06d6c5f6b 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -32,37 +32,6 @@ changelog: order: 1 - title: Others order: 999 -brews: - - name: supabase-beta - tap: - owner: supabase - name: homebrew-tap - token: "{{ .Env.BREWTAP_TOKEN }}" - commit_author: - name: Bobbie Soedirgo - email: bobbie@soedirgo.dev - url_template: "https://github.com/supabase/cli/releases/download/{{ .Tag }}/{{ .ArtifactName }}" - homepage: https://supabase.com - description: Supabase CLI (Beta) - license: MIT - install: | - bin.install "supabase" - (bash_completion/"supabase").write `#{bin}/supabase completion bash` - (fish_completion/"supabase.fish").write `#{bin}/supabase completion fish` - (zsh_completion/"_supabase").write `#{bin}/supabase completion zsh` -scoops: - - name: supabase-beta - bucket: - owner: supabase - name: scoop-bucket - token: "{{ .Env.SCOOP_TOKEN }}" - commit_author: - name: Bobbie Soedirgo - email: bobbie@soedirgo.dev - url_template: "https://github.com/supabase/cli/releases/download/{{ .Tag }}/{{ .ArtifactName }}" - homepage: https://supabase.com - description: Supabase CLI (Beta) - license: MIT nfpms: - vendor: Supabase description: Supabase CLI diff --git a/tools/publish/main.go b/tools/publish/main.go index e9202eae9..20afd7b20 100644 --- a/tools/publish/main.go +++ b/tools/publish/main.go @@ -6,6 +6,7 @@ import ( "context" _ "embed" "encoding/base64" + "flag" "fmt" "io" "log" @@ -36,32 +37,45 @@ var ( ) func main() { - if len(os.Args) < 2 { + beta := flag.Bool("beta", false, "Updates the beta release channel.") + flag.Parse() + + semver := flag.Arg(0) + if len(semver) == 0 { log.Fatalln("Missing required arg: version") } - semver := os.Args[1] ctx, _ := signal.NotifyContext(context.Background(), os.Interrupt) - if err := publishPackages(ctx, semver); err != nil { + if err := publishPackages(ctx, semver, *beta); err != nil { log.Fatalln(err) } } -func publishPackages(ctx context.Context, version string) error { +func publishPackages(ctx context.Context, version string, beta bool) error { config, err := fetchConfig(ctx, version) if err != nil { return err } + config.FormulaName = "Supabase" + config.Description = "Supabase CLI" + filename := "supabase" + if beta { + config.FormulaName += "Beta" + config.Description += " (Beta)" + filename += "-beta" + } client := shared.NewGtihubClient(ctx) - if err := updatePackage(ctx, client, HOMEBREW_REPO, "supabase.rb", brewFormulaTemplate, config); err != nil { + if err := updatePackage(ctx, client, HOMEBREW_REPO, filename+".rb", brewFormulaTemplate, config); err != nil { return err } - return updatePackage(ctx, client, SCOOP_REPO, "supabase.json", scoopBucketTemplate, config) + return updatePackage(ctx, client, SCOOP_REPO, filename+".json", scoopBucketTemplate, config) } type PackageConfig struct { - Version string - Checksum map[string]string + Version string + Checksum map[string]string + Description string + FormulaName string } func fetchConfig(ctx context.Context, version string) (PackageConfig, error) { @@ -112,8 +126,14 @@ func updatePackage(ctx context.Context, client *github.Client, repo, path string if err := tmpl.Execute(&buf, config); err != nil { return err } + branch := "release/cli" + master := "main" + if err := shared.CreateGitBranch(ctx, client, SUPABASE_OWNER, repo, branch, master); err != nil { + return err + } // Get file SHA - file, _, _, err := client.Repositories.GetContents(ctx, SUPABASE_OWNER, repo, path, nil) + opts := github.RepositoryContentGetOptions{Ref: "heads/" + branch} + file, _, _, err := client.Repositories.GetContents(ctx, SUPABASE_OWNER, repo, path, &opts) if err != nil { return err } @@ -126,16 +146,23 @@ func updatePackage(ctx context.Context, client *github.Client, repo, path string return nil } // Update file content - message := "Update supabase stable release channel" + message := "Release " + config.Description commit := github.RepositoryContentFileOptions{ Message: &message, Content: buf.Bytes(), SHA: file.SHA, + Branch: &branch, } resp, _, err := client.Repositories.UpdateFile(ctx, SUPABASE_OWNER, repo, path, &commit) if err != nil { return err } fmt.Fprintln(os.Stderr, "Committed changes to", *resp.Commit.SHA) - return nil + // Create pull request + pr := github.NewPullRequest{ + Title: &message, + Head: &branch, + Base: &master, + } + return shared.CreatePullRequest(ctx, client, SUPABASE_OWNER, repo, pr) } diff --git a/tools/publish/templates/supabase.json b/tools/publish/templates/supabase.json index 7ac518c11..3d2d6befb 100644 --- a/tools/publish/templates/supabase.json +++ b/tools/publish/templates/supabase.json @@ -7,9 +7,16 @@ "supabase.exe" ], "hash": "{{ .Checksum.supabase_windows_amd64 }}" + }, + "arm64": { + "url": "https://github.com/supabase/cli/releases/download/v{{ .Version }}/supabase_windows_arm64.tar.gz", + "bin": [ + "supabase.exe" + ], + "hash": "{{ .Checksum.supabase_windows_arm64 }}" } }, "homepage": "https://supabase.com", "license": "MIT", - "description": "Supabase CLI" -} \ No newline at end of file + "description": "{{ .Description }}" +} diff --git a/tools/publish/templates/supabase.rb b/tools/publish/templates/supabase.rb index 6cfc9bddf..8f97a99b3 100644 --- a/tools/publish/templates/supabase.rb +++ b/tools/publish/templates/supabase.rb @@ -2,59 +2,59 @@ # frozen_string_literal: true # This file was generated by GoReleaser. DO NOT EDIT. -class Supabase < Formula - desc "Supabase CLI" - homepage "https://supabase.com" - version "{{ .Version }}" - license "MIT" - - on_macos do - if Hardware::CPU.arm? - url "https://github.com/supabase/cli/releases/download/v{{ .Version }}/supabase_darwin_arm64.tar.gz" - sha256 "{{ .Checksum.supabase_darwin_arm64 }}" - - def install - bin.install "supabase" - (bash_completion/"supabase").write `#{bin}/supabase completion bash` - (fish_completion/"supabase.fish").write `#{bin}/supabase completion fish` - (zsh_completion/"_supabase").write `#{bin}/supabase completion zsh` - end +class {{ .FormulaName }} < Formula + desc "{{ .Description }}" + homepage "https://supabase.com" + version "{{ .Version }}" + license "MIT" + + on_macos do + if Hardware::CPU.arm? + url "https://github.com/supabase/cli/releases/download/v{{ .Version }}/supabase_darwin_arm64.tar.gz" + sha256 "{{ .Checksum.supabase_darwin_arm64 }}" + + def install + bin.install "supabase" + (bash_completion/"supabase").write `#{bin}/supabase completion bash` + (fish_completion/"supabase.fish").write `#{bin}/supabase completion fish` + (zsh_completion/"_supabase").write `#{bin}/supabase completion zsh` end - if Hardware::CPU.intel? - url "https://github.com/supabase/cli/releases/download/v{{ .Version }}/supabase_darwin_amd64.tar.gz" - sha256 "{{ .Checksum.supabase_darwin_amd64 }}" - - def install - bin.install "supabase" - (bash_completion/"supabase").write `#{bin}/supabase completion bash` - (fish_completion/"supabase.fish").write `#{bin}/supabase completion fish` - (zsh_completion/"_supabase").write `#{bin}/supabase completion zsh` - end + end + if Hardware::CPU.intel? + url "https://github.com/supabase/cli/releases/download/v{{ .Version }}/supabase_darwin_amd64.tar.gz" + sha256 "{{ .Checksum.supabase_darwin_amd64 }}" + + def install + bin.install "supabase" + (bash_completion/"supabase").write `#{bin}/supabase completion bash` + (fish_completion/"supabase.fish").write `#{bin}/supabase completion fish` + (zsh_completion/"_supabase").write `#{bin}/supabase completion zsh` end end - - on_linux do - if Hardware::CPU.arm? && Hardware::CPU.is_64_bit? - url "https://github.com/supabase/cli/releases/download/v{{ .Version }}/supabase_linux_arm64.tar.gz" - sha256 "{{ .Checksum.supabase_linux_arm64 }}" - - def install - bin.install "supabase" - (bash_completion/"supabase").write `#{bin}/supabase completion bash` - (fish_completion/"supabase.fish").write `#{bin}/supabase completion fish` - (zsh_completion/"_supabase").write `#{bin}/supabase completion zsh` - end + end + + on_linux do + if Hardware::CPU.arm? && Hardware::CPU.is_64_bit? + url "https://github.com/supabase/cli/releases/download/v{{ .Version }}/supabase_linux_arm64.tar.gz" + sha256 "{{ .Checksum.supabase_linux_arm64 }}" + + def install + bin.install "supabase" + (bash_completion/"supabase").write `#{bin}/supabase completion bash` + (fish_completion/"supabase.fish").write `#{bin}/supabase completion fish` + (zsh_completion/"_supabase").write `#{bin}/supabase completion zsh` end - if Hardware::CPU.intel? - url "https://github.com/supabase/cli/releases/download/v{{ .Version }}/supabase_linux_amd64.tar.gz" - sha256 "{{ .Checksum.supabase_linux_amd64 }}" - - def install - bin.install "supabase" - (bash_completion/"supabase").write `#{bin}/supabase completion bash` - (fish_completion/"supabase.fish").write `#{bin}/supabase completion fish` - (zsh_completion/"_supabase").write `#{bin}/supabase completion zsh` - end + end + if Hardware::CPU.intel? + url "https://github.com/supabase/cli/releases/download/v{{ .Version }}/supabase_linux_amd64.tar.gz" + sha256 "{{ .Checksum.supabase_linux_amd64 }}" + + def install + bin.install "supabase" + (bash_completion/"supabase").write `#{bin}/supabase completion bash` + (fish_completion/"supabase.fish").write `#{bin}/supabase completion fish` + (zsh_completion/"_supabase").write `#{bin}/supabase completion zsh` end end - end \ No newline at end of file + end +end