move versioning into the version package
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
parent
304959b3f5
commit
eb78661620
@ -5,14 +5,14 @@ before:
|
||||
- go mod download
|
||||
|
||||
builds:
|
||||
-
|
||||
env:
|
||||
- env:
|
||||
- CGO_ENABLED=0
|
||||
main: ./cmd/dagger
|
||||
binary: dagger
|
||||
ldflags:
|
||||
- -s -w
|
||||
- -X go.dagger.io/dagger/cmd/dagger/cmd.version={{.Version}}
|
||||
- -X go.dagger.io/dagger/version.Version={{.Version}}
|
||||
- -X go.dagger.io/dagger/version.Revision={{.ShortCommit}}
|
||||
goos:
|
||||
- linux
|
||||
- windows
|
||||
@ -22,8 +22,7 @@ builds:
|
||||
- arm64
|
||||
|
||||
archives:
|
||||
-
|
||||
name_template: "{{ .ProjectName }}_{{ .Tag }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}"
|
||||
- name_template: "{{ .ProjectName }}_{{ .Tag }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}"
|
||||
replacements:
|
||||
files:
|
||||
- LICENSE
|
||||
@ -33,7 +32,7 @@ archives:
|
||||
format: zip
|
||||
|
||||
checksum:
|
||||
name_template: 'checksums.txt'
|
||||
name_template: "checksums.txt"
|
||||
|
||||
snapshot:
|
||||
name_template: "{{ .Tag }}-next"
|
||||
@ -42,15 +41,14 @@ changelog:
|
||||
sort: asc
|
||||
filters:
|
||||
exclude:
|
||||
- '^docs:'
|
||||
- '^doc:'
|
||||
- '^test:'
|
||||
- '^tests:'
|
||||
- '^Merge pull request'
|
||||
- "^docs:"
|
||||
- "^doc:"
|
||||
- "^test:"
|
||||
- "^tests:"
|
||||
- "^Merge pull request"
|
||||
|
||||
brews:
|
||||
-
|
||||
tap:
|
||||
- tap:
|
||||
owner: dagger
|
||||
name: homebrew-tap
|
||||
commit_author:
|
||||
@ -63,15 +61,13 @@ brews:
|
||||
system "#{bin}/dagger version"
|
||||
|
||||
blobs:
|
||||
-
|
||||
provider: s3
|
||||
- provider: s3
|
||||
region: us-east-1
|
||||
bucket: dagger-io
|
||||
folder: "dagger/releases/{{ .Version }}"
|
||||
|
||||
publishers:
|
||||
-
|
||||
name: publish-version
|
||||
- name: publish-version
|
||||
cmd: sh -c "echo {{ .Version }} | aws s3 cp - s3://dagger-io/dagger/latest_version"
|
||||
env:
|
||||
- PATH={{ .Env.PATH }}
|
||||
|
6
Makefile
6
Makefile
@ -1,13 +1,15 @@
|
||||
GIT_REVISION := $(shell git rev-parse --short HEAD)
|
||||
|
||||
.PHONY: all
|
||||
all: dagger
|
||||
|
||||
.PHONY: dagger
|
||||
dagger:
|
||||
CGO_ENABLED=0 go build -o ./cmd/dagger/ -ldflags '-s -w' ./cmd/dagger/
|
||||
CGO_ENABLED=0 go build -o ./cmd/dagger/ -ldflags '-s -w -X go.dagger.io/dagger/version.Revision=$(GIT_REVISION)' ./cmd/dagger/
|
||||
|
||||
.PHONY: dagger-debug
|
||||
dagger-debug:
|
||||
go build -race -o ./cmd/dagger/dagger-debug ./cmd/dagger/
|
||||
go build -race -o ./cmd/dagger/dagger-debug -ldflags '-X go.dagger.io/dagger/version.Revision=$(GIT_REVISION)' ./cmd/dagger/
|
||||
|
||||
.PHONY: test
|
||||
test:
|
||||
|
@ -1,14 +1,12 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"runtime"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -16,19 +14,16 @@ import (
|
||||
"github.com/mitchellh/go-homedir"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"go.dagger.io/dagger/version"
|
||||
"golang.org/x/term"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultVersion = "devel"
|
||||
versionFile = "~/.config/dagger/version-check"
|
||||
versionURL = "https://releases.dagger.io/dagger/latest_version"
|
||||
versionFile = "~/.config/dagger/version-check"
|
||||
versionURL = "https://releases.dagger.io/dagger/latest_version"
|
||||
)
|
||||
|
||||
// set by goreleaser or other builder using
|
||||
// -ldflags='-X go.dagger.io/dagger/cmd/dagger/cmd.version=<version>'
|
||||
var (
|
||||
version = defaultVersion
|
||||
versionMessage = ""
|
||||
)
|
||||
|
||||
@ -40,12 +35,9 @@ var versionCmd = &cobra.Command{
|
||||
PersistentPostRun: func(*cobra.Command, []string) {},
|
||||
Args: cobra.NoArgs,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if bi, ok := debug.ReadBuildInfo(); ok && version == defaultVersion {
|
||||
// No specific version provided via version
|
||||
version = bi.Main.Version
|
||||
}
|
||||
fmt.Printf("dagger version %v %s/%s\n",
|
||||
version,
|
||||
fmt.Printf("dagger %s (%s) %s/%s\n",
|
||||
version.Version,
|
||||
version.Revision,
|
||||
runtime.GOOS, runtime.GOARCH,
|
||||
)
|
||||
|
||||
@ -99,18 +91,6 @@ func isCheckOutdated(path string) bool {
|
||||
return !time.Now().Before(nextCheck)
|
||||
}
|
||||
|
||||
func getCurrentVersion() (*goVersion.Version, error) {
|
||||
if version != defaultVersion {
|
||||
return goVersion.NewVersion(version)
|
||||
}
|
||||
|
||||
if build, ok := debug.ReadBuildInfo(); ok {
|
||||
// Also return error if version == (devel)
|
||||
return goVersion.NewVersion(build.Main.Version)
|
||||
}
|
||||
return nil, errors.New("could not read dagger version")
|
||||
}
|
||||
|
||||
func getLatestVersion(currentVersion *goVersion.Version) (*goVersion.Version, error) {
|
||||
req, err := http.NewRequest("GET", versionURL, nil)
|
||||
if err != nil {
|
||||
@ -139,7 +119,7 @@ func getLatestVersion(currentVersion *goVersion.Version) (*goVersion.Version, er
|
||||
// Compare the binary version with the latest version online
|
||||
// Return the latest version if current is outdated
|
||||
func isVersionLatest() (string, error) {
|
||||
currentVersion, err := getCurrentVersion()
|
||||
currentVersion, err := goVersion.NewVersion(version.Version)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@ -156,7 +136,7 @@ func isVersionLatest() (string, error) {
|
||||
}
|
||||
|
||||
func checkVersion() {
|
||||
if version == defaultVersion {
|
||||
if version.Version == version.DevelopmentVersion {
|
||||
// running devel version
|
||||
return
|
||||
}
|
||||
|
14
version/version.go
Normal file
14
version/version.go
Normal file
@ -0,0 +1,14 @@
|
||||
package version
|
||||
|
||||
const (
|
||||
DevelopmentVersion = "devel"
|
||||
)
|
||||
|
||||
var (
|
||||
// Version holds the complete version number. Filled in at linking time.
|
||||
Version = DevelopmentVersion
|
||||
|
||||
// Revision is filled with the VCS (e.g. git) revision being used to build
|
||||
// the program at linking time.
|
||||
Revision = ""
|
||||
)
|
Reference in New Issue
Block a user