-
Notifications
You must be signed in to change notification settings - Fork 0
146 lines (141 loc) · 4.61 KB
/
Copy pathrelease.yml
File metadata and controls
146 lines (141 loc) · 4.61 KB
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
141
142
143
144
145
146
name: 发布
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
tag:
description: "要发布的版本标签,可带或不带 v,例如 0.3.1"
required: true
type: string
permissions:
contents: write
jobs:
test:
name: 测试 (${{ matrix.os }})
runs-on: ${{ matrix.os }}
env:
RELEASE_TAG: ${{ github.event_name == 'workflow_dispatch' && (startsWith(inputs.tag, 'v') && inputs.tag || format('v{0}', inputs.tag)) || github.ref_name }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- windows-latest
steps:
# 使用默认分支的最新校验脚本,验证目标发布标签中的安装脚本。
- uses: actions/checkout@v5
with:
ref: ${{ github.event.repository.default_branch }}
- uses: actions/checkout@v5
with:
ref: ${{ env.RELEASE_TAG }}
path: release
- uses: actions/setup-go@v6
with:
go-version: "1.23.x"
- run: go test ./...
working-directory: release
- run: go vet ./...
working-directory: release
- name: 检查 Linux 安装脚本
if: runner.os == 'Linux'
run: |
sh -n release/scripts/install.sh
test_dir=$(mktemp -d)
cp scripts/install_sh_test.sh "$test_dir/install_sh_test.sh"
cp release/scripts/install.sh "$test_dir/install.sh"
sh "$test_dir/install_sh_test.sh"
build:
name: ${{ matrix.goos }}-${{ matrix.goarch }}
needs: test
runs-on: ubuntu-latest
env:
RELEASE_TAG: ${{ github.event_name == 'workflow_dispatch' && (startsWith(inputs.tag, 'v') && inputs.tag || format('v{0}', inputs.tag)) || github.ref_name }}
strategy:
fail-fast: false
matrix:
include:
- goos: windows
goarch: amd64
extension: .exe
archive: zip
- goos: linux
goarch: amd64
extension: ""
archive: tar.gz
- goos: linux
goarch: arm64
extension: ""
archive: tar.gz
- goos: darwin
goarch: amd64
extension: ""
archive: tar.gz
- goos: darwin
goarch: arm64
extension: ""
archive: tar.gz
steps:
- uses: actions/checkout@v5
with:
ref: ${{ env.RELEASE_TAG }}
- uses: actions/setup-go@v6
with:
go-version: "1.23.x"
- name: 构建并压缩
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
EXTENSION: ${{ matrix.extension }}
ARCHIVE: ${{ matrix.archive }}
VERSION: ${{ env.RELEASE_TAG }}
run: |
VERSION="${VERSION#v}"
mkdir -p dist
CGO_ENABLED=0 go build -trimpath -ldflags "-s -w -X github.com/certd/certd-client/internal/version.Version=${VERSION}" -o "dist/certd-client${EXTENSION}" ./cmd/certd-client
if [ "$ARCHIVE" = "zip" ]; then
(cd dist && zip "certd-client-${GOOS}-${GOARCH}.zip" "certd-client${EXTENSION}")
else
tar -C dist -czf "dist/certd-client-${GOOS}-${GOARCH}.tar.gz" "certd-client${EXTENSION}"
fi
- uses: actions/upload-artifact@v5
with:
name: certd-client-${{ matrix.goos }}-${{ matrix.goarch }}
path: dist/certd-client-${{ matrix.goos }}-${{ matrix.goarch }}.${{ matrix.archive }}
if-no-files-found: error
github-release:
name: 创建 GitHub Release
needs: build
runs-on: ubuntu-latest
env:
RELEASE_TAG: ${{ github.event_name == 'workflow_dispatch' && (startsWith(inputs.tag, 'v') && inputs.tag || format('v{0}', inputs.tag)) || github.ref_name }}
steps:
- uses: actions/checkout@v5
with:
ref: ${{ env.RELEASE_TAG }}
- uses: actions/download-artifact@v5
with:
path: dist
merge-multiple: true
- name: 读取发布说明
env:
TAG: ${{ env.RELEASE_TAG }}
run: |
version="${TAG#v}"
heading="## [${version}]"
if ! grep -Fq "$heading - " CHANGELOG.md; then
echo "CHANGELOG.md 中未找到 ${heading}" >&2
exit 1
fi
awk -v version="$version" '
index($0, "## [" version "] - ") == 1 { found = 1; next }
found && /^## \[/ { exit }
found { print }
' CHANGELOG.md > release-notes.md
- uses: softprops/action-gh-release@v2
with:
tag_name: ${{ env.RELEASE_TAG }}
body_path: release-notes.md
files: dist/*