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 return "", err
} }
} }
ts := time.Now().Format(YearMonthDayHourMin) ts := time.Now().Format(yearMonthDayHourMin)
return ioutil.TempDir(parentDir, fmt.Sprintf("buildenv_%s.", ts)) 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+)$`) var moduleVersionRegexp = regexp.MustCompile(`.+/v(\d+)$`)
const ( const (
// YearMonthDayHourMin is the date format // yearMonthDayHourMin is the date format
// used for temporary folder paths. // used for temporary folder paths.
YearMonthDayHourMin = "2006-01-02-1504" 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"
defaultCaddyModulePath = "github.com/caddyserver/caddy" defaultCaddyModulePath = "github.com/caddyserver/caddy"
) )

View file

@ -23,11 +23,17 @@ import (
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"strings"
"time" "time"
) )
func newEnvironment(caddyVersion string, plugins []CaddyPlugin) (*environment, error) { 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 { if err != nil {
return nil, err return nil, err
} }