Skip to content

Commit

Permalink
添加release功能
Browse files Browse the repository at this point in the history
  • Loading branch information
jianyun8023 committed Feb 24, 2023
1 parent 35ff440 commit b36e640
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 4 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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 }}
59 changes: 59 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -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"
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}

Expand All @@ -24,5 +24,5 @@ func Execute() {
func init() {
rootCmd.AddCommand(clnameCmd)
rootCmd.AddCommand(renameCmd)
rootCmd.SetVersionTemplate("v0.0.1")
rootCmd.AddCommand(versionCmd)
}
29 changes: 29 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -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)
},
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/jianyun8023/bookImporter
module github.com/jianyun8023/bookimporter

go 1.18

Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package main

import "github.com/jianyun8023/bookImporter/cmd"
import "github.com/jianyun8023/bookimporter/cmd"

func main() {
cmd.Execute()
Expand Down

0 comments on commit b36e640

Please sign in to comment.