Skip to content

chore(scripts): add release autoversion to bump releases in docs #13063

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

Merged
Changes from 1 commit
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
Prev Previous commit
ensure run in coder repo, use base path fs
  • Loading branch information
mafredri committed Apr 25, 2024
commit 1fdff416fe8742e8dcd94e8214744f3e19d037e1
39 changes: 37 additions & 2 deletions scripts/release/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io/fs"
"os"
"os/exec"
"path/filepath"
"regexp"
"slices"
Expand All @@ -30,8 +31,22 @@ const (
)

func main() {
// Pre-flight checks.
toplevel, err := run("git", "rev-parse", "--show-toplevel")
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "ERROR: %v\n", err)
_, _ = fmt.Fprintf(os.Stderr, "NOTE: This command must be run in the coder/coder repository.\n")
os.Exit(1)
}

if err = checkCoderRepo(toplevel); err != nil {
_, _ = fmt.Fprintf(os.Stderr, "ERROR: %v\n", err)
_, _ = fmt.Fprintf(os.Stderr, "NOTE: This command must be run in the coder/coder repository.\n")
os.Exit(1)
}

r := &releaseCommand{
fs: afero.NewOsFs(),
fs: afero.NewBasePathFs(afero.NewOsFs(), toplevel),
logger: slog.Make(sloghuman.Sink(os.Stderr)).Leveled(slog.LevelInfo),
}

Expand Down Expand Up @@ -109,7 +124,7 @@ func main() {
},
}

err := cmd.Invoke().WithOS().Run()
err = cmd.Invoke().WithOS().Run()
if err != nil {
if errors.Is(err, cliui.Canceled) {
os.Exit(1)
Expand All @@ -119,6 +134,17 @@ func main() {
}
}

func checkCoderRepo(path string) error {
remote, err := run("git", "-C", path, "remote", "get-url", "origin")
if err != nil {
return xerrors.Errorf("get remote failed: %w", err)
}
if !strings.Contains(remote, "github.com") || !strings.Contains(remote, "coder/coder") {
return xerrors.Errorf("origin is not set to the coder/coder repository on github.com")
}
return nil
}

type releaseCommand struct {
fs afero.Fs
logger slog.Logger
Expand Down Expand Up @@ -389,3 +415,12 @@ func (r *releaseCommand) autoversionFile(ctx context.Context, file, channel, ver

return nil
}

func run(command string, args ...string) (string, error) {
cmd := exec.Command(command, args...)
out, err := cmd.CombinedOutput()
if err != nil {
return "", xerrors.Errorf("command failed: %q: %w\n%s", fmt.Sprintf("%s %s", command, strings.Join(args, " ")), err, out)
}
return strings.TrimSpace(string(out)), nil
}
Loading