Files
opencode2api/.github/workflows/release.yml
T
Jason Xu 46def7fedc refactor: organize Go packages and remove test files
Move the command to cmd/opencode2api and group production code into
configuration, gateway, protocol, model, admin, telemetry and helper packages.
Keep shared state private behind context, metrics and runtime interfaces.

Remove the requested test files and replace test-only CI jobs with vet/build
checks. Update Docker and release build paths, preserve version injection and
make the WebUI an explicit embedded asset package.

Add directory trees and source reading guides to both READMEs. Anchor binary
ignore rules so the command package is tracked.
2026-09-15 01:28:44 +08:00

232 lines
7.3 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"
verify:
name: Verify source
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: Vet
run: go vet ./...
- name: Build
run: go build ./...
build:
name: Build ${{ matrix.goos }}/${{ matrix.goarch }}
needs: [prepare, verify]
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" ./cmd/opencode2api
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, verify]
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