Skip to content

Commit b25467a

Browse files
authored
chore: automatically bare-metal test the 'gonext' RC (#138)
Adds the necessary to automatically test "gonext" release candidates as soon as they are available.
1 parent 3454e6c commit b25467a

File tree

4 files changed

+105
-2
lines changed

4 files changed

+105
-2
lines changed

.github/workflows/_test_bare_metal.yml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,33 @@ on:
33
workflow_call: # This is called by test.yml
44

55
jobs:
6+
go-versions-matrix:
7+
name: Determine Go Versions to test
8+
runs-on: ubuntu-latest
9+
outputs:
10+
json: ${{ steps.matrix.outputs.json }}
11+
steps:
12+
- name: Checkout Code
13+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
14+
- name: Setup Go
15+
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
16+
with:
17+
go-version: stable
18+
cache: true
19+
cache-dependency-path: '**/go.mod'
20+
- name: Compute Matrix
21+
id: matrix
22+
run: |-
23+
echo -n "json=" >> "${GITHUB_OUTPUT}"
24+
go -C _tools/golang-versions-matrix run . >> "${GITHUB_OUTPUT}"
25+
626
test:
27+
needs: go-versions-matrix
728
strategy:
829
fail-fast: false
930
matrix:
1031
runs-on: [ macos-15, macos-14, macos-13, ubuntu-24.04, ubuntu-22.04, windows-latest, arm-4core-linux ]
11-
go-version: [ stable, oldstable ]
32+
go-version: ${{ fromJson(needs.go-versions-matrix.outputs.json) }}
1233
include:
1334
# Test with DD_APPSEC_WAF_LOG_LEVEL (only latest go version)
1435
- go-version: oldstable
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/DataDog/go-libddwaf/_tools/golang-versions-matrix
2+
3+
go 1.23.0
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"log"
6+
"os"
7+
"os/exec"
8+
"regexp"
9+
"slices"
10+
)
11+
12+
func main() {
13+
log.Println("Listing all available Go versions using `go list -m -versions go`...")
14+
cmd := exec.Command("go", "list", "-m", "-versions", "-json=Versions", "go")
15+
cmd.Env = append(os.Environ(), "GOPROXY=https://proxy.golang.org")
16+
out, err := cmd.Output()
17+
if err != nil {
18+
log.Fatalln(err)
19+
}
20+
21+
log.Println("Parsing output of `go list -m -versions go`...")
22+
var module struct {
23+
Versions []string `json:"Versions"`
24+
}
25+
if err := json.Unmarshal(out, &module); err != nil {
26+
if err, ok := err.(*exec.ExitError); ok {
27+
log.Println("STDERR:", string(err.Stderr))
28+
}
29+
log.Fatalln(err)
30+
}
31+
32+
if len(module.Versions) == 0 {
33+
log.Fatalln("No versions found!")
34+
}
35+
36+
// Versions are returned sorted in ascending SemVer order.
37+
slices.Reverse(module.Versions)
38+
39+
log.Println("Looking for a release candidate version...")
40+
goVersions := make([]string, 2, 3)
41+
goVersions[0] = "oldstable"
42+
goVersions[1] = "stable"
43+
44+
// Versions are represented in a form that isn't quite regular SemVer.
45+
versionRe := regexp.MustCompile(`^(1\.\d+)(\.\d+)?(?:(beta|rc)(\d+))?$`)
46+
for _, v := range module.Versions {
47+
parts := versionRe.FindStringSubmatch(v)
48+
if parts == nil {
49+
log.Fatalln("Encountered unsupported version string:", v)
50+
}
51+
major, minor, pre, serial := parts[1], parts[2], parts[3], parts[4]
52+
if pre == "" {
53+
// Not a pre-release version, there is no "next" release available.
54+
log.Println("No relevant release candidate version found!")
55+
break
56+
}
57+
if pre != "rc" {
58+
// Not a release candidate; we don't test against those.
59+
continue
60+
}
61+
// †he minor is omitted when it's ".0"; but actions/setup-go needs it.
62+
if minor == "" {
63+
minor = ".0"
64+
}
65+
rcVersion := major + minor + "-" + pre + "." + serial
66+
log.Println("Found release candidate version:", rcVersion)
67+
goVersions = append(goVersions, rcVersion)
68+
// We have what we came here for, we can break out of the loop now.
69+
break
70+
}
71+
72+
log.Println("Encoding output as a JSON array...")
73+
enc := json.NewEncoder(os.Stdout)
74+
if err := enc.Encode(goVersions); err != nil {
75+
log.Fatalln(err)
76+
}
77+
78+
log.Println("Done!")
79+
}

diagnostics_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// This product includes software developed at Datadog (https://www.datadoghq.com/).
44
// Copyright 2016-present Datadog, Inc.
55

6-
//go:build (amd64 || arm64) && (linux || darwin) && !go1.25 && !datadog.no_waf && (cgo || appsec)
6+
//go:build (amd64 || arm64) && (linux || darwin) && !go1.26 && !datadog.no_waf && (cgo || appsec)
77

88
package libddwaf
99

0 commit comments

Comments
 (0)