- 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 | matrix: | 215 | matrix: |
| 216 | include: | 216 | include: |
| 217 | - goarch: amd64 | 217 | - goarch: amd64 |
| 218 | vm_arch: x86-64 | ||
| 219 | asset_arch: amd64 | 218 | asset_arch: amd64 |
| 220 | - goarch: arm64 | 219 | - goarch: arm64 |
| 221 | vm_arch: arm64 | ||
| 222 | asset_arch: aarch64 | 220 | asset_arch: aarch64 |
| 223 | steps: | 221 | steps: |
| 224 | - uses: actions/checkout@v6 | 222 | - uses: actions/checkout@v6 |
| @@ -230,74 +228,63 @@ jobs: · 5 unmodified lines | |||
| 230 | git show FETCH_HEAD:models.json > internal/registry/models/models.json | 228 | git show FETCH_HEAD:models.json > internal/registry/models/models.json |
| 231 | - name: Fetch tags | 229 | - name: Fetch tags |
| 232 | run: git fetch --force --tags | 230 | run: git fetch --force --tags |
| 231 | - uses: actions/setup-go@v6 | ||
| 232 | with: | ||
| 233 | go-version: ${{ env.GO_VERSION }} | ||
| 234 | cache: true | ||
| 233 | - uses: actions/cache@v4 | 235 | - uses: actions/cache@v4 |
| 234 | with: | 236 | with: |
| 235 | path: | | 237 | path: | |
| 236 | .freebsd-cache/${{ matrix.goarch }}/go | 238 | ~/.cache/go-build |
| 237 | .freebsd-cache/${{ matrix.goarch }}/gocache | 239 | ~/go/pkg/mod |
| 238 | .freebsd-cache/${{ matrix.goarch }}/gomodcache | 240 | key: go-freebsd-${{ matrix.goarch }}-${{ hashFiles('go.sum') }} |
| 239 | key: freebsd-${{ matrix.goarch }}-go${{ env.GO_VERSION }}-${{ hashFiles('go.sum') }} | ||
| 240 | restore-keys: | | 241 | restore-keys: | |
| 241 | freebsd-${{ matrix.goarch }}-go${{ env.GO_VERSION }}- | 242 | go-freebsd-${{ matrix.goarch }}- |
| 242 | freebsd-${{ matrix.goarch }}- | 243 | go-freebsd- |
| 243 | - name: Generate Build Metadata | 244 | - name: Generate Build Metadata |
| 245 | id: metadata | ||
| 244 | run: | | 246 | run: | |
| 245 | echo "RELEASE_VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV | 247 | set -euo pipefail |
| 246 | echo COMMIT=`git rev-parse --short HEAD` >> $GITHUB_ENV | 248 | release_version="${GITHUB_REF_NAME#v}" |
| 247 | echo BUILD_DATE=`date -u +%Y-%m-%dT%H:%M:%SZ` >> $GITHUB_ENV | 249 | commit="$(git rev-parse --short HEAD)" |
| 248 | - name: Start FreeBSD ${{ matrix.goarch }} VM | 250 | build_date="$(date -u +%Y-%m-%dT%H:%M:%SZ)" |
| 249 | uses: cross-platform-actions/action@v1.2.0 | 251 | echo "RELEASE_VERSION=$release_version" >> "$GITHUB_ENV" |
| 250 | with: | 252 | echo "COMMIT=$commit" >> "$GITHUB_ENV" |
| 251 | operating_system: freebsd | 253 | echo "BUILD_DATE=$build_date" >> "$GITHUB_ENV" |
| 252 | architecture: ${{ matrix.vm_arch }} | 254 | echo "release_version=$release_version" >> "$GITHUB_OUTPUT" |
| 253 | version: '13.5' | 255 | echo "commit=$commit" >> "$GITHUB_OUTPUT" |
| 254 | shell: sh | 256 | echo "build_date=$build_date" >> "$GITHUB_OUTPUT" |
| 255 | memory: 5G | 257 | - name: Install FreeBSD cross-build dependencies |
| 256 | cpu_count: 4 | 258 | run: | |
| 257 | environment_variables: GO_VERSION RELEASE_VERSION COMMIT BUILD_DATE TARGET GOARCH ASSET_ARCH | 259 | set -euo pipefail |
| 258 | - name: Build FreeBSD archive | 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 | timeout-minutes: 45 | 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 | run: | | 279 | run: | |
| 262 | set -eu | 280 | set -euo pipefail |
| 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 | ||
| 289 | 281 | ||
| 290 | archive_dir="dist/${TARGET}/archive" | 282 | archive_dir="dist/${TARGET}/archive" |
| 291 | archive_name="CLIProxyAPI_${RELEASE_VERSION}_freebsd_${ASSET_ARCH}.tar.gz" | 283 | archive_name="CLIProxyAPI_${RELEASE_VERSION}_freebsd_${ASSET_ARCH}.tar.gz" |
| 292 | rm -rf "dist/${TARGET}" | ||
| 293 | mkdir -p "$archive_dir" | 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 | echo "Packaging ${archive_name}" | 286 | echo "Packaging ${archive_name}" |
| 287 | cp "dist/${TARGET}/bin/cli-proxy-api" "$archive_dir/cli-proxy-api" | ||
| 301 | cp LICENSE README.md README_CN.md config.example.yaml "$archive_dir/" | 288 | cp LICENSE README.md README_CN.md config.example.yaml "$archive_dir/" |
| 302 | tar -C "$archive_dir" -czf "dist/$archive_name" cli-proxy-api LICENSE README.md README_CN.md config.example.yaml | 289 | tar -C "$archive_dir" -czf "dist/$archive_name" cli-proxy-api LICENSE README.md README_CN.md config.example.yaml |
| 303 | - name: Create asset checksum | 290 | - name: Create asset checksum |