Repository navigation
189 lines (165 loc) · 6.26 KB
/
Copy pathrelease.yml
File metadata and controls
189 lines (165 loc) · 6.26 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
name: Release
on:
workflow_dispatch:
inputs:
release_tag:
description: 'Existing tag to build and publish, for example v3.0.1'
required: true
type: string
source_ref:
description: 'Optional commit or ref to build instead of the release tag'
required: false
type: string
workflow_call:
inputs:
release_tag:
description: 'Release tag to publish, for example v3.0.1'
required: true
type: string
source_ref:
description: 'Commit or ref containing the validated source to build'
required: true
type: string
permissions:
contents: write
concurrency:
# Reusable and manual invocations for the same version share one lane.
group: release-${{ inputs.release_tag || github.ref_name || github.run_id }}
cancel-in-progress: false
jobs:
release:
runs-on: ubuntu-latest
timeout-minutes: 30
env:
VERSION: ${{ inputs.release_tag || github.ref_name }}
SOURCE_REF: ${{ inputs.source_ref || inputs.release_tag || github.ref }}
steps:
- name: Checkout release source
uses: actions/checkout@v5
with:
ref: ${{ inputs.source_ref || inputs.release_tag || github.ref }}
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v5
with:
node-version: 22
cache: npm
cache-dependency-path: frontend/package-lock.json
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
- name: Build frontend
working-directory: frontend
env:
VITE_APP_VERSION: ${{ inputs.release_tag || github.ref_name }}
run: |
npm ci
npm run build
- name: Build release assets
shell: bash
run: |
set -euo pipefail
version="${VERSION#v}"
mkdir -p dist build
build_target() {
local goos="$1"
local goarch="$2"
local archive_base="codex2api_${version}_${goos}_${goarch}"
local workdir="build/${goos}_${goarch}"
local binary_name="codex2api"
rm -rf "$workdir"
mkdir -p "$workdir"
if [[ "$goos" == "windows" ]]; then
binary_name="codex2api.exe"
fi
CGO_ENABLED=0 GOOS="$goos" GOARCH="$goarch" go build -trimpath -ldflags="-s -w -X github.com/codex2api/internal/version.Version=${VERSION}" -o "$workdir/$binary_name" .
cp .env.example "$workdir/.env.example"
cp README.md "$workdir/README.md"
if [[ "$goos" == "windows" ]]; then
(
cd "$workdir"
zip -r "../../dist/${archive_base}.zip" .
)
else
tar -C "$workdir" -czf "dist/${archive_base}.tar.gz" .
fi
}
build_target linux amd64
build_target linux arm64
build_target darwin amd64
build_target darwin arm64
build_target windows amd64
(
cd dist
sha256sum * > SHA256SUMS.txt
)
- name: Prepare release notes
shell: bash
run: |
set -euo pipefail
notes_file="$RUNNER_TEMP/codex2api-release-notes.md"
# main carries upstream's README, which has no fork maintenance
# section. The notes live on the custom commit being released.
maintenance_file="docs/custom-maintenance.md"
version="$VERSION"
previous_tag="$(git tag --sort=-version:refname \
| grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' \
| grep -Fxv "$version" \
| head -n 1 || true)"
if [[ ! -f "$maintenance_file" ]]; then
# Tags cut before this file existed must still be rebuildable.
# A present file with a missing heading is a broken custom tree
# and still fails the release.
echo "Release source has no ${maintenance_file}; publishing without fork maintenance notes." >&2
printf '%s\n' \
'## Custom maintenance' \
'' \
'_This release commit has no docs/custom-maintenance.md._' \
'' \
'## 自定义维护内容' \
'' \
'_该发布提交没有 docs/custom-maintenance.md。_' \
> "$notes_file"
else
awk '
/^## Custom maintenance$/ { in_section=1 }
in_section && /^## / && $0 != "## Custom maintenance" { exit }
in_section { print }
' "$maintenance_file" > "$notes_file"
printf '\n---\n\n' >> "$notes_file"
awk '
/^## 自定义维护内容$/ { in_section=1 }
in_section && /^## / && $0 != "## 自定义维护内容" { exit }
in_section { print }
' "$maintenance_file" >> "$notes_file"
if ! grep -q '^## Custom maintenance$' "$notes_file" \
|| ! grep -q '^## 自定义维护内容$' "$notes_file"; then
echo "Custom maintenance sections were empty in ${maintenance_file}." >&2
exit 1
fi
fi
printf '\n## Custom changes in this release\n\n' >> "$notes_file"
custom_commits=""
if [[ -n "$previous_tag" ]]; then
custom_commits="$(git log --first-parent --format='- %s' \
"$previous_tag..$SOURCE_REF" -- \
':!CHANGELOG.md' ':!docs/**' ':!.github/**' \
| grep -Ev '^- (Merge pull request|chore: sync upstream release|ci:)' || true)"
fi
if [[ -n "$custom_commits" ]]; then
printf '%s\n' "$custom_commits" >> "$notes_file"
else
printf '%s\n' '- No additional custom code changes were recorded for this release.' >> "$notes_file"
fi
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ inputs.release_tag || github.ref_name }}
target_commitish: ${{ inputs.source_ref || github.sha }}
body_path: ${{ runner.temp }}/codex2api-release-notes.md
generate_release_notes: true
files: |
dist/*.tar.gz
dist/*.zip
dist/SHA256SUMS.txt