Skip to content

[scripts] Introduce a script that will create release/prerelease #6954

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ worker*.log
/cadence-bench
/cadence-cassandra-tool
/cadence-sql-tool
/cadence-releaser

# SQLite databases
cadence.db*
cadence_visibility.db*
cadence_visibility.db*
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,12 @@ cadence-bench: $(BINS_DEPEND_ON)
$Q echo "compiling cadence-bench with OS: $(GOOS), ARCH: $(GOARCH)"
$Q ./scripts/build-with-ldflags.sh -o $@ cmd/bench/main.go


BINS += cadence-releaser
cadence-releaser: $(BINS_DEPEND_ON)
$Q echo "compiling cadence-releaser with OS: $(GOOS), ARCH: $(GOARCH)"
$Q ./scripts/build-with-ldflags.sh -o $@ cmd/tools/releaser/releaser.go

.PHONY: go-generate bins tools release clean

bins: $(BINS) ## Build all binaries, and any fast codegen needed (does not refresh wrappers or mocks)
Expand Down
63 changes: 63 additions & 0 deletions cmd/tools/releaser/internal/fs/fs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package fs

import (
"os"
"os/exec"
"path/filepath"

"go.uber.org/zap"
)

// Client implements Interface
type Client struct {
logger *zap.Logger
}

func NewFileSystemClient(logger *zap.Logger) *Client {
return &Client{logger: logger}
}

func (f *Client) FindGoModFiles(root string) ([]string, error) {
f.logger.Debug("Finding go.mod files", zap.String("root", root))
var goModFiles []string

err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}

if info.Name() == "go.mod" {
goModFiles = append(goModFiles, filepath.Dir(path))
}
return nil
})

f.logger.Debug("Found go.mod files", zap.Int("count", len(goModFiles)))
return goModFiles, err
}

func (f *Client) ModTidy(dir string) error {
f.logger.Debug("Running go mod tidy", zap.String("dir", dir))
cmd := exec.Command("go", "mod", "tidy")
cmd.Dir = dir
cmd.Stdout = nil
cmd.Stderr = nil
err := cmd.Run()
if err != nil {
f.logger.Error("go mod tidy failed", zap.String("dir", dir), zap.Error(err))
}
return err
}

func (f *Client) Build(dir string) error {
f.logger.Debug("Building Go module", zap.String("dir", dir))
cmd := exec.Command("go", "build", "./...")
cmd.Dir = dir
cmd.Stdout = nil
cmd.Stderr = nil
err := cmd.Run()
if err != nil {
f.logger.Error("go build failed", zap.String("dir", dir), zap.Error(err))
}
return err
}
91 changes: 91 additions & 0 deletions cmd/tools/releaser/internal/git/git.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package git

import (
"bufio"
"fmt"
"os/exec"
"strings"

"go.uber.org/zap"
)

// Client implements Interface
type Client struct {
logger *zap.Logger
}

func NewGitClient(logger *zap.Logger) *Client {
return &Client{logger: logger}
}

func (g *Client) GetCurrentBranch() (string, error) {
g.logger.Debug("Getting current git branch")
cmd := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD")
output, err := cmd.Output()
if err != nil {
return "", fmt.Errorf("get current branch: %w", err)
}
branch := strings.TrimSpace(string(output))
g.logger.Debug("Current branch", zap.String("branch", branch))
return branch, nil
}

func (g *Client) IsWorkingDirClean() (bool, error) {
g.logger.Debug("Checking if working directory is clean")
cmd := exec.Command("git", "diff-index", "--quiet", "HEAD", "--")
err := cmd.Run()
isClean := err == nil
g.logger.Debug("Working directory status", zap.Bool("clean", isClean))
return isClean, nil
}

func (g *Client) GetTags() ([]string, error) {
g.logger.Debug("Fetching git tags")
cmd := exec.Command("git", "tag", "-l")
output, err := cmd.Output()
if err != nil {
return nil, fmt.Errorf("get git tags: %w", err)
}

var tags []string
scanner := bufio.NewScanner(strings.NewReader(string(output)))
for scanner.Scan() {
if tag := strings.TrimSpace(scanner.Text()); tag != "" {
tags = append(tags, tag)
}
}
g.logger.Debug("Found git tags", zap.Int("count", len(tags)))
return tags, scanner.Err()
}

func (g *Client) CreateTag(tag string) error {
g.logger.Info("Creating git tag", zap.String("tag", tag))
cmd := exec.Command("git", "tag", tag)
err := cmd.Run()
if err != nil {
return fmt.Errorf("create tag %s: %w", tag, err)
}
return err
}

func (g *Client) PushTag(tag string) error {
g.logger.Info("Pushing git tag", zap.String("tag", tag))
cmd := exec.Command("git", "push", "origin", tag)
err := cmd.Run()
if err != nil {
return fmt.Errorf("push tag %s: %w", tag, err)
}
return err
}

func (g *Client) GetRepoRoot() (string, error) {
g.logger.Debug("Getting repository root")
cmd := exec.Command("git", "rev-parse", "--show-toplevel")
output, err := cmd.Output()
if err != nil {
return "", fmt.Errorf("get repository root: %w", err)
}
root := strings.TrimSpace(string(output))
g.logger.Debug("Repository root", zap.String("root", root))
return root, nil
}
Loading