mirror of
https://github.com/jasonxu114514/opencode2api.git
synced 2026-12-05 08:02:53 +00:00
Preserve request parameters, tool-call completion reasons and retry session affinity. Bound upstream header waits, stop expired-context scans and add opt-in redacted request-body diagnostics. Isolate Playground diagnostics from production pools, report stream failures accurately, align readiness with discoverable models and honor Docker listen configuration. Split Go and WebUI modules by responsibility, add regression tests and CI, standardize formatting and rewrite the English and Chinese READMEs. Refs: #6, #18, #19, #20, #21, #22, #23, #24, #25
229 lines
7.2 KiB
YAML
229 lines
7.2 KiB
YAML
name: Release binaries and GHCR image
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- "v*"
|
|
workflow_dispatch:
|
|
inputs:
|
|
tag:
|
|
description: "Release tag, for example v1.0.0"
|
|
required: true
|
|
type: string
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
concurrency:
|
|
group: release-${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref }}
|
|
cancel-in-progress: false
|
|
|
|
jobs:
|
|
prepare:
|
|
name: Prepare release
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
release_tag: ${{ steps.metadata.outputs.release_tag }}
|
|
image_name: ${{ steps.metadata.outputs.image_name }}
|
|
steps:
|
|
- name: Resolve release metadata
|
|
id: metadata
|
|
shell: bash
|
|
env:
|
|
DISPATCH_TAG: ${{ inputs.tag }}
|
|
run: |
|
|
if [[ "$GITHUB_EVENT_NAME" == "workflow_dispatch" ]]; then
|
|
release_tag="$DISPATCH_TAG"
|
|
else
|
|
release_tag="$GITHUB_REF_NAME"
|
|
fi
|
|
if [[ ! "$release_tag" =~ ^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-[0-9A-Za-z]+([.-][0-9A-Za-z]+)*)?$ ]]; then
|
|
echo "Release tag must be a semantic version such as v1.0.0 or v1.0.0-rc.1" >&2
|
|
exit 1
|
|
fi
|
|
echo "release_tag=$release_tag" >> "$GITHUB_OUTPUT"
|
|
echo "image_name=ghcr.io/${GITHUB_REPOSITORY,,}" >> "$GITHUB_OUTPUT"
|
|
|
|
test:
|
|
name: Test
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Check out source
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Go
|
|
uses: actions/setup-go@v5
|
|
with:
|
|
go-version-file: go.mod
|
|
cache: true
|
|
|
|
- name: Run tests
|
|
run: go test ./...
|
|
|
|
build:
|
|
name: Build ${{ matrix.goos }}/${{ matrix.goarch }}
|
|
needs: [prepare, test]
|
|
runs-on: ubuntu-latest
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
include:
|
|
- goos: linux
|
|
goarch: amd64
|
|
extension: ""
|
|
archive: tar.gz
|
|
- goos: linux
|
|
goarch: arm64
|
|
extension: ""
|
|
archive: tar.gz
|
|
- goos: windows
|
|
goarch: amd64
|
|
extension: .exe
|
|
archive: zip
|
|
- goos: windows
|
|
goarch: arm64
|
|
extension: .exe
|
|
archive: zip
|
|
- goos: darwin
|
|
goarch: amd64
|
|
extension: ""
|
|
archive: tar.gz
|
|
- goos: darwin
|
|
goarch: arm64
|
|
extension: ""
|
|
archive: tar.gz
|
|
|
|
steps:
|
|
- name: Check out source
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Go
|
|
uses: actions/setup-go@v5
|
|
with:
|
|
go-version-file: go.mod
|
|
cache: true
|
|
|
|
- name: Prepare package name
|
|
id: metadata
|
|
shell: bash
|
|
env:
|
|
RELEASE_TAG: ${{ needs.prepare.outputs.release_tag }}
|
|
run: |
|
|
package_name="opencode2api_${RELEASE_TAG}_${{ matrix.goos }}_${{ matrix.goarch }}"
|
|
echo "package_name=$package_name" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Build and package
|
|
shell: bash
|
|
env:
|
|
CGO_ENABLED: "0"
|
|
GOOS: ${{ matrix.goos }}
|
|
GOARCH: ${{ matrix.goarch }}
|
|
RELEASE_TAG: ${{ needs.prepare.outputs.release_tag }}
|
|
PACKAGE_NAME: ${{ steps.metadata.outputs.package_name }}
|
|
EXTENSION: ${{ matrix.extension }}
|
|
ARCHIVE_FORMAT: ${{ matrix.archive }}
|
|
run: |
|
|
mkdir -p "dist/$PACKAGE_NAME"
|
|
go build -trimpath -ldflags="-s -w -X main.version=$RELEASE_TAG" -o "dist/$PACKAGE_NAME/opencode2api$EXTENSION" ./
|
|
cp README.md README.zh-CN.md config.example.json "dist/$PACKAGE_NAME/"
|
|
if [[ "$ARCHIVE_FORMAT" == "zip" ]]; then
|
|
(cd dist && zip -q -r "$PACKAGE_NAME.zip" "$PACKAGE_NAME")
|
|
archive="$PACKAGE_NAME.zip"
|
|
else
|
|
tar -C dist -czf "dist/$PACKAGE_NAME.tar.gz" "$PACKAGE_NAME"
|
|
archive="$PACKAGE_NAME.tar.gz"
|
|
fi
|
|
(cd dist && sha256sum "$archive" > "$archive.sha256")
|
|
|
|
- name: Upload release files
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: ${{ steps.metadata.outputs.package_name }}
|
|
path: |
|
|
dist/${{ steps.metadata.outputs.package_name }}.${{ matrix.archive }}
|
|
dist/${{ steps.metadata.outputs.package_name }}.${{ matrix.archive }}.sha256
|
|
if-no-files-found: error
|
|
|
|
container:
|
|
name: Publish GHCR image
|
|
needs: [prepare, test]
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
steps:
|
|
- name: Check out source
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v3
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Log in to GHCR
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Generate image metadata
|
|
id: image_metadata
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: ${{ needs.prepare.outputs.image_name }}
|
|
tags: |
|
|
type=raw,value=${{ needs.prepare.outputs.release_tag }}
|
|
type=semver,pattern={{version}},value=${{ needs.prepare.outputs.release_tag }}
|
|
type=semver,pattern={{major}}.{{minor}},value=${{ needs.prepare.outputs.release_tag }},enable=${{ !contains(needs.prepare.outputs.release_tag, '-') }}
|
|
type=semver,pattern={{major}},value=${{ needs.prepare.outputs.release_tag }},enable=${{ !contains(needs.prepare.outputs.release_tag, '-') }}
|
|
labels: |
|
|
org.opencontainers.image.title=opencode2api
|
|
org.opencontainers.image.description=OpenAI-compatible API gateway for OpenCode Zen and Go
|
|
|
|
- name: Build and push image
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
platforms: linux/amd64,linux/arm64
|
|
push: true
|
|
tags: ${{ steps.image_metadata.outputs.tags }}
|
|
labels: ${{ steps.image_metadata.outputs.labels }}
|
|
build-args: |
|
|
VERSION=${{ needs.prepare.outputs.release_tag }}
|
|
cache-from: type=gha,scope=container
|
|
cache-to: type=gha,mode=max,scope=container
|
|
provenance: mode=max
|
|
sbom: true
|
|
|
|
release:
|
|
name: Publish GitHub Release
|
|
needs: [prepare, build, container]
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: write
|
|
steps:
|
|
- name: Download release files
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
pattern: opencode2api_*
|
|
path: release-files
|
|
merge-multiple: true
|
|
|
|
- name: Create or update release
|
|
shell: bash
|
|
env:
|
|
GH_TOKEN: ${{ github.token }}
|
|
RELEASE_TAG: ${{ needs.prepare.outputs.release_tag }}
|
|
run: |
|
|
release_type=()
|
|
if [[ "$RELEASE_TAG" == *-* ]]; then
|
|
release_type+=(--prerelease)
|
|
fi
|
|
if gh release view "$RELEASE_TAG" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
|
|
gh release upload "$RELEASE_TAG" release-files/* --clobber --repo "$GITHUB_REPOSITORY"
|
|
else
|
|
gh release create "$RELEASE_TAG" release-files/* "${release_type[@]}" --generate-notes --title "$RELEASE_TAG" --target "$GITHUB_SHA" --repo "$GITHUB_REPOSITORY"
|
|
fi
|