From b36e640ee6fc3c3626e3bd74c3aae322d2efc426 Mon Sep 17 00:00:00 2001 From: Jianyun Date: Fri, 24 Feb 2023 15:04:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0release=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 28 +++++++++++++++++ .goreleaser.yml | 59 +++++++++++++++++++++++++++++++++++ cmd/root.go | 4 +-- cmd/version.go | 29 +++++++++++++++++ go.mod | 2 +- main.go | 2 +- 6 files changed, 120 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 .goreleaser.yml create mode 100644 cmd/version.go diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..c3e64a5 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,28 @@ +name: release + +on: + push: + tags: + - '*' + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: '1.19' + check-latest: true + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v3 + with: + distribution: goreleaser + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..17dceb1 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,59 @@ +project_name: bookimport + +before: + hooks: + - go mod tidy + +builds: + - id: bookimport + binary: bookimport + gcflags: + - all=-l -B + ldflags: + - -s -w + - -X github.com/jianyun8023/bookimport/cmd.gitVersion={{ .Version }} + - -X github.com/jianyun8023/bookimport/cmd.gitCommit={{ .Commit }} + - -X github.com/jianyun8023/bookimport/cmd.buildDate={{ .Date }} + env: + - CGO_ENABLED=0 + goos: + - linux + - windows + - darwin + goarch: + - "386" + - amd64 + - arm64 + ignore: + - goos: darwin + goarch: "386" + - goos: windows + goarch: arm64 + +checksum: + name_template: 'checksums.txt' + +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' + - '^web:' + - '^build:' + +archives: + - id: bookimport + builds: + - bookimport + format: tar.gz + wrap_in_directory: "true" + format_overrides: + - goos: windows + format: zip + +release: + draft: true + +snapshot: + name_template: "{{ incminor .Version }}-next" \ No newline at end of file diff --git a/cmd/root.go b/cmd/root.go index 72e9c85..83a76be 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -8,7 +8,7 @@ import ( // rootCmd represents the base command when called without any subcommands var rootCmd = &cobra.Command{ - Use: "bookImporter", + Use: "bookimporter", Short: "Import books into your library", } @@ -24,5 +24,5 @@ func Execute() { func init() { rootCmd.AddCommand(clnameCmd) rootCmd.AddCommand(renameCmd) - rootCmd.SetVersionTemplate("v0.0.1") + rootCmd.AddCommand(versionCmd) } diff --git a/cmd/version.go b/cmd/version.go new file mode 100644 index 0000000..9db7778 --- /dev/null +++ b/cmd/version.go @@ -0,0 +1,29 @@ +package cmd + +import ( + "fmt" + "github.com/spf13/cobra" + "runtime" +) + +var ( + gitVersion = "" + gitCommit = "" // sha1 from git, output of $(git rev-parse HEAD) + buildDate = "" // build date in ISO8601 format, output of $(date -u +'%Y-%m-%dT%H:%M:%SZ') + goVersion = runtime.Version() + platform = fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH) +) + +// versionCmd represents the version command. +var versionCmd = &cobra.Command{ + Use: "version", + Short: "Return the bookimporter version info", + Run: func(cmd *cobra.Command, args []string) { + fmt.Println("bookimporter version info") + fmt.Printf(" - Version: %v\n", gitVersion) + fmt.Printf(" - Commit: %v\n", gitCommit) + fmt.Printf(" - Build Date: %v\n", buildDate) + fmt.Printf(" - Go Version: %v\n", goVersion) + fmt.Printf(" - Platform: %s\n", platform) + }, +} diff --git a/go.mod b/go.mod index b7d7eb1..ecb1c93 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/jianyun8023/bookImporter +module github.com/jianyun8023/bookimporter go 1.18 diff --git a/main.go b/main.go index 82618a0..edfdc82 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,6 @@ package main -import "github.com/jianyun8023/bookImporter/cmd" +import "github.com/jianyun8023/bookimporter/cmd" func main() { cmd.Execute()