Skip to content

Commit

Permalink
fix updating latest Zig version to -wip nomination
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Gutekanst <[email protected]>
  • Loading branch information
emidoots committed Mar 8, 2024
1 parent b0c39ab commit c023963
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
13 changes: 12 additions & 1 deletion internal/wrench/scripts/install_zig.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os/exec"
"path/filepath"
"runtime"
"strings"

"github.com/hexops/wrench/internal/errors"
)
Expand All @@ -20,7 +21,7 @@ func init() {
Execute: func(args ...string) error {
force := len(args) == 1 && args[0] == "true"

wantZigVersion, err := QueryZigVersion("mach-latest")
wantZigVersion, err := QueryZigVersion("latest")
if err != nil {
return errors.Wrap(err, "QueryZigVersion")
}
Expand Down Expand Up @@ -97,6 +98,16 @@ func QueryZigVersion(name string) (string, error) {
if err := json.NewDecoder(resp.Body).Decode(&v); err != nil {
return "", err
}
if name == "latest" {
// If we want generic latest it means either we should use e.g. "2024.3.0-mach-wip" if
// there is a work-in-progress nomination, otherwise fallback to "mach-latest" tag.
for name, version := range v {
if strings.HasSuffix(name, "-mach-wip") {
return version.Version, nil
}
}
name = "mach-latest"
}
version, ok := v[name]
if !ok {
return "", fmt.Errorf("no Zig version %q found in %s", name, indexURL)
Expand Down
8 changes: 6 additions & 2 deletions internal/wrench/scripts/mach-push-rewrite-zig-version.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ import (
func init() {
Scripts = append(Scripts, Script{
Command: "mach-push-rewrite-zig-version",
Args: nil,
Args: []string{"new version"},
Description: "wrench installs prerequisites (Go), rebuilds itself, and restarts the service",
ExecuteResponse: func(args ...string) (*api.ScriptResponse, error) {
wantZigVersion, err := QueryZigVersion("mach-latest")
if len(args) != 1 {
return nil, errors.New("expected [new version] argument (e.g. 'latest', 'mach-latest')")
}

wantZigVersion, err := QueryZigVersion(args[0])
if err != nil {
return nil, errors.Wrap(err, "QueryZigVersion")
}
Expand Down

0 comments on commit c023963

Please sign in to comment.