Skip to content

Commit 8732966

Browse files
committedJun 27, 2024
ci: test against mainline and stable versions
1 parent e6ba29a commit 8732966

File tree

4 files changed

+104
-5
lines changed

4 files changed

+104
-5
lines changed
 

‎.github/workflows/test.yml

+11-3
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,21 @@ jobs:
3838
run: |
3939
go build -v .
4040
41-
- name: Run integration test
41+
- name: Run integration test (mainline)
4242
timeout-minutes: 10
4343
env:
4444
CODER_IMAGE: "ghcr.io/coder/coder"
45-
CODER_VERSION: "latest"
4645
run: |
47-
go test -v ./integration
46+
source <(go run ./scripts/coderversion)
47+
CODER_VERSION="${CODER_MAINLINE_VERSION}" go test -v ./integration
48+
49+
- name: Run integration test (stable)
50+
timeout-minutes: 10
51+
env:
52+
CODER_IMAGE: "ghcr.io/coder/coder"
53+
run: |
54+
source <(go run ./scripts/coderversion)
55+
CODER_VERSION="${CODER_STABLE_VERSION}" go test -v ./integration
4856
4957
# run acceptance tests in a matrix with Terraform core versions
5058
test:

‎go.mod

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,21 @@ toolchain go1.22.3
66

77
require (
88
github.com/docker/docker v26.1.4+incompatible
9+
github.com/google/go-github v17.0.0+incompatible
910
github.com/google/uuid v1.6.0
1011
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
1112
github.com/hashicorp/terraform-plugin-sdk/v2 v2.20.0
13+
github.com/masterminds/semver v1.5.0
1214
github.com/mitchellh/mapstructure v1.5.0
1315
github.com/robfig/cron/v3 v3.0.1
1416
github.com/stretchr/testify v1.9.0
17+
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8
18+
golang.org/x/mod v0.18.0
1519
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
1620
)
1721

1822
require (
23+
github.com/Masterminds/semver v1.5.0 // indirect
1924
github.com/Microsoft/go-winio v0.5.2 // indirect
2025
github.com/agext/levenshtein v1.2.3 // indirect
2126
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
@@ -31,6 +36,7 @@ require (
3136
github.com/gogo/protobuf v1.3.2 // indirect
3237
github.com/golang/protobuf v1.5.4 // indirect
3338
github.com/google/go-cmp v0.6.0 // indirect
39+
github.com/google/go-querystring v1.1.0 // indirect
3440
github.com/hashicorp/errwrap v1.1.0 // indirect
3541
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
3642
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
@@ -76,8 +82,6 @@ require (
7682
go.opentelemetry.io/otel/sdk v1.27.0 // indirect
7783
go.opentelemetry.io/otel/trace v1.27.0 // indirect
7884
golang.org/x/crypto v0.23.0 // indirect
79-
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 // indirect
80-
golang.org/x/mod v0.18.0 // indirect
8185
golang.org/x/net v0.25.0 // indirect
8286
golang.org/x/sys v0.20.0 // indirect
8387
golang.org/x/text v0.15.0 // indirect

‎go.sum

+9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
22
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=
33
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
4+
github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=
5+
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
46
github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA=
57
github.com/Microsoft/go-winio v0.4.16/go.mod h1:XB6nPKklQyQ7GC9LdcBEcBl8PF76WugXOPRXwdLnMv0=
68
github.com/Microsoft/go-winio v0.5.2 h1:a9IhgEQBCUEk6QCdml9CiJGhAws+YwffDHEMp1VMrpA=
@@ -70,10 +72,15 @@ github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek
7072
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
7173
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
7274
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
75+
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
7376
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
7477
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
7578
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
7679
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
80+
github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY=
81+
github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ=
82+
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
83+
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
7784
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
7885
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
7986
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1YCS1PXdKYWi8FsN0=
@@ -147,6 +154,8 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
147154
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k=
148155
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
149156
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
157+
github.com/masterminds/semver v1.5.0 h1:hTxJTTY7tjvnWMrl08O6u3G6BLlKVwxSz01lVac9P8U=
158+
github.com/masterminds/semver v1.5.0/go.mod h1:s7KNT9fnd7edGzwwP7RBX4H0v/CYd5qdOLfkL1V75yg=
150159
github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA=
151160
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
152161
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=

‎scripts/coderversion/main.go

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"os"
7+
8+
"github.com/google/go-github/github"
9+
"github.com/masterminds/semver"
10+
)
11+
12+
func main() {
13+
client := github.NewClient(nil)
14+
// We consider the latest release as 'mainline'
15+
ctx, cancel := context.WithCancel(context.Background())
16+
defer cancel()
17+
latest, _, err := client.Repositories.GetLatestRelease(ctx, "coder", "coder")
18+
if err != nil {
19+
fatal("get mainline release: %w\n", err)
20+
}
21+
22+
if latest.TagName == nil {
23+
fatal("latest release is not tagged", err)
24+
}
25+
26+
mainlineVer, err := semver.NewVersion(*latest.TagName)
27+
if err != nil {
28+
fatal("invalid mainline tag name: %w\n", err)
29+
}
30+
mainline := fmt.Sprintf("v%d.%d.%d", mainlineVer.Major(), mainlineVer.Minor(), mainlineVer.Patch())
31+
32+
expectedStableMinor := mainlineVer.Minor() - 1
33+
if expectedStableMinor < 0 {
34+
fatal("unexpected minor version 0")
35+
}
36+
37+
previousReleases, _, err := client.Repositories.ListReleases(ctx, "coder", "coder", &github.ListOptions{
38+
Page: 0,
39+
PerPage: 100,
40+
})
41+
if err != nil {
42+
fatal("list previous releases: %w\n", err)
43+
}
44+
45+
var stable string
46+
for _, rel := range previousReleases {
47+
if rel.TagName == nil {
48+
debug("ignoring untagged version %s\n", rel.String())
49+
continue
50+
}
51+
52+
ver, err := semver.NewVersion(*rel.TagName)
53+
if err != nil {
54+
debug("skipping invalid version %s\n", *rel.TagName)
55+
}
56+
57+
// Assuming that the first one we find with minor-1 is what we want
58+
if ver.Minor() == expectedStableMinor {
59+
debug("found stable version %s\n", *rel.TagName)
60+
stable = fmt.Sprintf("v%d.%d.%d", ver.Major(), ver.Minor(), ver.Patch())
61+
break
62+
}
63+
64+
}
65+
_, _ = fmt.Fprintf(os.Stdout, "CODER_MAINLINE_VERSION=%q\n", mainline)
66+
_, _ = fmt.Fprintf(os.Stdout, "CODER_STABLE_VERSION=%q\n", stable)
67+
}
68+
69+
func debug(format string, args ...any) {
70+
if _, ok := os.LookupEnv("VERBOSE"); ok {
71+
_, _ = fmt.Fprintf(os.Stderr, format, args...)
72+
}
73+
}
74+
75+
func fatal(format string, args ...any) {
76+
_, _ = fmt.Fprintf(os.Stderr, format, args...)
77+
os.Exit(1)
78+
}

0 commit comments

Comments
 (0)