Skip to content

Commit

Permalink
Merge pull request #21 from jcchavezs/upgrades_go_1.22
Browse files Browse the repository at this point in the history
chore: upgrades to go 1.22 and tinygo 0.33
  • Loading branch information
jcchavezs authored Oct 2, 2024
2 parents cdd5ac8 + f33ef5e commit 2c3c4e7
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ on:
- "LICENSE"

env:
GO_VERSION: "1.21.x"
TINYGO_VERSION: "0.30.0"
GO_VERSION: "1.22"
TINYGO_VERSION: "0.33.0"

jobs:
build:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/nightly-coraza-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ on:
- cron: "0 4 * * *"

env:
GO_VERSION: "1.21.x"
TINYGO_VERSION: "0.30.0"
GO_VERSION: "1.22"
TINYGO_VERSION: "0.33.0"

jobs:
test:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/corazawaf/coraza-http-wasm

go 1.21
go 1.22

require (
github.com/corazawaf/coraza-coreruleset/v4 v4.0.0
Expand Down
2 changes: 1 addition & 1 deletion go.work
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
go 1.21.0
go 1.22

use (
.
Expand Down
80 changes: 78 additions & 2 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
"io"
"os"
"path/filepath"
"regexp"
"strconv"
"strings"

"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
Expand All @@ -18,12 +21,85 @@ import (
var Default = Build

var (
golangCILintVer = "v1.56.2" // https://github.com/golangci/golangci-lint/releases
gosImportsVer = "v0.3.8" // https://github.com/rinchsan/gosimports/releases/tag/v0.3.1
minGoVersion = "1.22"
minTinygoVersion = "0.33.0"
golangCILintVer = "v1.61.0" // https://github.com/golangci/golangci-lint/releases
gosImportsVer = "v0.3.8" // https://github.com/rinchsan/gosimports/releases/tag/v0.3.1
)

var errCommitFormatting = errors.New("files not formatted, please commit formatting changes")

func init() {
for _, check := range []struct {
lang string
minVersion string
}{
{"tinygo", minTinygoVersion},
{"go", minGoVersion},
} {
if err := checkVersion(check.lang, check.minVersion); err != nil {
fmt.Printf("Error: %v\n", err)
os.Exit(1)
}
}
}

// checkVersion checks the minimum version of the specified language is supported.
// Note: While it is likely, there are no guarantees that a newer version of the language will work
func checkVersion(lang string, minVersion string) error {
var compare []string

switch lang {
case "go":
// Version can/cannot include patch version e.g.
// - go version go1.19 darwin/arm64
// - go version go1.19.2 darwin/amd64
goVersionRegex := regexp.MustCompile("go([0-9]+).([0-9]+).?([0-9]+)?")
v, err := sh.Output("go", "version")
if err != nil {
return fmt.Errorf("unexpected go error: %v", err)
}
compare = goVersionRegex.FindStringSubmatch(v)
if len(compare) != 4 {
return fmt.Errorf("unexpected go semver: %q", v)
}
case "tinygo":
tinygoVersionRegex := regexp.MustCompile("tinygo version ([0-9]+).([0-9]+).?([0-9]+)?")
v, err := sh.Output("tinygo", "version")
if err != nil {
return fmt.Errorf("unexpected tinygo error: %v", err)
}
// Assume a dev build is valid.
if strings.Contains(v, "-dev") {
return nil
}
compare = tinygoVersionRegex.FindStringSubmatch(v)
if len(compare) != 4 {
return fmt.Errorf("unexpected tinygo semver: %q", v)
}
default:
return fmt.Errorf("unexpected language: %s", lang)
}

compare = compare[1:]
if compare[2] == "" {
compare[2] = "0"
}

base := strings.SplitN(minVersion, ".", 3)
if len(base) == 2 {
base = append(base, "0")
}
for i := 0; i < 3; i++ {
baseN, _ := strconv.Atoi(base[i])
compareN, _ := strconv.Atoi(compare[i])
if baseN > compareN {
return fmt.Errorf("unexpected %s version, minimum want %q, have %q", lang, minVersion, strings.Join(compare, "."))
}
}
return nil
}

// Format formats code in this repository.
func Format() error {
if err := sh.RunV("go", "mod", "tidy"); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion testing/coreruleset/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/jcchavezs/coraza-http-wasm/testing/coreruleset

go 1.21.0
go 1.22

require (
github.com/bmatcuk/doublestar/v4 v4.6.1
Expand Down

0 comments on commit 2c3c4e7

Please sign in to comment.