-
Notifications
You must be signed in to change notification settings - Fork 0
140 lines (121 loc) · 3.8 KB
/
go-release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
name: Release分发
on:
release:
types: [created] # 表示在创建新的 Release 时触发
jobs:
changelog:
name: Generate Changelog
runs-on: ubuntu-latest
outputs:
release_body: ${{ steps.git-cliff.outputs.content }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate a changelog
uses: orhun/git-cliff-action@v2
id: git-cliff
with:
config: git-cliff/cliff.toml
args: -vv --latest --strip 'footer'
env:
OUTPUT: CHANGES.md
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
body: ${{ steps.git-cliff.outputs.content }}
token: ${{ secrets.GITHUB_TOKEN }}
env:
GITHUB_REPOSITORY: ${{ github.repository }}
golangci-latest:
name: Go Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.21'
- run: go mod download
# 进行代码检查
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.55.2
skip-pkg-cache: true
build-test:
runs-on: ubuntu-latest
needs: golangci-latest
strategy:
matrix:
go: [ '1.20', '1.21','stable' ]
name: Go ${{ matrix.go }} Build Test
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
check-latest: true
- name: Get Git Commit Log
id: git-commit-log
run: echo "GIT_COMMIT_LOG=${{ github.sha }}" >> $GITHUB_ENV
- name: Get current time
uses: josStorer/get-current-time@v2
id: current-time
with:
format: YYYYMMDD-HH
utcOffset: "+08:00"
- name: Get Build Time
id: build-time
run: echo "BUILD_TIME=${{ steps.current-time.outputs.readableTime }}" >> $GITHUB_ENV
- name: Print Environment Variables
run: |
echo "${{env.GIT_COMMIT_LOG}}"
echo "${{env.BUILD_TIME}}"
- name: Go Build Binary - Windows amd64
run: |
GOOS=windows GOARCH=amd64 go build
pwd
# go-test:
# runs-on: windows-latest
# needs: [changelog, build-test]
# environment: production
# name: Go Test
# steps:
# - uses: actions/checkout@v4
# - name: Set up Go
# uses: actions/setup-go@v5
# with:
# go-version: '1.21'
# cache: false
#
# - name: Go Test
# run: |
# go test -v ./g_test -tag="@test" -baseurl="${{ secrets.BACKEND_URL }}"
# pwd
build-go-binary:
runs-on: ubuntu-latest
needs: build-test
environment: production
name: Go Build Binary
env:
GOOS: windows
GOARCH: amd64
steps:
- name: Get version
id: get_version
run: echo "CURRENT_VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
- uses: actions/checkout@v4
- uses: hamster1963/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }} # 一个默认的变量,用来实现往 Release 中添加文件
goos: ${{ env.GOOS }}
goarch: ${{ env.GOARCH }}
goversion: 1.21.1 # 可以指定编译使用的 Golang 版本
ldflags: -X "main.GitTag=${{ env.CURRENT_VERSION }}" -X "main.BackendBaseUrl=${{ secrets.BACKEND_URL }}" # 通过 ldflags 注入版本号
pre_command: export CGO_ENABLED=0 && export GODEBUG=http2client=0
overwrite: true
asset_name: "speed_cron_${{ env.GOOS }}_${{ env.GOARCH }}" # 可以指定二进制文件的名称
compress_assets: OFF # 可以指定是否压缩二进制文件