- Removed redundant `vm_arch` matrix configuration. - Replaced manual FreeBSD VM setup with `go-cross/cgo-actions` for cross-compilation. - Improved caching for Go modules and build artifacts. - Simplified metadata generation and environment variable handling. - Streamlined binary packaging and archive creation steps.
Showing the changes to .github (1 of 1 file). Show all
Unified · Split
| @@ -215,10 +215,8 @@ jobs: · 214 unmodified lines | ||
| 215 | 215 | matrix: |
| 216 | 216 | include: |
| 217 | 217 | - goarch: amd64 |
| 218 | − vm_arch: x86-64 | |
| 219 | 218 | asset_arch: amd64 |
| 220 | 219 | - goarch: arm64 |
| 221 | − vm_arch: arm64 | |
| 222 | 220 | asset_arch: aarch64 |
| 223 | 221 | steps: |
| 224 | 222 | - uses: actions/checkout@v6 |
| @@ -230,74 +228,63 @@ jobs: · 5 unmodified lines | ||
| 230 | 228 | git show FETCH_HEAD:models.json > internal/registry/models/models.json |
| 231 | 229 | - name: Fetch tags |
| 232 | 230 | run: git fetch --force --tags |
| 231 | + - uses: actions/setup-go@v6 | |
| 232 | + with: | |
| 233 | + go-version: ${{ env.GO_VERSION }} | |
| 234 | + cache: true | |
| 233 | 235 | - uses: actions/cache@v4 |
| 234 | 236 | with: |
| 235 | 237 | path: | |
| 236 | − .freebsd-cache/${{ matrix.goarch }}/go | |
| 237 | − .freebsd-cache/${{ matrix.goarch }}/gocache | |
| 238 | − .freebsd-cache/${{ matrix.goarch }}/gomodcache | |
| 239 | − key: freebsd-${{ matrix.goarch }}-go${{ env.GO_VERSION }}-${{ hashFiles('go.sum') }} | |
| 238 | + ~/.cache/go-build | |
| 239 | + ~/go/pkg/mod | |
| 240 | + key: go-freebsd-${{ matrix.goarch }}-${{ hashFiles('go.sum') }} | |
| 240 | 241 | restore-keys: | |
| 241 | − freebsd-${{ matrix.goarch }}-go${{ env.GO_VERSION }}- | |
| 242 | − freebsd-${{ matrix.goarch }}- | |
| 242 | + go-freebsd-${{ matrix.goarch }}- | |
| 243 | + go-freebsd- | |
| 243 | 244 | - name: Generate Build Metadata |
| 245 | + id: metadata | |
| 244 | 246 | run: | |
| 245 | − echo "RELEASE_VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV | |
| 246 | − echo COMMIT=`git rev-parse --short HEAD` >> $GITHUB_ENV | |
| 247 | − echo BUILD_DATE=`date -u +%Y-%m-%dT%H:%M:%SZ` >> $GITHUB_ENV | |
| 248 | − - name: Start FreeBSD ${{ matrix.goarch }} VM | |
| 249 | − uses: cross-platform-actions/action@v1.2.0 | |
| 250 | − with: | |
| 251 | − operating_system: freebsd | |
| 252 | − architecture: ${{ matrix.vm_arch }} | |
| 253 | − version: '13.5' | |
| 254 | − shell: sh | |
| 255 | − memory: 5G | |
| 256 | − cpu_count: 4 | |
| 257 | − environment_variables: GO_VERSION RELEASE_VERSION COMMIT BUILD_DATE TARGET GOARCH ASSET_ARCH | |
| 258 | − - name: Build FreeBSD archive | |
| 247 | + set -euo pipefail | |
| 248 | + release_version="${GITHUB_REF_NAME#v}" | |
| 249 | + commit="$(git rev-parse --short HEAD)" | |
| 250 | + build_date="$(date -u +%Y-%m-%dT%H:%M:%SZ)" | |
| 251 | + echo "RELEASE_VERSION=$release_version" >> "$GITHUB_ENV" | |
| 252 | + echo "COMMIT=$commit" >> "$GITHUB_ENV" | |
| 253 | + echo "BUILD_DATE=$build_date" >> "$GITHUB_ENV" | |
| 254 | + echo "release_version=$release_version" >> "$GITHUB_OUTPUT" | |
| 255 | + echo "commit=$commit" >> "$GITHUB_OUTPUT" | |
| 256 | + echo "build_date=$build_date" >> "$GITHUB_OUTPUT" | |
| 257 | + - name: Install FreeBSD cross-build dependencies | |
| 258 | + run: | | |
| 259 | + set -euo pipefail | |
| 260 | + rm -rf "dist/${TARGET}" | |
| 261 | + sudo apt-get update | |
| 262 | + sudo apt-get install -y clang lld wget | |
| 263 | + - name: Build FreeBSD binary | |
| 259 | 264 | timeout-minutes: 45 |
| 260 | − shell: cpa.sh {0} | |
| 265 | + uses: go-cross/cgo-actions@v1 | |
| 266 | + with: | |
| 267 | + dir: . | |
| 268 | + packages: ./cmd/server/ | |
| 269 | + targets: ${{ env.TARGET }} | |
| 270 | + out-dir: dist/${{ env.TARGET }}/bin | |
| 271 | + output: cli-proxy-api | |
| 272 | + flags: >- | |
| 273 | + -ldflags=-s -w | |
| 274 | + -X main.Version=${{ steps.metadata.outputs.release_version }} | |
| 275 | + -X main.Commit=${{ steps.metadata.outputs.commit }} | |
| 276 | + -X main.BuildDate=${{ steps.metadata.outputs.build_date }} | |
| 277 | + - name: Package FreeBSD archive | |
| 278 | + shell: bash | |
| 261 | 279 | run: | |
| 262 | − set -eu | |
| 263 | − cache_root=".freebsd-cache/${GOARCH}" | |
| 264 | − go_root="${cache_root}/go" | |
| 265 | − mkdir -p "${cache_root}/gocache" "${cache_root}/gomodcache" | |
| 266 | − echo "Preparing Go ${GO_VERSION} for FreeBSD ${GOARCH}" | |
| 267 | − if [ ! -x "${go_root}/bin/go" ]; then | |
| 268 | − fetch -o /tmp/go.tar.gz "https://go.dev/dl/go${GO_VERSION}.freebsd-${GOARCH}.tar.gz" | |
| 269 | − rm -rf "$go_root" | |
| 270 | − mkdir -p "$cache_root" | |
| 271 | − tar -C "$cache_root" -xzf /tmp/go.tar.gz | |
| 272 | − fi | |
| 273 | − export GOCACHE="$PWD/${cache_root}/gocache" | |
| 274 | − export GOMODCACHE="$PWD/${cache_root}/gomodcache" | |
| 275 | − export PATH="/usr/local/bin:$PWD/${go_root}/bin:$PATH" | |
| 276 | − go version | |
| 277 | − go env GOOS GOARCH GOCACHE GOMODCACHE | |
| 278 | − | |
| 279 | − echo "Downloading Go modules" | |
| 280 | − go mod download | |
| 281 | − | |
| 282 | − if [ "$GOARCH" = "arm64" ] && ! command -v ld.bfd >/dev/null 2>&1; then | |
| 283 | − echo "Installing binutils for FreeBSD arm64 external linking" | |
| 284 | − sudo env IGNORE_OSVERSION=yes ASSUME_ALWAYS_YES=yes pkg install -y binutils | |
| 285 | − fi | |
| 286 | − if [ "$GOARCH" = "arm64" ]; then | |
| 287 | − ld.bfd --version | head -n 1 | |
| 288 | − fi | |
| 280 | + set -euo pipefail | |
| 289 | 281 | |
| 290 | 282 | archive_dir="dist/${TARGET}/archive" |
| 291 | 283 | archive_name="CLIProxyAPI_${RELEASE_VERSION}_freebsd_${ASSET_ARCH}.tar.gz" |
| 292 | − rm -rf "dist/${TARGET}" | |
| 293 | 284 | mkdir -p "$archive_dir" |
| 294 | 285 | |
| 295 | − echo "Building ${TARGET}" | |
| 296 | − CGO_ENABLED=1 GOOS=freebsd GOARCH="$GOARCH" go build \ | |
| 297 | − -ldflags="-s -w -X main.Version=${RELEASE_VERSION} -X main.Commit=${COMMIT} -X main.BuildDate=${BUILD_DATE}" \ | |
| 298 | − -o "$archive_dir/cli-proxy-api" ./cmd/server/ | |
| 299 | − | |
| 300 | 286 | echo "Packaging ${archive_name}" |
| 287 | + cp "dist/${TARGET}/bin/cli-proxy-api" "$archive_dir/cli-proxy-api" | |
| 301 | 288 | cp LICENSE README.md README_CN.md config.example.yaml "$archive_dir/" |
| 302 | 289 | tar -C "$archive_dir" -czf "dist/$archive_name" cli-proxy-api LICENSE README.md README_CN.md config.example.yaml |
| 303 | 290 | - name: Create asset checksum |