Skip to content

Commit

Permalink
fix: update release process to create PR (#1991)
Browse files Browse the repository at this point in the history
  • Loading branch information
sweatybridge authored Feb 26, 2024
1 parent cdf3892 commit 756a0b2
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 94 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/release-beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
31 changes: 0 additions & 31 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: [email protected]
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: [email protected]
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
Expand Down
49 changes: 38 additions & 11 deletions tools/publish/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"context"
_ "embed"
"encoding/base64"
"flag"
"fmt"
"io"
"log"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
}
11 changes: 9 additions & 2 deletions tools/publish/templates/supabase.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
"description": "{{ .Description }}"
}
100 changes: 50 additions & 50 deletions tools/publish/templates/supabase.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
end
end

0 comments on commit 756a0b2

Please sign in to comment.