Skip to content

Commit

Permalink
ci: fix Vim master build (#907)
Browse files Browse the repository at this point in the history
The Go version numbers used by the setup-go action do not,
unfortunately, following the versioning scheme used by Go itself. Fix
the version used for the Vim master build.
  • Loading branch information
myitcv committed Jul 14, 2020
1 parent 086297e commit 54eb286
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/vim_master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
go-version: ["1.15beta1"]
go-version: ["1.15.0-beta1"]
runs-on: ${{ matrix.os }}
env:
VIM_FLAVOR: vim
Expand Down
50 changes: 49 additions & 1 deletion internal/cmd/genconfig/genconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"path/filepath"
"regexp"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -102,7 +103,7 @@ func writeMaxVersionsScripts() {
vs.VimCommand = strconv.Quote(testsetup.VimCommand.String())
vs.GvimCommand = strconv.Quote(testsetup.GvimCommand.String())
vs.MaxGoVersion = testsetup.GoVersions[len(testsetup.GoVersions)-1]
vs.MaxRealGoVersion = strings.TrimPrefix(vs.MaxGoVersion, "go")
vs.MaxRealGoVersion = semverGitHubGoVersion(vs.MaxGoVersion)

goVersionsSet := make(map[string]bool)
vimVersionsSet := make(map[string]bool)
Expand Down Expand Up @@ -228,6 +229,53 @@ func writeFileFromTmpl(path string, tmpl string, v interface{}) {
}
}

var (
betaSuffix = regexp.MustCompile(`beta\d+$`)
rcSuffix = regexp.MustCompile(`rc\d+$`)
)

// semverGitHubGoVersion is a temporary hack to deal with the fact that the GitHub
// action setup-go requires a semantic version, despite the fact that Go does
// not follow semver.
//
// More discussion: https://github.com/actions/setup-go/issues/63
//
// This function panics in case we don't see a valid Go version, e.g.
// go1.14beta1rc1
func semverGitHubGoVersion(v string) string {
r := v
beta := betaSuffix.FindString(v)
if beta != "" {
r = strings.TrimSuffix(r, beta)
}
rc := rcSuffix.FindString(r)
if rc != "" {
r = strings.TrimSuffix(r, rc)
}
if beta != "" && rc != "" {
panic(fmt.Errorf("invalid Go version %v: had both beta and rc suffixes", v))
}
if !strings.HasPrefix(r, "go") {
panic(fmt.Errorf("invalid Go version %v: missing go prefix", v))
}
r = strings.TrimPrefix(r, "go")
rps := strings.Split(r, ".")
if len(rps) == 2 {
rps = append(rps, "0")
}
r = strings.Join(rps, ".")
if !semver.IsValid("v" + r) {
panic(fmt.Errorf("failed to build valid version from %v", v))
}
if beta != "" {
r = r + "-" + beta
}
if rc != "" {
r = r + "-" + rc
}
return r
}

const dockerWorkflowYaml = `# Code generated by genconfig. DO NOT EDIT.
on:
push:
Expand Down

0 comments on commit 54eb286

Please sign in to comment.