Skip to content

Commit 555d802

Browse files
authored
refine build and update misc (#26)
* update go-deps and go-sdk * use github-action
1 parent 88c898f commit 555d802

File tree

140 files changed

+898
-16698
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

140 files changed

+898
-16698
lines changed

.github/workflows/build.yaml

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: Build
2+
3+
"on":
4+
"push":
5+
"tags":
6+
- "v*"
7+
"branches":
8+
- "*"
9+
"pull_request":
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
env:
15+
GO111MODULE: "on"
16+
steps:
17+
- uses: actions/checkout@master
18+
19+
- uses: actions/setup-go@v2
20+
with:
21+
go-version: 1.17.6
22+
23+
- name: Prepare environment
24+
run: |-
25+
RELEASE_VERSION="${GITHUB_REF##*/}"
26+
if [[ "${RELEASE_VERSION}" != v* ]]; then RELEASE_VERSION='dev'; fi
27+
echo "RELEASE_VERSION=\"${RELEASE_VERSION}@${GITHUB_SHA:0:10}\"" | tee -a $GITHUB_ENV
28+
go mod vendor
29+
30+
# Win
31+
- run: GOOS=windows GOARCH=386 VERSION=${RELEASE_VERSION} make release
32+
- run: GOOS=windows GOARCH=amd64 VERSION=${RELEASE_VERSION} make release
33+
- run: GOOS=windows GOARCH=arm64 VERSION=${RELEASE_VERSION} make release
34+
35+
# MacOS
36+
- run: GOOS=darwin GOARCH=amd64 VERSION=${RELEASE_VERSION} make release
37+
- run: GOOS=darwin GOARCH=arm64 VERSION=${RELEASE_VERSION} make release
38+
39+
# Linux X86/AMD64
40+
- run: GOOS=linux GOARCH=386 VERSION=${RELEASE_VERSION} make release
41+
- run: GOOS=linux GOARCH=amd64 VERSION=${RELEASE_VERSION} make release
42+
43+
# Linux ARM
44+
- run: GOOS=linux GOARCH=arm GOARM=6 VERSION=${RELEASE_VERSION} make release
45+
- run: GOOS=linux GOARCH=arm64 VERSION=${RELEASE_VERSION} make release
46+
47+
# Linux MIPS/MIPSLE
48+
- run: GOOS=linux GOARCH=mips GOMIPS=softfloat VERSION=${RELEASE_VERSION} make release
49+
- run: GOOS=linux GOARCH=mipsle GOMIPS=softfloat VERSION=${RELEASE_VERSION} make release
50+
51+
# FreeBSD X86
52+
- run: GOOS=freebsd GOARCH=386 VERSION=${RELEASE_VERSION} make release
53+
- run: GOOS=freebsd GOARCH=amd64 VERSION=${RELEASE_VERSION} make release
54+
55+
# FreeBSD ARM/ARM64
56+
- run: GOOS=freebsd GOARCH=arm GOARM=6 VERSION=${RELEASE_VERSION} make release
57+
- run: GOOS=freebsd GOARCH=arm64 VERSION=${RELEASE_VERSION} make release
58+
59+
- run: ls -l build/tcping-*
60+
61+
- name: Create release
62+
if: startsWith(github.ref, 'refs/tags/v')
63+
id: create_release
64+
uses: actions/create-release@v1
65+
env:
66+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
67+
with:
68+
tag_name: ${{ github.ref }}
69+
release_name: Release ${{ github.ref }}
70+
draft: false
71+
prerelease: false
72+
73+
- name: Upload
74+
if: startsWith(github.ref, 'refs/tags/v')
75+
uses: xresloader/upload-to-github-release@v1
76+
env:
77+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
78+
with:
79+
file: "build/tcping-*.tar.gz;build/tcping-*.zip"
80+
tags: true
81+
draft: false

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,9 @@
1616
dist
1717
*.tar.gz
1818
.idea/
19+
20+
vendor/
21+
build/
22+
23+
tcping
24+
tcping.exe

.travis.yml

-14
This file was deleted.

Makefile

+37-26
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,43 @@
1-
.SILENT :
2-
.PHONY : tcping clean fmt
1+
NAME=tcping
2+
BASE_BUILDDIR=build
3+
BUILDNAME=$(GOOS)-$(GOARCH)$(GOARM)
4+
BUILDDIR=$(BASE_BUILDDIR)/$(BUILDNAME)
5+
VERSION?=dev
36

4-
TAG:=`git describe --abbrev=0 --tags`
5-
GITCOMMIT:=`git rev-parse HEAD`
6-
LDFLAGS:=-X main.version=$(TAG) -X main.gitCommit=$(GITCOMMIT)
7+
ifeq ($(GOOS),windows)
8+
ext=.exe
9+
archiveCmd=zip -9 -r $(NAME)-$(BUILDNAME)-$(VERSION).zip $(BUILDNAME)
10+
else
11+
ext=
12+
archiveCmd=tar czpvf $(NAME)-$(BUILDNAME)-$(VERSION).tar.gz $(BUILDNAME)
13+
endif
714

8-
all: tcping
15+
.PHONY: default
16+
default: build
917

10-
tcping:
11-
echo "Building tcping"
12-
go install -ldflags "$(LDFLAGS)"
18+
build: clean test
19+
go build -mod=vendor
1320

14-
dist-clean:
15-
rm -rf dist
16-
rm -f tcping-*.tar.gz
21+
release: check-env-release
22+
mkdir -p $(BUILDDIR)
23+
cp LICENSE $(BUILDDIR)/
24+
cp README.md $(BUILDDIR)/
25+
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build -mod=vendor -ldflags "-s -w -X main.Version=$(VERSION)" -o $(BUILDDIR)/$(NAME)$(ext)
26+
cd $(BASE_BUILDDIR) ; $(archiveCmd)
1727

18-
dist: dist-clean
19-
mkdir -p dist/alpine-linux/amd64 && GOOS=linux GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -a -tags netgo -installsuffix netgo -o dist/alpine-linux/amd64/tcping
20-
mkdir -p dist/linux/amd64 && GOOS=linux GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o dist/linux/amd64/tcping
21-
mkdir -p dist/linux/armel && GOOS=linux GOARCH=arm GOARM=5 go build -ldflags "$(LDFLAGS)" -o dist/linux/armel/tcping
22-
mkdir -p dist/linux/armhf && GOOS=linux GOARCH=arm GOARM=6 go build -ldflags "$(LDFLAGS)" -o dist/linux/armhf/tcping
23-
mkdir -p dist/darwin/amd64 && GOOS=darwin GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o dist/darwin/amd64/tcping
24-
mkdir -p dist/windows/amd64 && GOOS=windows GOARCH=amd64 GOARM=6 go build -ldflags "$(LDFLAGS)" -o dist/windows/amd64/tcping.exe
28+
test:
29+
go test -race -v -bench=. ./...
2530

26-
release: dist
27-
tar -cvzf tcping-alpine-linux-amd64-$(TAG).tar.gz -C dist/alpine-linux/amd64 tcping
28-
tar -cvzf tcping-linux-amd64-$(TAG).tar.gz -C dist/linux/amd64 tcping
29-
tar -cvzf tcping-linux-armel-$(TAG).tar.gz -C dist/linux/armel tcping
30-
tar -cvzf tcping-linux-armhf-$(TAG).tar.gz -C dist/linux/armhf tcping
31-
tar -cvzf tcping-darwin-amd64-$(TAG).tar.gz -C dist/darwin/amd64 tcping
32-
tar -cvzf tcping-windows-amd64-$(TAG).tar.gz -C dist/windows/amd64 tcping.exe
31+
clean:
32+
go clean
33+
rm -rf $(BASE_BUILDDIR)
34+
35+
check-env-release:
36+
@ if [ "$(GOOS)" = "" ]; then \
37+
echo "Environment variable GOOS not set"; \
38+
exit 1; \
39+
fi
40+
@ if [ "$(GOARCH)" = "" ]; then \
41+
echo "Environment variable GOOS not set"; \
42+
exit 1; \
43+
fi

README.md

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
1-
[![Build Status](https://travis-ci.org/cloverstd/tcping.svg?branch=master)](https://travis-ci.org/cloverstd/tcping)
2-
31
# tcping
42

53
tcping is like [tcping.exe](https://elifulkerson.com/projects/tcping.php), but written with Golang.
64

7-
85
## Usage
96

10-
* The default count of ping is 4.
7+
- The default count of ping is 4.
118

12-
* If the port is omitted, the default port is 80.
9+
- If the port is omitted, the default port is 80.
1310

14-
* The default interval of ping is 1s.
11+
- The default interval of ping is 1s.
1512

16-
* The default timeout of ping is 1s.
13+
- The default timeout of ping is 1s.
1714

1815
### ping tcp
1916

go.mod

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
module github.com/cloverstd/tcping
22

3-
go 1.12
3+
go 1.17
44

55
require (
6+
github.com/smartystreets/goconvey v1.7.2
7+
github.com/spf13/cobra v1.3.0
8+
golang.org/x/net v0.0.0-20220114011407-0dd24b26b47d
9+
)
10+
11+
require (
12+
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 // indirect
613
github.com/inconshreveable/mousetrap v1.0.0 // indirect
7-
github.com/smartystreets/goconvey v0.0.0-20190306220146-200a235640ff
8-
github.com/spf13/cobra v0.0.3
9-
github.com/spf13/pflag v1.0.3 // indirect
10-
golang.org/x/net v0.0.0-20210224082022-3d97a244fca7
14+
github.com/jtolds/gls v4.20.0+incompatible // indirect
15+
github.com/smartystreets/assertions v1.2.0 // indirect
16+
github.com/spf13/pflag v1.0.5 // indirect
1117
)

0 commit comments

Comments
 (0)