Skip to content

Commit 2cebbda

Browse files
author
coolrc136
committed
👷 (ci) 修改makefile增加自动构建和测试
1 parent 471d6b2 commit 2cebbda

File tree

8 files changed

+177
-5
lines changed

8 files changed

+177
-5
lines changed

.github/workflows/build-test.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: build-test
2+
on: [pull_request]
3+
4+
jobs:
5+
run:
6+
name: Test
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Checkout
10+
uses: actions/checkout@v2
11+
12+
- name: Setup go
13+
uses: actions/setup-go@v2
14+
with:
15+
go-version: '^1.16'
16+
- run: |
17+
# https://github.com/actions/setup-go/issues/107
18+
cp -f `which go` /usr/bin/go
19+
20+
- name: check fmt
21+
run: |
22+
make fmt-check
23+
24+
- name: vet
25+
run: |
26+
make vet
27+
28+
- name: test
29+
run: |
30+
make test
31+
32+
- name: build
33+
run: |
34+
make

.github/workflows/release.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: release
2+
3+
on:
4+
workflow_dispatch: null
5+
push:
6+
tags:
7+
- '*'
8+
9+
jobs:
10+
goreleaser:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v2
15+
16+
- name: Set up Go
17+
uses: actions/setup-go@v2
18+
with:
19+
go-version: '^1.16'
20+
21+
- run: |
22+
# https://github.com/actions/setup-go/issues/107
23+
cp -f `which go` /usr/bin/go
24+
25+
- name: Make All
26+
run: |
27+
bash ./package.sh
28+
29+
- name: Release
30+
uses: softprops/action-gh-release@v1
31+
if: startsWith(github.ref, 'refs/tags/')
32+
with:
33+
files: |
34+
release/packages/*
35+
env:
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ lmap
66
*.so
77
*.dylib
88

9+
release
10+
911
# Test binary, built with `go test -c`
1012
*.test
1113

Makefile

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,56 @@
1-
GO=go
1+
LDFLAGS := -s -w
2+
3+
BINARY="lmap"
4+
RELEASE_DIR="release"
5+
VERSION=`git describe --tags $(git rev-list --tags --max-count=1 --branches master)`
6+
7+
os-archs=darwin:amd64 darwin:arm64 freebsd:386:softfloat freebsd:amd64 linux:386:softfloat linux:amd64 linux:arm linux:arm64 windows:386:softfloat windows:amd64 linux:mips64 linux:mips64le linux:mips:softfloat linux:mipsle:softfloat
8+
9+
packages=./cmd/lmap ./pkg/lmap
10+
11+
default:
12+
@go build ./cmd/lmap
13+
14+
version:
15+
@echo $(VERSION)
16+
217
all:
3-
"$(GO)" build -o lmap cmd/lmap/main.go
18+
@$(foreach n, $(os-archs),\
19+
os=$(shell echo "$(n)" | cut -d : -f 1);\
20+
arch=$(shell echo "$(n)" | cut -d : -f 2);\
21+
GO386=$(shell echo "$(n)" | cut -d : -f 3);\
22+
target_suffix=$${os}_$${arch};\
23+
echo "Build $${os}-$${arch}...";\
24+
env CGO_ENABLED=0 GOOS=$${os} GOARCH=$${arch} GO386="$${GO386}" go build -trimpath -ldflags "$(LDFLAGS)" -o ./$(RELEASE_DIR)/$(BINARY)_$${target_suffix} ./cmd/lmap;\
25+
echo "Build $${os}-$${arch} done";\
26+
)
27+
@mv ./$(RELEASE_DIR)/$(BINARY)_windows_386 ./$(RELEASE_DIR)/$(BINARY)_windows_386.exe
28+
@mv ./$(RELEASE_DIR)/$(BINARY)_windows_amd64 ./$(RELEASE_DIR)/$(BINARY)_windows_amd64.exe
29+
30+
fmt:
31+
@gofmt -s -w ./
32+
33+
fmt-check:
34+
@diff=`gofmt -s -d ./`; \
35+
if [ -n "$$diff" ]; then \
36+
echo "Please run 'make fmt' and commit the result:"; \
37+
echo "$${diff}"; \
38+
exit 1; \
39+
fi;
40+
41+
install:
42+
@go mod tidy
43+
44+
test:
45+
@go test -cpu=1,2,4 -v -tags integration ./...
46+
47+
vet:
48+
@$(foreach n, $(packages),\
49+
go vet ${n} ;\
50+
)
51+
52+
clean:
53+
@if [ -f ${BINARY} ] ; then rm -r ${BINARY} ; fi
54+
@if [ -d ${RELEASE_DIR} ] ; then rm -r ${RELEASE_DIR} ; fi
55+
56+
.PHONY: default fmt fmt-check install test vet docker clean

cmd/lmap/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ package main
2121
import (
2222
"flag"
2323
"fmt"
24-
"github.com/LinuxHub-Group/lmap/pkg/lmap"
2524
"os"
25+
26+
"github.com/LinuxHub-Group/lmap/pkg/lmap"
2627
)
2728

2829
func main() {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module github.com/LinuxHub-Group/lmap
22

3-
go 1.17
3+
go 1.16

package.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# 当前tag版本
2+
version=`git describe --tags $(git rev-list --tags --max-count=1 --branches master)`
3+
binary="lmap"
4+
echo "build version: $version"
5+
6+
# cross_compiles
7+
make all
8+
9+
rm -rf ./release/packages
10+
mkdir -p ./release/packages
11+
12+
os_all='linux windows darwin freebsd'
13+
arch_all='386 amd64 arm arm64 mips64 mips64le mips mipsle'
14+
15+
cd ./release
16+
17+
for os in $os_all; do
18+
for arch in $arch_all; do
19+
binary_dir_name="${binary}_${version}_${os}_${arch}" #压缩包目录
20+
binary_path="./packages/${binary_dir_name}"
21+
22+
if [ "x${os}" = x"windows" ]; then
23+
if [ ! -f "./${binary}_${os}_${arch}.exe" ]; then
24+
continue
25+
fi
26+
mkdir ${binary_path}
27+
mv ./${binary}_${os}_${arch}.exe ${binary_path}/${binary}.exe
28+
else
29+
if [ ! -f "./${binary}_${os}_${arch}" ]; then
30+
continue
31+
fi
32+
mkdir ${binary_path}
33+
mv ${binary}_${os}_${arch} ${binary_path}/${binary}
34+
fi
35+
cp ../LICENSE ${binary_path}
36+
cp ../README.md ${binary_path}
37+
38+
# packages
39+
cd ./packages
40+
tar -zcf ${binary_dir_name}.tar.gz ${binary_dir_name}
41+
cd ..
42+
rm -rf ${binary_path}
43+
done
44+
done
45+
46+
cd -

pkg/lmap/common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ type ICMP struct {
3131
type HostInfo struct {
3232
host net.IP
3333
isUsed bool
34-
}
34+
}

0 commit comments

Comments
 (0)