diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 205120ab..2abcff98 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,6 +13,8 @@ jobs: steps: - name: Check out uses: actions/checkout@v2 + with: + fetch-depth: 0 - name: Set up Go uses: actions/setup-go@v1 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..63ede82b --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,26 @@ +name: Release +on: + push: + tags: + - v* +jobs: + goreleaser: + runs-on: ubuntu-latest + defaults: + run: + shell: bash + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: 1.16 + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.ACTIONS_GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 1244af75..43cb1378 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,4 @@ tests/report.xml # node_modules tests/node_modules +dist/ diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 00000000..7f6fde26 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,58 @@ +project_name: dagger + +before: + hooks: + - go mod download + +builds: + - env: + - CGO_ENABLED=0 + main: ./cmd/dagger + binary: dagger + ldflags: + - -s -w + - -X dagger.io/go/cmd/dagger/cmd.version={{.Version}} + goos: + - linux + - windows + - darwin + goarch: + - amd64 + - arm64 + +archives: +- name_template: "{{ .ProjectName }}_{{ .Tag }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}" + replacements: + files: + - LICENSE + - README.md + - doc/**/* + - examples/**/* + format_overrides: + - goos: windows + format: zip + +checksum: + name_template: 'checksums.txt' + +snapshot: + name_template: "{{ .Tag }}-next" + +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' + +brews: +- tap: + owner: dagger + name: homebrew-tap + commit_author: + name: dagger-bot + email: noreply@dagger.io + homepage: "https://github.com/dagger/dagger" + description: "Dagger is a programmable deployment system." + test: | + system "#{bin}/dagger version" diff --git a/cmd/dagger/cmd/root.go b/cmd/dagger/cmd/root.go index 88858f3f..32dea121 100644 --- a/cmd/dagger/cmd/root.go +++ b/cmd/dagger/cmd/root.go @@ -39,6 +39,7 @@ func init() { plan.Cmd, input.Cmd, output.Cmd, + versionCmd, ) if err := viper.BindPFlags(rootCmd.PersistentFlags()); err != nil { diff --git a/cmd/dagger/cmd/version.go b/cmd/dagger/cmd/version.go new file mode 100644 index 00000000..5d85b9e4 --- /dev/null +++ b/cmd/dagger/cmd/version.go @@ -0,0 +1,35 @@ +package cmd + +import ( + "fmt" + "runtime" + "runtime/debug" + + "github.com/spf13/cobra" +) + +const ( + defaultVersion = "devel" +) + +// set by goreleaser or other builder using +// -ldflags='-X dagger.io/go/cmd/dagger/cmd.version=' +var ( + version = defaultVersion +) + +var versionCmd = &cobra.Command{ + Use: "version", + Short: "Print dagger version", + 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, + runtime.GOOS, runtime.GOARCH, + ) + }, +}