Skip to content

Commit 5bf5b7d

Browse files
authored
Create go.yml
1 parent e64b63c commit 5bf5b7d

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

.github/workflows/go.yml

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
2+
# This workflow will build a golang project
3+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
4+
5+
name: Go
6+
7+
on:
8+
push:
9+
branches: [ "main" ]
10+
pull_request:
11+
branches: [ "main" ]
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-20.04
16+
steps:
17+
- uses: actions/checkout@v3
18+
19+
- name: Set up Go
20+
uses: actions/setup-go@v4
21+
with:
22+
go-version: '1.20.1'
23+
24+
- name: Install dependencies
25+
run: |
26+
go get .
27+
sudo apt install upx -y
28+
- name: Get Set
29+
run: |
30+
go env -w GO111MODULE=on
31+
go env -w CGO_ENABLED=0
32+
- name: Checkout code
33+
uses: actions/checkout@v2
34+
with:
35+
fetch-depth: 0 # 拉取所有历史记录
36+
37+
- name: Build LINUX
38+
run: |
39+
env GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "-s -w" -o Serverless_PortScan_linux_amd64 main.go
40+
env GOOS=linux GOARCH=arm64 go build -trimpath -ldflags "-s -w" -o Serverless_PortScan_linux_arm64 main.go
41+
- name: Build WINDOWS
42+
run: |
43+
env GOOS=windows GOARCH=amd64 go build -trimpath -ldflags "-s -w" -o Serverless_PortScan_windows_amd64.exe main.go
44+
env GOOS=windows GOARCH=386 go build -trimpath -ldflags "-s -w" -o Serverless_PortScan_windows_386.exe main.go
45+
- name: Create Zip Archive
46+
run: |
47+
upx -9 Serverless_PortScan*
48+
zip -r Serverless_PortScan_linux_amd64.zip Serverless_PortScan_linux_amd64
49+
zip -r Serverless_PortScan_linux_arm64.zip Serverless_PortScan_linux_arm64
50+
zip -r Serverless_PortScan_windows_amd64.zip Serverless_PortScan_windows_amd64.exe
51+
zip -r Serverless_PortScan_windows_386.zip Serverless_PortScan_windows_386.exe
52+
53+
- name: Fetch all tags
54+
run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
55+
56+
- name: Get latest tag
57+
id: latest-tag
58+
run: |
59+
# 获取最新的 tag
60+
LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1`)
61+
echo "Latest tag: $LATEST_TAG"
62+
echo ::set-output name=tag::${LATEST_TAG}
63+
- name: Increment tag
64+
id: increment-tag
65+
run: |
66+
# 解析 tag 并递增
67+
LATEST_TAG=${{ steps.latest-tag.outputs.tag }}
68+
BASE_TAG=$(echo "$LATEST_TAG" | sed 's/\(.*\)\.\([0-9]*\)$/\1/')
69+
VERSION=$(echo "$LATEST_TAG" | sed 's/.*\.\([0-9]*\)$/\1/')
70+
NEW_VERSION=$((VERSION + 1))
71+
NEW_TAG="$BASE_TAG.$NEW_VERSION"
72+
echo ::set-output name=new-tag::${NEW_TAG}
73+
echo "NEW_TAG=$NEW_TAG" >> $GITHUB_ENV
74+
- name: Create and Upload Release
75+
env:
76+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
77+
run: |
78+
# 创建 Release
79+
gh release create $NEW_TAG --title "Release $NEW_TAG" --notes "github action自动构建"
80+
81+
# 上传当前目录下所有 zip 文件为 Release 附件
82+
for zip_file in *.zip; do
83+
gh release upload $NEW_TAG "$zip_file" --clobber
84+
done

0 commit comments

Comments
 (0)