-
Notifications
You must be signed in to change notification settings - Fork 23
152 lines (131 loc) · 4.97 KB
/
Copy pathrelease.yml
File metadata and controls
152 lines (131 loc) · 4.97 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
name: 发布发行版
on:
workflow_dispatch:
push:
branches:
- master
permissions:
contents: write
packages: write
pull-requests: write
# BuildKit type=gha 缓存走 Actions Cache API;write 含读权限;不显式授权时 actions 为 none
actions: write
jobs:
release-please:
name: release-please
runs-on: ubuntu-latest
outputs:
release_created: ${{ steps.release.outputs.release_created }}
tag_name: ${{ steps.release.outputs.tag_name }}
release_body: ${{ steps.release.outputs.body }}
steps:
- name: 检出代码
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: release-please
id: release
uses: googleapis/release-please-action@v5
with:
config-file: .release-please-config.json
manifest-file: .release-please-manifest.json
build:
name: 构建 ${{ matrix.out }}
runs-on: ubuntu-latest
needs: release-please
if: ${{ needs.release-please.outputs.release_created == 'true' }}
strategy:
fail-fast: false
matrix:
include:
- { goos: linux, goarch: amd64, out: codex-proxy-linux-amd64, zip: codex-proxy-linux-amd64.zip }
- { goos: linux, goarch: arm64, out: codex-proxy-linux-arm64, zip: codex-proxy-linux-arm64.zip }
- { goos: linux, goarch: "386", out: codex-proxy-linux-386, zip: codex-proxy-linux-386.zip }
- { goos: windows, goarch: amd64, out: codex-proxy-windows-amd64.exe, zip: codex-proxy-windows-amd64.zip }
- { goos: windows, goarch: arm64, out: codex-proxy-windows-arm64.exe, zip: codex-proxy-windows-arm64.zip }
- { goos: windows, goarch: "386", out: codex-proxy-windows-386.exe, zip: codex-proxy-windows-386.zip }
- { goos: darwin, goarch: amd64, out: codex-proxy-darwin-amd64, zip: codex-proxy-darwin-amd64.zip }
- { goos: darwin, goarch: arm64, out: codex-proxy-darwin-arm64, zip: codex-proxy-darwin-arm64.zip }
steps:
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version: "1.25.0"
cache: true
- run: go mod download
- name: 交叉编译
env:
CGO_ENABLED: 0
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
run: go build -ldflags="-s -w" -o "${{ matrix.out }}"
- name: 打包 zip
run: |
set -euo pipefail
mkdir -p staging
cp "${{ matrix.out }}" staging/
cp config.example.yaml staging/
(cd staging && zip -q -r "$GITHUB_WORKSPACE/${{ matrix.zip }}" .)
- uses: actions/upload-artifact@v7
with:
name: zip-${{ matrix.goos }}-${{ matrix.goarch }}
path: ${{ matrix.zip }}
package-release:
name: 上传 Release 资产
runs-on: ubuntu-latest
needs:
- release-please
- build
if: ${{ needs.release-please.outputs.release_created == 'true' }}
steps:
- uses: actions/download-artifact@v8
with:
pattern: zip-*
merge-multiple: true
path: dist
- name: 上传 Release 资产
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ needs.release-please.outputs.tag_name }}
name: ${{ needs.release-please.outputs.tag_name }}
body: ${{ needs.release-please.outputs.release_body }}
files: dist/*.zip
docker:
name: Docker 镜像
runs-on: ubuntu-latest
needs: release-please
if: ${{ needs.release-please.outputs.release_created == 'true' }}
steps:
- uses: actions/checkout@v6
- uses: docker/setup-buildx-action@v4
- uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: GHCR 镜像基址
id: ghcr
run: echo "image=ghcr.io/${GITHUB_REPOSITORY,,}" >> "$GITHUB_OUTPUT"
- id: meta
uses: docker/metadata-action@v6
with:
images: ${{ steps.ghcr.outputs.image }}
tags: |
type=semver,pattern={{version}},value=${{ needs.release-please.outputs.tag_name }}
type=semver,pattern={{major}}.{{minor}},value=${{ needs.release-please.outputs.tag_name }}
type=raw,value=latest
type=sha,prefix=
- uses: docker/build-push-action@v7
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# 优先用 GHCR 专用缓存镜像(release 之间可复用);ignore-error 避免首次无 buildcache 时拉取失败
cache-from: |
type=registry,ref=${{ steps.ghcr.outputs.image }}:buildcache,ignore-error=true
type=gha,scope=codex-proxy-docker
cache-to: |
type=gha,mode=max,scope=codex-proxy-docker
type=registry,ref=${{ steps.ghcr.outputs.image }}:buildcache,mode=max