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
|
- go mod download
|
||||||
|
|
||||||
builds:
|
builds:
|
||||||
-
|
- env:
|
||||||
env:
|
|
||||||
- CGO_ENABLED=0
|
- CGO_ENABLED=0
|
||||||
main: ./cmd/dagger
|
main: ./cmd/dagger
|
||||||
binary: dagger
|
binary: dagger
|
||||||
ldflags:
|
ldflags:
|
||||||
- -s -w
|
- -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:
|
goos:
|
||||||
- linux
|
- linux
|
||||||
- windows
|
- windows
|
||||||
@ -22,8 +22,7 @@ builds:
|
|||||||
- arm64
|
- arm64
|
||||||
|
|
||||||
archives:
|
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:
|
replacements:
|
||||||
files:
|
files:
|
||||||
- LICENSE
|
- LICENSE
|
||||||
@ -33,7 +32,7 @@ archives:
|
|||||||
format: zip
|
format: zip
|
||||||
|
|
||||||
checksum:
|
checksum:
|
||||||
name_template: 'checksums.txt'
|
name_template: "checksums.txt"
|
||||||
|
|
||||||
snapshot:
|
snapshot:
|
||||||
name_template: "{{ .Tag }}-next"
|
name_template: "{{ .Tag }}-next"
|
||||||
@ -42,15 +41,14 @@ changelog:
|
|||||||
sort: asc
|
sort: asc
|
||||||
filters:
|
filters:
|
||||||
exclude:
|
exclude:
|
||||||
- '^docs:'
|
- "^docs:"
|
||||||
- '^doc:'
|
- "^doc:"
|
||||||
- '^test:'
|
- "^test:"
|
||||||
- '^tests:'
|
- "^tests:"
|
||||||
- '^Merge pull request'
|
- "^Merge pull request"
|
||||||
|
|
||||||
brews:
|
brews:
|
||||||
-
|
- tap:
|
||||||
tap:
|
|
||||||
owner: dagger
|
owner: dagger
|
||||||
name: homebrew-tap
|
name: homebrew-tap
|
||||||
commit_author:
|
commit_author:
|
||||||
@ -63,15 +61,13 @@ brews:
|
|||||||
system "#{bin}/dagger version"
|
system "#{bin}/dagger version"
|
||||||
|
|
||||||
blobs:
|
blobs:
|
||||||
-
|
- provider: s3
|
||||||
provider: s3
|
|
||||||
region: us-east-1
|
region: us-east-1
|
||||||
bucket: dagger-io
|
bucket: dagger-io
|
||||||
folder: "dagger/releases/{{ .Version }}"
|
folder: "dagger/releases/{{ .Version }}"
|
||||||
|
|
||||||
publishers:
|
publishers:
|
||||||
-
|
- name: publish-version
|
||||||
name: publish-version
|
|
||||||
cmd: sh -c "echo {{ .Version }} | aws s3 cp - s3://dagger-io/dagger/latest_version"
|
cmd: sh -c "echo {{ .Version }} | aws s3 cp - s3://dagger-io/dagger/latest_version"
|
||||||
env:
|
env:
|
||||||
- PATH={{ .Env.PATH }}
|
- PATH={{ .Env.PATH }}
|
||||||
|
6
Makefile
6
Makefile
@ -1,13 +1,15 @@
|
|||||||
|
GIT_REVISION := $(shell git rev-parse --short HEAD)
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: dagger
|
all: dagger
|
||||||
|
|
||||||
.PHONY: dagger
|
.PHONY: dagger
|
||||||
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
|
.PHONY: dagger-debug
|
||||||
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
|
.PHONY: test
|
||||||
test:
|
test:
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"runtime"
|
"runtime"
|
||||||
"runtime/debug"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -16,19 +14,16 @@ import (
|
|||||||
"github.com/mitchellh/go-homedir"
|
"github.com/mitchellh/go-homedir"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
"go.dagger.io/dagger/version"
|
||||||
"golang.org/x/term"
|
"golang.org/x/term"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
defaultVersion = "devel"
|
versionFile = "~/.config/dagger/version-check"
|
||||||
versionFile = "~/.config/dagger/version-check"
|
versionURL = "https://releases.dagger.io/dagger/latest_version"
|
||||||
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 (
|
var (
|
||||||
version = defaultVersion
|
|
||||||
versionMessage = ""
|
versionMessage = ""
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -40,12 +35,9 @@ var versionCmd = &cobra.Command{
|
|||||||
PersistentPostRun: func(*cobra.Command, []string) {},
|
PersistentPostRun: func(*cobra.Command, []string) {},
|
||||||
Args: cobra.NoArgs,
|
Args: cobra.NoArgs,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
if bi, ok := debug.ReadBuildInfo(); ok && version == defaultVersion {
|
fmt.Printf("dagger %s (%s) %s/%s\n",
|
||||||
// No specific version provided via version
|
version.Version,
|
||||||
version = bi.Main.Version
|
version.Revision,
|
||||||
}
|
|
||||||
fmt.Printf("dagger version %v %s/%s\n",
|
|
||||||
version,
|
|
||||||
runtime.GOOS, runtime.GOARCH,
|
runtime.GOOS, runtime.GOARCH,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -99,18 +91,6 @@ func isCheckOutdated(path string) bool {
|
|||||||
return !time.Now().Before(nextCheck)
|
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) {
|
func getLatestVersion(currentVersion *goVersion.Version) (*goVersion.Version, error) {
|
||||||
req, err := http.NewRequest("GET", versionURL, nil)
|
req, err := http.NewRequest("GET", versionURL, nil)
|
||||||
if err != 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
|
// Compare the binary version with the latest version online
|
||||||
// Return the latest version if current is outdated
|
// Return the latest version if current is outdated
|
||||||
func isVersionLatest() (string, error) {
|
func isVersionLatest() (string, error) {
|
||||||
currentVersion, err := getCurrentVersion()
|
currentVersion, err := goVersion.NewVersion(version.Version)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@ -156,7 +136,7 @@ func isVersionLatest() (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func checkVersion() {
|
func checkVersion() {
|
||||||
if version == defaultVersion {
|
if version.Version == version.DevelopmentVersion {
|
||||||
// running devel version
|
// running devel version
|
||||||
return
|
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