-
Notifications
You must be signed in to change notification settings - Fork 835
[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
3vilhamster
wants to merge
12
commits into
cadence-workflow:master
Choose a base branch
from
3vilhamster:release-script
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
53077b0
[scripte] Introduce a script that will create release/prerelease
3vilhamster 1b569f5
check for master and changes
3vilhamster 560fc92
convert the script to go binary with tests
3vilhamster aff5765
set the default branch to master
3vilhamster a6891a7
fix lint issue
3vilhamster 67e6bab
remove clean repo requirement - we push existing commits
3vilhamster 3045f5c
tests cleanup
3vilhamster d7ce004
use go.work instead of directory traversal
3vilhamster 64794d0
add signal handling and propagate context so that operations could be…
3vilhamster e48bd27
use simple logger, simplify code and flow
3vilhamster 1773f27
change the flow to explicit command to calculate the version
3vilhamster ad3a655
mod tidy
3vilhamster File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
3vilhamster marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 | ||
} | ||
3vilhamster marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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 | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.