-
Notifications
You must be signed in to change notification settings - Fork 0
155 lines (131 loc) · 4.78 KB
/
release.yml
File metadata and controls
155 lines (131 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
name: Build and Release
on:
push:
tags:
- 'v*'
branches:
- main
- master
jobs:
build:
name: Build Binary
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
# Semantic version range syntax or exact version of Go
go-version: '1.24.1'
- name: Get version from tag
id: get_version
run: |
if [[ $GITHUB_REF == refs/tags/* ]]; then
echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
else
echo "VERSION=dev-$(date +'%Y%m%d')-$(git rev-parse --short HEAD)" >> $GITHUB_ENV
fi
- name: Build binaries
run: |
mkdir -p ./bin
# Windows
GOOS=windows GOARCH=amd64 go build -ldflags="-s -w -X main.version=${{ env.VERSION }}" -o ./bin/github-proxy-windows-amd64.exe
GOOS=windows GOARCH=386 go build -ldflags="-s -w -X main.version=${{ env.VERSION }}" -o ./bin/github-proxy-windows-386.exe
# macOS
GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w -X main.version=${{ env.VERSION }}" -o ./bin/github-proxy-darwin-amd64
GOOS=darwin GOARCH=arm64 go build -ldflags="-s -w -X main.version=${{ env.VERSION }}" -o ./bin/github-proxy-darwin-arm64
# Linux
GOOS=linux GOARCH=amd64 go build -ldflags="-s -w -X main.version=${{ env.VERSION }}" -o ./bin/github-proxy-linux-amd64
GOOS=linux GOARCH=386 go build -ldflags="-s -w -X main.version=${{ env.VERSION }}" -o ./bin/github-proxy-linux-386
GOOS=linux GOARCH=arm64 go build -ldflags="-s -w -X main.version=${{ env.VERSION }}" -o ./bin/github-proxy-linux-arm64
GOOS=linux GOARCH=arm go build -ldflags="-s -w -X main.version=${{ env.VERSION }}" -o ./bin/github-proxy-linux-arm
# Compress binaries
cd ./bin
for file in *; do
if [[ "$file" == *.exe ]]; then
zip "${file%.exe}.zip" "$file"
rm "$file"
else
gzip -9 "$file"
fi
done
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: github-proxy-binaries
path: ./bin/*
retention-days: 7
docker:
name: Build and Push Docker Image
needs: build
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: github-proxy-binaries
path: ./bin
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Get version from tag
id: get_version
run: |
VERSION=${GITHUB_REF#refs/tags/}
echo "VERSION=${VERSION}" >> $GITHUB_ENV
# 去掉版本号前面的 'v' 用于 Docker 标签
DOCKER_VERSION=${VERSION#v}
echo "DOCKER_VERSION=${DOCKER_VERSION}" >> $GITHUB_ENV
- name: Prepare Docker build context
run: |
mkdir -p ./docker
gunzip -c ./bin/github-proxy-linux-amd64.gz > ./docker/github-proxy
chmod +x ./docker/github-proxy
# 创建 Alpine 基础镜像的 Dockerfile
cat > ./docker/Dockerfile << EOF
FROM alpine:latest
# 添加证书以支持 HTTPS
RUN apk --no-cache add ca-certificates tzdata
WORKDIR /app
COPY github-proxy /app/
# 暴露服务端口
EXPOSE 8080
# 设置可执行文件作为容器的入口点
ENTRYPOINT ["/app/github-proxy"]
EOF
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: ./docker
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/github-proxy:latest
${{ secrets.DOCKERHUB_USERNAME }}/github-proxy:${{ env.DOCKER_VERSION }}
release:
name: Create Release
needs: build
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: github-proxy-binaries
path: ./bin
- name: Create Release
uses: softprops/action-gh-release@v1
with:
files: ./bin/*
draft: false
prerelease: false
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.ACTION_GITHUB_TOKEN }}