Assume Caddy v2 if no semantic version is available

Useful if providing just a commit SHA
This commit is contained in:
Matthew Holt 2020-03-21 16:27:26 -06:00
parent 01dba9ce94
commit 362c34597d
No known key found for this signature in database
GPG key ID: 2A349DD577D586A5
2 changed files with 10 additions and 11 deletions

View file

@ -106,7 +106,7 @@ func newTempFolder() (string, error) {
return "", err
}
}
ts := time.Now().Format(YearMonthDayHourMin)
ts := time.Now().Format(yearMonthDayHourMin)
return ioutil.TempDir(parentDir, fmt.Sprintf("buildenv_%s.", ts))
}
@ -148,16 +148,9 @@ func versionedModulePath(modulePath, moduleVersion string) (string, error) {
var moduleVersionRegexp = regexp.MustCompile(`.+/v(\d+)$`)
const (
// YearMonthDayHourMin is the date format
// yearMonthDayHourMin is the date format
// used for temporary folder paths.
YearMonthDayHourMin = "2006-01-02-1504"
// // ParallelBuildOps is how many build operations
// // to perform in parallel (`go build -p` value)
// ParallelBuildOps = 4
// CaddyRepo is the repository path of the Caddy package.
CaddyRepo = "https://github.com/caddyserver/caddy.git"
yearMonthDayHourMin = "2006-01-02-1504"
defaultCaddyModulePath = "github.com/caddyserver/caddy"
)

View file

@ -23,11 +23,17 @@ import (
"os"
"os/exec"
"path/filepath"
"strings"
"time"
)
func newEnvironment(caddyVersion string, plugins []CaddyPlugin) (*environment, error) {
caddyModulePath, err := versionedModulePath(defaultCaddyModulePath, caddyVersion)
// assume v2 if no semantic version is provided
caddyModulePath := defaultCaddyModulePath
if !strings.HasPrefix(caddyVersion, "v") || !strings.Contains(caddyVersion, ".") {
caddyModulePath += "/v2"
}
caddyModulePath, err := versionedModulePath(caddyModulePath, caddyVersion)
if err != nil {
return nil, err
}