Skip to content

Commit

Permalink
Assume Caddy v2 if no semantic version is available
Browse files Browse the repository at this point in the history
Useful if providing just a commit SHA
  • Loading branch information
mholt committed Mar 21, 2020
1 parent 01dba9c commit 362c345
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
13 changes: 3 additions & 10 deletions builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down Expand Up @@ -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"
)
8 changes: 7 additions & 1 deletion environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 362c345

Please sign in to comment.