Skip to content

Commit

Permalink
Merge pull request #8 from wuqinqiang/feat/build
Browse files Browse the repository at this point in the history
add build sh
  • Loading branch information
wuqinqiang authored Feb 27, 2023
2 parents 81b35a9 + 84bb224 commit 0eb15e1
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 8 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
build/.*
.idea
conf/conf.yml
conf/conf.example.yml
conf/conf.example.yml

release/
packages/
22 changes: 22 additions & 0 deletions Makefile.cross-compiles
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export PATH := $(GOPATH)/bin:$(PATH)
export GO111MODULE=on
LDFLAGS := -s -w

os-archs=darwin:amd64 darwin:arm64 linux:amd64 linux:arm64 windows:amd64 windows:arm64

all: build

build: app

app:
@$(foreach n, $(os-archs),\
os=$(shell echo "$(n)" | cut -d : -f 1);\
arch=$(shell echo "$(n)" | cut -d : -f 2);\
gomips=$(shell echo "$(n)" | cut -d : -f 3);\
target_suffix=$${os}_$${arch};\
echo "Build $${os}-$${arch}...";\
GOOS=$${os} GOARCH=$${arch} GOMIPS=$${gomips} go build -trimpath -ldflags "$(LDFLAGS)" -o ./release/helloword_$${target_suffix} main.go;\
echo "Build $${os}-$${arch} done";\
)
@mv ./release/helloword_windows_amd64 ./release/helloword_windows_amd64.exe
@mv ./release/helloword_windows_arm64 ./release/helloword_windows_arm64.exe
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ notify: # 通知配置,目前支持telegram,dingtalk,lark可以全配,
指定单词数量,随机选择单词,生成一段小短文,推送到用户指定平台。
```shell
go run main.go daemon --files="CET4.txt,CET6.txt" --spec="@every 10s" --word-number=8
./helloword daemon --files="CET4.txt,CET6.txt" --spec="@every 10s" --word-number=8
```

**参数说明**
Expand All @@ -65,7 +65,7 @@ go run main.go daemon --files="CET4.txt,CET6.txt" --spec="@every 10s" --word-num
### 指定单词,直接生成短语

```shell
go run main.go phrase "approach,proportion,academy,weapon"
./helloword phrase "approach,proportion,academy,weapon"
```

### 单词游戏
Expand All @@ -78,7 +78,7 @@ go run main.go phrase "approach,proportion,academy,weapon"
使用

```shell
go run main.go games chain --files="CET4.txt,CET6.txt"
./helloword games chain --files="CET4.txt,CET6.txt"
```

**参数说明**
Expand Down
44 changes: 44 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@


# cross_compiles
make -f ./Makefile.cross-compiles
rm -rf ./release/packages
mkdir -p ./release/packages

os_all='linux windows darwin'
arch_all='amd64 arm64'

cd ./release

for os in $os_all; do
for arch in $arch_all; do
hello_dir_name="helloword_${os}_${arch}"
hello_path="./packages/helloword_${os}_${arch}"

if [ "x${os}" = x"windows" ]; then
if [ ! -f "./helloword_${os}_${arch}.exe" ]; then
continue
fi
mkdir ${hello_path}
mv ./helloword_${os}_${arch}.exe ${hello_path}/helloword.exe
else
if [ ! -f "./helloword_${os}_${arch}" ]; then
continue
fi
mkdir ${hello_path}
mv ./helloword_${os}_${arch} ${hello_path}/helloword
fi
cp ../LICENSE ${hello_path}
cp -rf ../library/* ${hello_path}

# packages
cd ./packages
if [ "x${os}" = x"windows" ]; then
zip -rq ${hello_dir_name}.zip ${hello_dir_name}
else
tar -zcf ${hello_dir_name}.tar.gz ${hello_dir_name}
fi
cd ..
rm -rf ${hello_path}
done
done
6 changes: 2 additions & 4 deletions collector/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bufio"
"context"
"os"
"path/filepath"
"strings"

"github.com/wuqinqiang/helloword/logging"
Expand All @@ -20,9 +19,8 @@ type File struct {

func New(fileNames string) *File {
file := new(File)
for _, name := range strings.Split(fileNames, ",") {
// hard code
file.fileList = append(file.fileList, filepath.Join("library", name))
for _, fileName := range strings.Split(fileNames, ",") {
file.fileList = append(file.fileList, fileName)
}
return file
}
Expand Down

0 comments on commit 0eb15e1

Please sign in to comment.