Files
coder/scripts/release-action/version_test.go
T
Garrett Delfosse b95697a370 ci: rewrite release workflow to be fully GitHub Actions-driven (#25162)
Replace the local interactive release CLI and legacy shell scripts with
a non-interactive Go tool (`scripts/release-action/`) and a rewritten
`release.yaml` workflow. Release managers trigger releases from the
GitHub Actions UI by selecting a branch, picking a release type (`rc`,
`release`, or `create-release-branch`), and optionally providing a
commit SHA.

The Go tool has four subcommands: `calculate-version` (computes next
version from git state), `generate-notes` (release notes from commit log
and PR metadata), `publish` (creates GitHub release with checksums), and
the workflow handles tag creation, branch creation, building, and
downstream publishing.

`scripts/version.sh` fallback now uses `git describe` (nearest ancestor
tag) instead of global latest so dev builds on release branches show the
correct version series.
2026-06-04 14:38:48 -04:00

97 lines
2.0 KiB
Go

package main
import (
"testing"
"github.com/stretchr/testify/require"
)
func Test_parseVersion(t *testing.T) {
t.Parallel()
tests := []struct {
input string
wantErr bool
want version
}{
{
input: "v2.21.0",
want: version{major: 2, minor: 21, patch: 0, rc: -1, original: "v2.21.0"},
},
{
input: "v2.21.0-rc.3",
want: version{major: 2, minor: 21, patch: 0, rc: 3, original: "v2.21.0-rc.3"},
},
{
input: "2.21.0",
want: version{major: 2, minor: 21, patch: 0, rc: -1, original: "v2.21.0"},
},
{
input: "v0.0.0",
want: version{major: 0, minor: 0, patch: 0, rc: -1, original: "v0.0.0"},
},
{
input: "v1.2.3-rc.0",
want: version{major: 1, minor: 2, patch: 3, rc: 0, original: "v1.2.3-rc.0"},
},
{
input: "not-a-version",
wantErr: true,
},
{
input: "",
wantErr: true,
},
{
input: "v1.2",
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.input, func(t *testing.T) {
t.Parallel()
got, err := parseVersion(tt.input)
if tt.wantErr {
require.Error(t, err)
return
}
require.NoError(t, err)
require.Equal(t, tt.want.major, got.major, "major")
require.Equal(t, tt.want.minor, got.minor, "minor")
require.Equal(t, tt.want.patch, got.patch, "patch")
require.Equal(t, tt.want.rc, got.rc, "rc")
require.Equal(t, tt.want.original, got.original, "original")
})
}
}
func Test_versionString(t *testing.T) {
t.Parallel()
tests := []struct {
v version
want string
}{
{version{major: 2, minor: 21, patch: 0, rc: -1}, "v2.21.0"},
{version{major: 2, minor: 21, patch: 0, rc: 3}, "v2.21.0-rc.3"},
{version{major: 1, minor: 0, patch: 5, rc: -1}, "v1.0.5"},
{version{major: 1, minor: 0, patch: 0, rc: 0}, "v1.0.0-rc.0"},
}
for _, tt := range tests {
t.Run(tt.want, func(t *testing.T) {
t.Parallel()
require.Equal(t, tt.want, tt.v.String())
})
}
}
func Test_versionIsRC(t *testing.T) {
t.Parallel()
require.True(t, version{rc: 0}.IsRC())
require.True(t, version{rc: 3}.IsRC())
require.False(t, version{rc: -1}.IsRC())
}