-
Notifications
You must be signed in to change notification settings - Fork 1
135 lines (108 loc) · 4.78 KB
/
Copy pathrelease.yml
File metadata and controls
135 lines (108 loc) · 4.78 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
name: Release Binaries and Docker Image
on:
push:
tags:
- "v*" # 当推送以v开头的标签时触发,例如V20260612.0
permissions:
contents: write # 需要这个权限来创建release和上传文件
jobs:
build:
name: Build and Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23'
check-latest: true
- name: Get tag name
id: get_tag
run: echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
- name: Build binaries
run: |
# 创建build目录存放二进制文件
mkdir -p builds
# linux (amd64)
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags '-extldflags "-static"' -o builds/tiny-requestbin-linux-amd64 .
# Linux (arm64)
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -a -ldflags '-extldflags "-static"' -o builds/tiny-requestbin-linux-arm64 .
# macOS (Intel)
GOOS=darwin GOARCH=amd64 go build -o builds/tiny-requestbin-darwin-amd64 .
# macOS (Apple Silicon)
GOOS=darwin GOARCH=arm64 go build -o builds/tiny-requestbin-darwin-arm64 .
# Windows (x86_64)
GOOS=windows GOARCH=amd64 go build -o builds/tiny-requestbin-windows-amd64.exe .
- name: Compress Binaries
run: |
cd builds
mkdir -p packages
make_package_dir() {
local package_name="$1"
local binary_source="$2"
local binary_name="$3"
mkdir -p "packages/${package_name}"
cp "${binary_source}" "packages/${package_name}/${binary_name}"
cp ../LICENSE "packages/${package_name}/LICENSE"
cp ../packaging/release-package-readme.txt "packages/${package_name}/README.txt"
}
make_package_dir "tiny-requestbin-${TAG}-linux-amd64" "tiny-requestbin-linux-amd64" "tiny-requestbin"
make_package_dir "tiny-requestbin-${TAG}-linux-arm64" "tiny-requestbin-linux-arm64" "tiny-requestbin"
make_package_dir "tiny-requestbin-${TAG}-darwin-amd64" "tiny-requestbin-darwin-amd64" "tiny-requestbin"
make_package_dir "tiny-requestbin-${TAG}-darwin-arm64" "tiny-requestbin-darwin-arm64" "tiny-requestbin"
make_package_dir "tiny-requestbin-${TAG}-windows-amd64" "tiny-requestbin-windows-amd64.exe" "tiny-requestbin.exe"
tar -czf "tiny-requestbin-${TAG}-linux-amd64.tar.gz" -C packages "tiny-requestbin-${TAG}-linux-amd64"
tar -czf "tiny-requestbin-${TAG}-linux-arm64.tar.gz" -C packages "tiny-requestbin-${TAG}-linux-arm64"
tar -czf "tiny-requestbin-${TAG}-darwin-amd64.tar.gz" -C packages "tiny-requestbin-${TAG}-darwin-amd64"
tar -czf "tiny-requestbin-${TAG}-darwin-arm64.tar.gz" -C packages "tiny-requestbin-${TAG}-darwin-arm64"
(cd packages && zip -rq "../tiny-requestbin-${TAG}-windows-amd64.zip" "tiny-requestbin-${TAG}-windows-amd64")
- name: Create Release
id: create_release
uses: softprops/action-gh-release@v1
with:
name: Release ${{ env.TAG }}
draft: false
prerelease: false
files: |
builds/tiny-requestbin-${{ env.TAG }}-darwin-amd64.tar.gz
builds/tiny-requestbin-${{ env.TAG }}-darwin-arm64.tar.gz
builds/tiny-requestbin-${{ env.TAG }}-linux-amd64.tar.gz
builds/tiny-requestbin-${{ env.TAG }}-linux-arm64.tar.gz
builds/tiny-requestbin-${{ env.TAG }}-windows-amd64.zip
docker:
name: Build and Push Docker Image
runs-on: ubuntu-latest
needs: build # 等待 build job 完成
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: knktc
password: ${{ secrets.DOCKERHUB_KEY }}
- name: Get tag name
id: get_tag
run: echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: knktc/tiny-requestbin
tags: |
type=ref,event=tag
type=raw,value=latest
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max