-
Notifications
You must be signed in to change notification settings - Fork 0
69 lines (59 loc) · 1.81 KB
/
go-binary-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
name: build-go-binary
on:
release:
types: [created] # 表示在创建新的 Release 时触发
jobs:
goreleaser:
runs-on: ubuntu-latest
env:
flags: ''
steps:
# 1. 检出代码
- name: Checkout
uses: actions/checkout@v3
# 2. 设置 Go 环境
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.21
cache: true
# 3. 运行 GoReleaser
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: latest
args: release --clean ${{ env.flags }}
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_SET_TOKEN }}
# 4. 安装 GitHub CLI
- name: Install GitHub CLI
run: |
sudo apt-get update
sudo apt-get install -y gh
# 5. 定义镜像列表并拉取、推送镜像
- name: Pull and push images to Release
run: |
# 定义镜像列表
images="
nginx:latest
mysql:5.7
jmalloc/echo-server:latest
"
# 逐行处理镜像列表
echo "$images" | while read -r image; do
if [ -n "$image" ]; then
echo "Pulling and pushing image: $image"
# 生成带前缀的文件名
filename="offline-image-$(echo "$image" | tr ':/' '-').tar"
# 拉取镜像并保存为临时文件
docker pull "$image"
docker save -o "$filename" "$image"
# 上传临时文件到 Release
gh release upload ${{ github.event.release.tag_name }} "$filename" --clobber
# 删除临时文件
rm "$filename"
fi
done
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_SET_TOKEN }}