diff --git a/.github/workflows/debug.yml b/.github/workflows/debug.yml index 7147a8d2..2071776b 100644 --- a/.github/workflows/debug.yml +++ b/.github/workflows/debug.yml @@ -181,18 +181,9 @@ jobs: key: go-${{ hashFiles('**/go.sum') }} - name: Build id: build - run: | - VERSION="$(date +%Y%m%d).$(git rev-parse --short HEAD)" - BUILDTIME="$(LANG=en_US.UTF-8 date -u)" - - go build -v -trimpath -ldflags '\ - -X "github.com/sagernet/sing-box/constant.Version=$VERSION" \ - -X "github.com/sagernet/sing-box/constant.BuildTime=$BUILDTIME" \ - -s -w -buildid=' ./cmd/sing-box - - echo "::set-output name=VERSION::$VERSION" + run: make - name: Upload artifact uses: actions/upload-artifact@v2 with: - name: sing-box-${{ matrix.name }}-${{ steps.build.outputs.VERSION }} + name: sing-box-${{ matrix.name }} path: sing-box* \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml index 012d08a1..88628eca 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -17,4 +17,4 @@ linters-settings: - prefix(github.com/sagernet/) - default staticcheck: - go: '1.18' + go: '1.19' diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..3dab7f57 --- /dev/null +++ b/Makefile @@ -0,0 +1,49 @@ +NAME=sing-box +COMMIT=$(shell git rev-parse --short HEAD) +PARAMS=-trimpath -tags '$(TAGS)' -ldflags \ + '-X "github.com/sagernet/sing-box/constant.Commit=$(COMMIT)" \ + -w -s -buildid=' +MAIN=./cmd/sing-box + +.PHONY: test + +build: + go build $(PARAMS) $(MAIN) + +action_version: build + echo "::set-output name=VERSION::`./sing-box version -n`" + +install: + go install $(PARAMS) $(MAIN) + +fmt_install: + go install -v mvdan.cc/gofumpt@latest + go install -v github.com/daixiang0/gci@v0.4.0 + +fmt: + gofumpt -l -w . + gofmt -s -w . + gci write -s "standard,prefix(github.com/sagernet/),default" . + +lint_install: + go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest + +lint: + GOOS=linux golangci-lint run ./... + GOOS=windows golangci-lint run ./... + GOOS=darwin golangci-lint run ./... + GOOS=freebsd golangci-lint run ./... + +test: + go test -v . && \ + pushd test && \ + go test -v . && \ + popd + +clean: + rm -f $(shell go env GOPATH)/sing-box + +update: + git fetch + git reset FETCH_HEAD --hard + git clean -fdx \ No newline at end of file diff --git a/cmd/sing-box/cmd_version.go b/cmd/sing-box/cmd_version.go index 6327d814..e1ecc381 100644 --- a/cmd/sing-box/cmd_version.go +++ b/cmd/sing-box/cmd_version.go @@ -17,11 +17,37 @@ var commandVersion = &cobra.Command{ Args: cobra.NoArgs, } -func printVersion(cmd *cobra.Command, args []string) { - os.Stderr.WriteString(F.ToString("sing-box version ", C.Version, " (", runtime.Version(), ", ", runtime.GOOS, "/", runtime.GOARCH, ", CGO ")) - if C.CGO_ENABLED { - os.Stderr.WriteString("enabled)\n") - } else { - os.Stderr.WriteString("disabled)\n") - } +var nameOnly bool + +func init() { + commandVersion.Flags().BoolVarP(&nameOnly, "name", "n", false, "print version name only") +} + +func printVersion(cmd *cobra.Command, args []string) { + var version string + if !nameOnly { + version = "sing-box " + } + version += F.ToString(C.Version) + if C.Commit != "" { + version += "." + C.Commit + } + if !nameOnly { + version += " (" + version += runtime.Version() + version += ", " + version += runtime.GOOS + version += ", " + version += runtime.GOARCH + version += ", " + version += "CGO " + if C.CGO_ENABLED { + version += "enabled" + } else { + version += "disabled" + } + version += ")" + } + version += "\n" + os.Stdout.WriteString(version) } diff --git a/constant/version.go b/constant/version.go index 037699f4..e2612c6f 100644 --- a/constant/version.go +++ b/constant/version.go @@ -1,6 +1,6 @@ package constant var ( - Version = "nightly" - BuildTime = "unknown" + Version = "20220812" + Commit = "" ) diff --git a/format.go b/format.go deleted file mode 100644 index 7b30b9ac..00000000 --- a/format.go +++ /dev/null @@ -1,7 +0,0 @@ -package box - -//go:generate go install -v mvdan.cc/gofumpt@latest -//go:generate go install -v github.com/daixiang0/gci@v0.4.0 -//go:generate gofumpt -l -w . -//go:generate gofmt -s -w . -//go:generate gci write -s "standard,prefix(github.com/sagernet/),default" .