Compare commits

...

1 Commits

Author SHA1 Message Date
世界
0ca7d15955
Improve build 2022-08-12 18:51:58 +08:00
6 changed files with 87 additions and 28 deletions

View File

@ -181,18 +181,9 @@ jobs:
key: go-${{ hashFiles('**/go.sum') }} key: go-${{ hashFiles('**/go.sum') }}
- name: Build - name: Build
id: build id: build
run: | run: make
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"
- name: Upload artifact - name: Upload artifact
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v2
with: with:
name: sing-box-${{ matrix.name }}-${{ steps.build.outputs.VERSION }} name: sing-box-${{ matrix.name }}
path: sing-box* path: sing-box*

View File

@ -17,4 +17,4 @@ linters-settings:
- prefix(github.com/sagernet/) - prefix(github.com/sagernet/)
- default - default
staticcheck: staticcheck:
go: '1.18' go: '1.19'

49
Makefile Normal file
View File

@ -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

View File

@ -17,11 +17,37 @@ var commandVersion = &cobra.Command{
Args: cobra.NoArgs, Args: cobra.NoArgs,
} }
func printVersion(cmd *cobra.Command, args []string) { var nameOnly bool
os.Stderr.WriteString(F.ToString("sing-box version ", C.Version, " (", runtime.Version(), ", ", runtime.GOOS, "/", runtime.GOARCH, ", CGO "))
if C.CGO_ENABLED { func init() {
os.Stderr.WriteString("enabled)\n") commandVersion.Flags().BoolVarP(&nameOnly, "name", "n", false, "print version name only")
} else { }
os.Stderr.WriteString("disabled)\n")
} 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)
} }

View File

@ -1,6 +1,6 @@
package constant package constant
var ( var (
Version = "nightly" Version = "20220812"
BuildTime = "unknown" Commit = ""
) )

View File

@ -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" .