diff --git a/.github/workflows/gorelease.yml b/.github/workflows/gorelease.yml new file mode 100644 index 0000000..f15cda3 --- /dev/null +++ b/.github/workflows/gorelease.yml @@ -0,0 +1,51 @@ +name: goreleaser + +on: + push: + tags: + - 'v*.*.*' + workflow_dispatch: + +jobs: + goreleaser: + runs-on: ubuntu-20.04 + steps: + - + name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + token: ${{secrets.TOKEN}} + submodules: recursive + - + name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: 1.17 + - + name: Install upx + run: sudo apt install upx -y + continue-on-error: true + - + name: Run GoReleaser + uses: goreleaser/goreleaser-action@v4 + with: + distribution: goreleaser + version: latest + args: release --rm-dist --skip-validate + env: + GITHUB_TOKEN: ${{ secrets.TOKEN }} + GOPATH: "/home/runner/go" + + - name: upx + run: upx dist/gogo* + continue-on-error: true + + - name: Upload assets + uses: actions/upload-artifact@v3 + with: + name: gogo_archive + path: | + dist/gogo* + tools/* + README.md diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..0252e78 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "templates"] + path = templates + url = https://github.com/chainreactors/gogo-templates diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..346f366 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,58 @@ +project_name: spray + +before: + hooks: + - go mod tidy + - go get sigs.k8s.io/yaml + - go generate + +builds: + - + main: . + binary: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}" + goos: + - windows + - linux + - darwin + goarch: + - amd64 + - "386" + - arm64 + ignore: + - goos: windows + goarch: arm64 + - goos: darwin + goarch: "386" + ldflags: "-s -w -X 'github.com/chainreactors/spray/cmd.ver=={{ .Tag }}'" + flags: + - -trimpath + - -tags=forceposix + asmflags: + - all=-trimpath={{.Env.GOPATH}} + gcflags: + - all=-trimpath={{.Env.GOPATH}} + no_unique_dist_dir: true + +archives: + - + name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}" + format: binary + replacements: + amd64_v1: amd64 + +checksum: + name_template: "{{ .ProjectName }}_checksums.txt" + +changelog: + sort: desc + filters: + exclude: + - '^MERGE' + - "{{ .Tag }}" + - "^docs" + +release: + github: + owner: chainreactors + name: spray + draft: true diff --git a/cmd/cmd.go b/cmd/cmd.go index b29b86e..dc07a80 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -17,6 +17,8 @@ import ( "time" ) +var ver = "" + func Spray() { var option internal.Option parser := flags.NewParser(&option, flags.Default) @@ -49,6 +51,11 @@ func Spray() { return } + if option.Version { + fmt.Println(ver) + return + } + if option.Format != "" { internal.Format(option.Format, !option.NoColor) os.Exit(0) diff --git a/internal/option.go b/internal/option.go index c79e559..d4da272 100644 --- a/internal/option.go +++ b/internal/option.go @@ -124,6 +124,7 @@ type MiscOptions struct { PoolSize int `short:"P" long:"pool" default:"5" description:"Int, Pool size"` Threads int `short:"t" long:"thread" default:"20" description:"Int, number of threads per pool"` Debug bool `long:"debug" description:"Bool, output debug info"` + Version bool `short:"v" long:"version" description:"Bool, show version"` Quiet bool `short:"q" long:"quiet" description:"Bool, Quiet"` NoColor bool `long:"no-color" description:"Bool, no color"` NoBar bool `long:"no-bar" description:"Bool, No progress bar"` diff --git a/templates b/templates new file mode 160000 index 0000000..241a707 --- /dev/null +++ b/templates @@ -0,0 +1 @@ +Subproject commit 241a707ce2a8d32b8bc96ebb5a06bcfdecb54b24