From c711405197d3d98b717846ebd3fdbdc7d00c3d59 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Sat, 29 Jun 2019 09:57:41 +0200 Subject: [PATCH] Use goreleaser's fine-grained control for releases --- .gitignore | 1 - .goreleaser.yaml | 49 +++++++-- .travis.yml | 2 +- Makefile | 37 +------ goreleaser/goreleaser.snap.yaml | 40 -------- goreleaser/goreleaser.yaml.tmpl | 115 ---------------------- internal/generate-goreleaser-yaml/main.go | 59 ----------- 7 files changed, 46 insertions(+), 257 deletions(-) delete mode 100644 goreleaser/goreleaser.snap.yaml delete mode 100644 goreleaser/goreleaser.yaml.tmpl delete mode 100644 internal/generate-goreleaser-yaml/main.go diff --git a/.gitignore b/.gitignore index f3835d522a1..166684badf7 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,5 @@ /chezmoi /cmd/cmd-packr.go /dist -/goreleaser/goreleaser.host.yaml /goreleaser/snap.login /packrd \ No newline at end of file diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 8237f078340..0ec44492e2a 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -5,6 +5,15 @@ before: - go mod download builds: +- id: chezmoi-cgo + binary: chezmoi + ldflags: "-s -w -X github.com/twpayne/chezmoi/cmd.VersionStr={{ .Version }} -X github.com/twpayne/chezmoi/cmd.Commit={{ .Commit }} -X github.com/twpayne/chezmoi/cmd.Date={{ .Date }}" + env: + - CGO_ENABLED=1 + goos: + - linux + goarch: + - amd64 - id: chezmoi-nocgo binary: chezmoi env: @@ -15,8 +24,6 @@ builds: - darwin - freebsd - openbsd - # - dragonfly - # - netbsd goarch: - "386" - amd64 @@ -31,8 +38,10 @@ builds: goarch: "386" - goos: linux goarch: amd64 -- id: chezmoi-cgo +- id: chezmoi-cgo-snap binary: chezmoi + flags: + - -tags=snap ldflags: "-s -w -X github.com/twpayne/chezmoi/cmd.VersionStr={{ .Version }} -X github.com/twpayne/chezmoi/cmd.Commit={{ .Commit }} -X github.com/twpayne/chezmoi/cmd.Date={{ .Date }}" env: - CGO_ENABLED=1 @@ -40,9 +49,24 @@ builds: - linux goarch: - amd64 +- id: chezmoi-nocgo-snap + binary: chezmoi + flags: + - -tags=snap + ldflags: "-s -w -X github.com/twpayne/chezmoi/cmd.VersionStr={{ .Version }} -X github.com/twpayne/chezmoi/cmd.Commit={{ .Commit }} -X github.com/twpayne/chezmoi/cmd.Date={{ .Date }}" + env: + - CGO_ENABLED=0 + goos: + - linux + goarch: + - "386" + - arm64 archives: -- files: +- builds: + - chezmoi-cgo + - chezmoi-nocgo + files: - LICENSE - README.md - completions/* @@ -66,7 +90,10 @@ changelog: - "Merge branch" nfpms: -- vendor: "Tom Payne " +- builds: + - chezmoi-cgo + - chezmoi-nocgo + vendor: "Tom Payne " homepage: "https://github.com/twpayne/chezmoi" maintainer: "Tom Payne " description: "Manage your dotfiles across multiple machines, securely." @@ -112,4 +139,14 @@ brews: bash_completion.install "completions/chezmoi-completion.bash" zsh_completion.install "completions/chezmoi.zsh" => "_chezmoi" fish_completion.install "completions/chezmoi.fish" - description: "Manage your dotfiles across multiple machines, securely." \ No newline at end of file + description: "Manage your dotfiles across multiple machines, securely." + +snapcrafts: +- builds: + - chezmoi-cgo-snap + - chezmoi-nocgo-snap + summary: "Manage your dotfiles across multiple machines, securely." + description: "Manage your dotfiles across multiple machines, securely." + publish: true + grade: stable + confinement: classic \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index af809a7a88a..064904490f3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,7 +32,7 @@ sudo: false deploy: - provider: script skip_cleanup: true - script: make release-setup-travis release release-snap + script: make release-setup-travis release on: tags: true condition: "$TRAVIS_OS_NAME = linux" diff --git a/Makefile b/Makefile index 622ebdc4de5..65373264a0d 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ .PHONY: nothing nothing: -all: .goreleaser.yaml completions generate +all: completions generate .PHONY: completions completions: \ @@ -36,18 +36,6 @@ generate: go generate ./... packr2 -.goreleaser.yaml: goreleaser/goreleaser.yaml.tmpl internal/generate-goreleaser-yaml/main.go - go run ./internal/generate-goreleaser-yaml \ - -host-arch amd64 \ - -host-os linux \ - $< > $@ \ - || ( rm -f $@ ; false ) - -goreleaser/goreleaser.host.yaml: goreleaser/goreleaser.yaml.tmpl internal/generate-goreleaser-yaml/main.go - go run ./internal/generate-goreleaser-yaml \ - $< > $@ \ - || ( rm -f $@ ; false ) - .PHONY: html-coverage html-coverage: go tool cover -html=coverage.out @@ -73,17 +61,6 @@ release: --rm-dist \ ${GORELEASER_FLAGS} -.PHONY: release-snap -release-snap: - goreleaser release \ - --config=goreleaser/goreleaser.snap.yaml \ - --rm-dist \ - --skip-publish \ - ${GORELEASER_FLAGS} - for snap in dist/*.snap ; do \ - snapcraft push --release=stable $${snap} ; \ - done - .PHONY: release-setup-travis release-setup-travis: sudo snap install goreleaser --classic @@ -98,18 +75,8 @@ release-setup-travis: --with goreleaser/snap.login .PHONY: test-release -test-release: goreleaser/goreleaser.host.yaml - TRAVIS_BUILD_NUMBER=1 goreleaser release \ - --config goreleaser/goreleaser.host.yaml \ - --rm-dist \ - --skip-publish \ - --snapshot \ - ${GORELEASER_FLAGS} - -.PHONY: test-release-snap -test-release-snap: +test-release: TRAVIS_BUILD_NUMBER=1 goreleaser release \ - --config goreleaser/goreleaser.snap.yaml \ --rm-dist \ --skip-publish \ --snapshot \ diff --git a/goreleaser/goreleaser.snap.yaml b/goreleaser/goreleaser.snap.yaml deleted file mode 100644 index b67b9a704a8..00000000000 --- a/goreleaser/goreleaser.snap.yaml +++ /dev/null @@ -1,40 +0,0 @@ -project_name: chezmoi - -before: - hooks: - - go mod download - -builds: -- id: chezmoi-cgo-snap - binary: chezmoi - flags: - - -tags=snap - ldflags: "-s -w -X github.com/twpayne/chezmoi/cmd.VersionStr={{ .Version }} -X github.com/twpayne/chezmoi/cmd.Commit={{ .Commit }} -X github.com/twpayne/chezmoi/cmd.Date={{ .Date }}" - env: - - CGO_ENABLED=1 - goos: - - linux - goarch: - - amd64 -- id: chezmoi-nocgo-snap - binary: chezmoi - flags: - - -tags=snap - ldflags: "-s -w -X github.com/twpayne/chezmoi/cmd.VersionStr={{ .Version }} -X github.com/twpayne/chezmoi/cmd.Commit={{ .Commit }} -X github.com/twpayne/chezmoi/cmd.Date={{ .Date }}" - env: - - CGO_ENABLED=0 - goos: - - linux - goarch: - - "386" - - arm64 - -snapshot: - name_template: "{{ .Tag }}-next" - -snapcrafts: -- summary: "Manage your dotfiles across multiple machines, securely." - description: "Manage your dotfiles across multiple machines, securely." - publish: true - grade: stable - confinement: classic diff --git a/goreleaser/goreleaser.yaml.tmpl b/goreleaser/goreleaser.yaml.tmpl deleted file mode 100644 index 33b6e134eb6..00000000000 --- a/goreleaser/goreleaser.yaml.tmpl +++ /dev/null @@ -1,115 +0,0 @@ -project_name: chezmoi - -before: - hooks: - - go mod download - -builds: -- id: chezmoi-nocgo - binary: chezmoi - env: - - CGO_ENABLED=0 - ldflags: "-s -w -X github.com/twpayne/chezmoi/cmd.VersionStr={{ .Version }} -X github.com/twpayne/chezmoi/cmd.Commit={{ .Commit }} -X github.com/twpayne/chezmoi/cmd.Date={{ .Date }}" - goos: - - linux - - darwin - - freebsd - - openbsd - # - dragonfly - # - netbsd - goarch: - - "386" - - amd64 - - arm - - arm64 - - ppc64 - - ppc64le - goarm: - - "" - ignore: - - goos: darwin - goarch: "386" - - goos: {{ .HostOS }} - goarch: {{ .HostArch }} -- id: chezmoi-cgo - binary: chezmoi - ldflags: "-s -w -X github.com/twpayne/chezmoi/cmd.VersionStr={{ .Version }} -X github.com/twpayne/chezmoi/cmd.Commit={{ .Commit }} -X github.com/twpayne/chezmoi/cmd.Date={{ .Date }}" - env: - - CGO_ENABLED=1 - goos: - - {{ .HostOS }} - goarch: - - {{ .HostArch }} - -archives: -- files: - - LICENSE - - README.md - - completions/* - - docs/* - replacements: - 386: i386 - -checksum: - name_template: "checksums.txt" - -snapshot: - name_template: "{{ .Tag }}-next" - -changelog: - sort: asc - filters: - exclude: - - "^docs:" - - "^test:" - - "Merge pull request" - - "Merge branch" - -nfpms: -- vendor: "Tom Payne " - homepage: "https://github.com/twpayne/chezmoi" - maintainer: "Tom Payne " - description: "Manage your dotfiles across multiple machines, securely." - license: MIT - formats: - - deb - - rpm - dependencies: - - git - bindir: "/usr/bin" - files: - "completions/chezmoi-completion.bash": "/usr/share/bash-completion/completions/chezmoi" - "completions/chezmoi.fish": "/usr/share/fish/completions/chezmoi.fish" - overrides: - rpm: - name_template: "{{ .ProjectName }}-{{ .Version }}-{{ .Env.TRAVIS_BUILD_NUMBER }}-{{ .Arch }}" - replacements: - amd64: x86_64 - 386: i686 - arm: armhfp - arm64: aarch64 - files: - "completions/chezmoi.zsh": "/usr/share/zsh/functions/_chezmoi" - deb: - name_template: "{{ .ProjectName }}_{{ .Version }}-{{ .Env.TRAVIS_BUILD_NUMBER }}_{{ .Os }}_{{ .Arch }}" - replacements: - 386: i386 - arm: armel - files: - "completions/chezmoi.zsh": "/usr/share/zsh/vendor-completions/_chezmoi" - -brews: -- github: - owner: twpayne - name: homebrew-taps - commit_author: - name: Tom Payne - email: twpayne@gmail.com - folder: Formula - homepage: "https://github.com/twpayne/chezmoi" - install: | - bin.install "chezmoi" - bash_completion.install "completions/chezmoi-completion.bash" - zsh_completion.install "completions/chezmoi.zsh" => "_chezmoi" - fish_completion.install "completions/chezmoi.fish" - description: "Manage your dotfiles across multiple machines, securely." \ No newline at end of file diff --git a/internal/generate-goreleaser-yaml/main.go b/internal/generate-goreleaser-yaml/main.go deleted file mode 100644 index 53c63b33f51..00000000000 --- a/internal/generate-goreleaser-yaml/main.go +++ /dev/null @@ -1,59 +0,0 @@ -package main - -import ( - "flag" - "fmt" - "os" - "runtime" - "text/template" -) - -var ( - hostArch = flag.String("host-arch", runtime.GOARCH, "host architecture") - hostOS = flag.String("host-os", runtime.GOOS, "host OS") - name = flag.String("name", "goreleaser.yaml.tmpl", "template name") -) - -func run() error { - flag.Parse() - tmpl, err := template.ParseFiles(flag.Args()...) - if err != nil { - return err - } - // This is a horrible horrible hack. The template itself generates a YAML - // file where some of the values are they themselves templates. We need to - // pass variables used in these values through unchanged. So, replace every - // variable with the template expression that generates it. Yuk! - return tmpl.ExecuteTemplate(os.Stdout, *name, struct { - HostArch string - HostOS string - Arch string - Commit string - Date string - Env map[string]string - Os string - ProjectName string - Tag string - Version string - }{ - HostArch: *hostArch, - HostOS: *hostOS, - Arch: "{{ .Arch }}", - Commit: "{{ .Commit }}", - Date: "{{ .Date }}", - Env: map[string]string{ - "TRAVIS_BUILD_NUMBER": "{{ .Env.TRAVIS_BUILD_NUMBER }}", - }, - Os: "{{ .Os }}", - ProjectName: "{{ .ProjectName }}", - Tag: "{{ .Tag }}", - Version: "{{ .Version }}", - }) -} - -func main() { - if err := run(); err != nil { - fmt.Fprintln(os.Stderr, err) - os.Exit(1) - } -}