Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 2 additions & 3 deletions .github/release-tools/release-images.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#!/usr/bin/env bash
set -euo pipefail
: "${RELEASE_VERSION:?}" "${RELEASE_SHA:?}" "${GITHUB_REPOSITORY:?}" "${RUNNER_TEMP:?}"
owner=${GITHUB_REPOSITORY%%/*}
registries=("ghcr.io/${owner,,}/sub2api")
registries=("ghcr.io/${GITHUB_REPOSITORY,,}")
if [[ ${SIMPLE_RELEASE:-false} != true && ${DOCKERHUB_USERNAME:-skip} != skip ]]; then
registries+=("${DOCKERHUB_USERNAME}/sub2api")
registries+=("${DOCKERHUB_USERNAME,,}/sub4api")
fi
arches=(amd64 arm64)
if [[ ${SIMPLE_RELEASE:-false} == true ]]; then arches=(amd64); fi
Expand Down
4 changes: 2 additions & 2 deletions .github/release-tools/release_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def archive_name(version, target):
if not VERSION_RE.fullmatch(version) or target not in targets():
raise ValueError('invalid release version or target')
suffix = 'zip' if target['goos'] == 'windows' else 'tar.gz'
return f"sub2api_{version}_{target['goos']}_{target['goarch']}.{suffix}"
return f"sub4api_{version}_{target['goos']}_{target['goarch']}.{suffix}"


def sha256(path):
Expand Down Expand Up @@ -95,7 +95,7 @@ def generate_config(args):
data['before'] = {'hooks': []}
data['builds'] = [{'id': 'sub2api', 'skip': True}]
data['archives'] = []
extra = [{'glob': 'release-input/sub2api_*.tar.gz'}, {'glob': 'release-input/sub2api_*.zip'}]
extra = [{'glob': 'release-input/sub4api_*.tar.gz'}, {'glob': 'release-input/sub4api_*.zip'}]
if args.simple:
data['checksum'] = {'disable': True}
else:
Expand Down
13 changes: 7 additions & 6 deletions .github/release-tools/test_release_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def test_missing_extra_and_wrong_commit_artifacts_are_rejected(self):
with self.assertRaises(FileNotFoundError):
release.verify(args)

@unittest.skipIf(os.name == 'nt', 'POSIX executable mode requires a POSIX filesystem')
def test_linux_context_preserves_binary_executable_mode(self):
args = self.fixture_artifacts()
Path('Dockerfile.goreleaser').write_text('FROM scratch\nCOPY sub2api /sub2api\n')
Expand Down Expand Up @@ -147,7 +148,7 @@ def test_docker_commands_do_not_publish_during_dry_run(self):
docker.chmod(0o755)
env = {**os.environ, 'PATH': str(fake_bin.resolve()) + os.pathsep + os.environ['PATH'],
'DOCKER_LOG': str(Path('docker.log').resolve()), 'RUNNER_TEMP': self.temp.name,
'RELEASE_VERSION': '9.8.7', 'RELEASE_SHA': 'a' * 40, 'GITHUB_REPOSITORY': 'ExampleOwner/sub2api',
'RELEASE_VERSION': '9.8.7', 'RELEASE_SHA': 'a' * 40, 'GITHUB_REPOSITORY': 'ExampleOwner/sub4api',
'DRY_RUN': 'true', 'SIMPLE_RELEASE': 'false', 'DOCKERHUB_USERNAME': 'skip'}
subprocess.run(['bash', str(ROOT / '.github/release-tools/release-images.sh')], env=env, check=True)
log = Path('docker.log').read_text()
Expand All @@ -156,7 +157,7 @@ def test_docker_commands_do_not_publish_during_dry_run(self):
self.assertNotIn('--push', log)
self.assertNotIn('imagetools', log)
self.assertNotIn('skip/sub2api', log)
self.assertIn('ghcr.io/exampleowner/sub2api', log)
self.assertIn('ghcr.io/exampleowner/sub4api', log)


def test_published_full_and_simple_image_tags(self):
Expand All @@ -170,7 +171,7 @@ def test_published_full_and_simple_image_tags(self):
log_path = Path(f'docker-{simple}.log').resolve()
env = {**os.environ, 'PATH': str(fake_bin.resolve()) + os.pathsep + os.environ['PATH'],
'DOCKER_LOG': str(log_path), 'RUNNER_TEMP': self.temp.name,
'RELEASE_VERSION': '9.8.7', 'RELEASE_SHA': 'a' * 40, 'GITHUB_REPOSITORY': 'ExampleOwner/sub2api',
'RELEASE_VERSION': '9.8.7', 'RELEASE_SHA': 'a' * 40, 'GITHUB_REPOSITORY': 'ExampleOwner/sub4api',
'DRY_RUN': 'false', 'SIMPLE_RELEASE': str(simple).lower(), 'DOCKERHUB_USERNAME': 'fixturehub'}
subprocess.run(['bash', str(ROOT / '.github/release-tools/release-images.sh')], env=env, check=True)
log = log_path.read_text()
Expand All @@ -179,11 +180,11 @@ def test_published_full_and_simple_image_tags(self):
if simple:
self.assertNotIn('fixturehub', log)
self.assertNotIn('imagetools', log)
self.assertIn('ghcr.io/exampleowner/sub2api:latest', log)
self.assertIn('ghcr.io/exampleowner/sub4api:latest', log)
else:
self.assertEqual(log.count('imagetools create'), 2)
self.assertIn('fixturehub/sub2api:9.8', log)
self.assertIn('ghcr.io/exampleowner/sub2api:9', log)
self.assertIn('fixturehub/sub4api:9.8', log)
self.assertIn('ghcr.io/exampleowner/sub4api:9', log)



Expand Down
8 changes: 8 additions & 0 deletions .github/upstream-sync.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"repository": "Wei-Shaw/sub2api",
"version": "0.2.17",
"commit": "b0a02a3304a0a78cdd003ddda1dd23ba02c03084",
"previous_commit": "f2669c8cf62555cd92389b3f55920e9e6e7c6ff2",
"sub4api_version": "1.1.11",
"method": "Three-way source merge with Sub4API module paths and customizations preserved"
}
12 changes: 11 additions & 1 deletion .github/workflows/backend-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ permissions:
contents: read

jobs:
release-validation:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
with:
python-version: '3.13'
- name: Validate fork packaging and update compatibility
run: python3 scripts/release/test_release.py

shell:
runs-on: macos-15
steps:
Expand Down Expand Up @@ -48,7 +58,7 @@ jobs:
- name: Setup pnpm
uses: pnpm/action-setup@v6
with:
version: 9
version: 9.15.9
- name: Setup Node.js
uses: actions/setup-node@v6
with:
Expand Down
13 changes: 4 additions & 9 deletions .github/workflows/main-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ concurrency:
jobs:
release:
runs-on: ubuntu-latest
environment: sub4api
steps:
- uses: actions/checkout@v6
with:
Expand Down Expand Up @@ -71,7 +70,7 @@ jobs:
- uses: pnpm/action-setup@v6
if: steps.current.outputs.publish == 'true'
with:
version: 9
version: 9.15.9
- uses: actions/setup-node@v6
if: steps.current.outputs.publish == 'true'
with:
Expand Down Expand Up @@ -108,11 +107,11 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/login-action@v3
if: steps.current.outputs.publish == 'true'
if: steps.current.outputs.publish == 'true' && steps.meta.outputs.dockerhub_enabled == 'true'
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push both registries
- name: Build and push images
if: steps.current.outputs.publish == 'true'
id: image
uses: docker/build-push-action@v6
Expand All @@ -121,11 +120,7 @@ jobs:
file: Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ steps.meta.outputs.ghcr }}:${{ steps.meta.outputs.version }}
${{ steps.meta.outputs.ghcr }}:latest
${{ steps.meta.outputs.dockerhub }}:${{ steps.meta.outputs.version }}
${{ steps.meta.outputs.dockerhub }}:latest
tags: ${{ steps.meta.outputs.tags }}
build-args: |
VERSION=${{ steps.meta.outputs.version }}
COMMIT=${{ steps.meta.outputs.commit }}
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ on:
workflow_dispatch:
inputs:
tag:
description: Tag to release (e.g. v0.2.7)
description: Existing branch or tag to release (use main for a new version)
required: true
default: main
type: string

permissions:
Expand All @@ -20,3 +21,4 @@ jobs:
with:
release-ref: ${{ inputs.tag || github.ref }}
secrets: inherit

2 changes: 1 addition & 1 deletion .github/workflows/security-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
- name: Set up pnpm
uses: pnpm/action-setup@v6
with:
version: 9
version: 9.15.9
- name: Set up Node.js
uses: actions/setup-node@v6
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ docs/*
!docs/ASYNC_IMAGE_TASKS.md
!docs/BATCH_IMAGE_MVP.md
!docs/COMPOSITE_GROUPS.md
!docs/OPENAI_GPT55_RETIREMENT.md
!docs/openai-bps.md
!docs/openai-bps-sources.md
!docs/PLUGIN_DEVELOPMENT.md
Expand Down
12 changes: 6 additions & 6 deletions .goreleaser.simple.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# 简化版 GoReleaser 配置 - 仅发布 x86_64 GHCR 镜像
version: 2

project_name: sub2api
project_name: sub4api

before:
hooks:
Expand Down Expand Up @@ -42,9 +42,9 @@ dockers:
goos: linux
goarch: amd64
image_templates:
- "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub2api:{{ .Version }}-amd64"
- "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub2api:{{ .Version }}"
- "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub2api:latest"
- "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub4api:{{ .Version }}-amd64"
- "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub4api:{{ .Version }}"
- "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub4api:latest"
dockerfile: Dockerfile.goreleaser
use: buildx
extra_files:
Expand All @@ -65,7 +65,7 @@ release:
name: "{{ .Env.GITHUB_REPO_NAME }}"
draft: false
prerelease: auto
name_template: "Sub2API {{.Version}} (Simple)"
name_template: "Sub4API {{.Version}} (Simple)"
# 跳过上传二进制包
skip_upload: true
header: |
Expand All @@ -81,7 +81,7 @@ release:

**Docker (x86_64 only):**
```bash
docker pull ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub2api:{{ .Version }}
docker pull ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub4api:{{ .Version }}
```

## 📚 Documentation
Expand Down
64 changes: 32 additions & 32 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: 2

project_name: sub2api
project_name: sub4api

before:
hooks:
Expand Down Expand Up @@ -60,7 +60,7 @@ dockers:
goarch: amd64
skip_push: '{{ if eq .Env.DOCKERHUB_USERNAME "skip" }}true{{ else }}false{{ end }}'
image_templates:
- "{{ .Env.DOCKERHUB_USERNAME }}/sub2api:{{ .Version }}-amd64"
- "{{ .Env.DOCKERHUB_USERNAME }}/sub4api:{{ .Version }}-amd64"
dockerfile: Dockerfile.goreleaser
use: buildx
extra_files:
Expand All @@ -76,7 +76,7 @@ dockers:
goarch: arm64
skip_push: '{{ if eq .Env.DOCKERHUB_USERNAME "skip" }}true{{ else }}false{{ end }}'
image_templates:
- "{{ .Env.DOCKERHUB_USERNAME }}/sub2api:{{ .Version }}-arm64"
- "{{ .Env.DOCKERHUB_USERNAME }}/sub4api:{{ .Version }}-arm64"
dockerfile: Dockerfile.goreleaser
use: buildx
extra_files:
Expand All @@ -92,7 +92,7 @@ dockers:
goos: linux
goarch: amd64
image_templates:
- "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub2api:{{ .Version }}-amd64"
- "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub4api:{{ .Version }}-amd64"
dockerfile: Dockerfile.goreleaser
use: buildx
extra_files:
Expand All @@ -108,7 +108,7 @@ dockers:
goos: linux
goarch: arm64
image_templates:
- "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub2api:{{ .Version }}-arm64"
- "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub4api:{{ .Version }}-arm64"
dockerfile: Dockerfile.goreleaser
use: buildx
extra_files:
Expand All @@ -123,58 +123,58 @@ dockers:
# Docker manifests for multi-arch support
docker_manifests:
# DockerHub manifests (skipped if DOCKERHUB_USERNAME is 'skip')
- name_template: "{{ .Env.DOCKERHUB_USERNAME }}/sub2api:{{ .Version }}"
- name_template: "{{ .Env.DOCKERHUB_USERNAME }}/sub4api:{{ .Version }}"
skip_push: '{{ if eq .Env.DOCKERHUB_USERNAME "skip" }}true{{ else }}false{{ end }}'
image_templates:
- "{{ .Env.DOCKERHUB_USERNAME }}/sub2api:{{ .Version }}-amd64"
- "{{ .Env.DOCKERHUB_USERNAME }}/sub2api:{{ .Version }}-arm64"
- "{{ .Env.DOCKERHUB_USERNAME }}/sub4api:{{ .Version }}-amd64"
- "{{ .Env.DOCKERHUB_USERNAME }}/sub4api:{{ .Version }}-arm64"

- name_template: "{{ .Env.DOCKERHUB_USERNAME }}/sub2api:latest"
- name_template: "{{ .Env.DOCKERHUB_USERNAME }}/sub4api:latest"
skip_push: '{{ if eq .Env.DOCKERHUB_USERNAME "skip" }}true{{ else }}false{{ end }}'
image_templates:
- "{{ .Env.DOCKERHUB_USERNAME }}/sub2api:{{ .Version }}-amd64"
- "{{ .Env.DOCKERHUB_USERNAME }}/sub2api:{{ .Version }}-arm64"
- "{{ .Env.DOCKERHUB_USERNAME }}/sub4api:{{ .Version }}-amd64"
- "{{ .Env.DOCKERHUB_USERNAME }}/sub4api:{{ .Version }}-arm64"

- name_template: "{{ .Env.DOCKERHUB_USERNAME }}/sub2api:{{ .Major }}.{{ .Minor }}"
- name_template: "{{ .Env.DOCKERHUB_USERNAME }}/sub4api:{{ .Major }}.{{ .Minor }}"
skip_push: '{{ if eq .Env.DOCKERHUB_USERNAME "skip" }}true{{ else }}false{{ end }}'
image_templates:
- "{{ .Env.DOCKERHUB_USERNAME }}/sub2api:{{ .Version }}-amd64"
- "{{ .Env.DOCKERHUB_USERNAME }}/sub2api:{{ .Version }}-arm64"
- "{{ .Env.DOCKERHUB_USERNAME }}/sub4api:{{ .Version }}-amd64"
- "{{ .Env.DOCKERHUB_USERNAME }}/sub4api:{{ .Version }}-arm64"

- name_template: "{{ .Env.DOCKERHUB_USERNAME }}/sub2api:{{ .Major }}"
- name_template: "{{ .Env.DOCKERHUB_USERNAME }}/sub4api:{{ .Major }}"
skip_push: '{{ if eq .Env.DOCKERHUB_USERNAME "skip" }}true{{ else }}false{{ end }}'
image_templates:
- "{{ .Env.DOCKERHUB_USERNAME }}/sub2api:{{ .Version }}-amd64"
- "{{ .Env.DOCKERHUB_USERNAME }}/sub2api:{{ .Version }}-arm64"
- "{{ .Env.DOCKERHUB_USERNAME }}/sub4api:{{ .Version }}-amd64"
- "{{ .Env.DOCKERHUB_USERNAME }}/sub4api:{{ .Version }}-arm64"

# GHCR manifests (owner must be lowercase)
- name_template: "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub2api:{{ .Version }}"
- name_template: "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub4api:{{ .Version }}"
image_templates:
- "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub2api:{{ .Version }}-amd64"
- "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub2api:{{ .Version }}-arm64"
- "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub4api:{{ .Version }}-amd64"
- "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub4api:{{ .Version }}-arm64"

- name_template: "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub2api:latest"
- name_template: "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub4api:latest"
image_templates:
- "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub2api:{{ .Version }}-amd64"
- "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub2api:{{ .Version }}-arm64"
- "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub4api:{{ .Version }}-amd64"
- "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub4api:{{ .Version }}-arm64"

- name_template: "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub2api:{{ .Major }}.{{ .Minor }}"
- name_template: "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub4api:{{ .Major }}.{{ .Minor }}"
image_templates:
- "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub2api:{{ .Version }}-amd64"
- "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub2api:{{ .Version }}-arm64"
- "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub4api:{{ .Version }}-amd64"
- "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub4api:{{ .Version }}-arm64"

- name_template: "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub2api:{{ .Major }}"
- name_template: "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub4api:{{ .Major }}"
image_templates:
- "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub2api:{{ .Version }}-amd64"
- "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub2api:{{ .Version }}-arm64"
- "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub4api:{{ .Version }}-amd64"
- "ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub4api:{{ .Version }}-arm64"

release:
github:
owner: "{{ .Env.GITHUB_REPO_OWNER }}"
name: "{{ .Env.GITHUB_REPO_NAME }}"
draft: false
prerelease: auto
name_template: "Sub2API {{.Version}}"
name_template: "Sub4API {{.Version}}"
# 完全使用 tag 消息作为 release 内容(通过环境变量传入)
header: |
> AI API Gateway Platform - 将 AI 订阅配额分发和管理
Expand All @@ -191,11 +191,11 @@ release:
```bash
{{ if ne .Env.DOCKERHUB_USERNAME "skip" -}}
# Docker Hub
docker pull {{ .Env.DOCKERHUB_USERNAME }}/sub2api:{{ .Version }}
docker pull {{ .Env.DOCKERHUB_USERNAME }}/sub4api:{{ .Version }}

{{ end -}}
# GitHub Container Registry
docker pull ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub2api:{{ .Version }}
docker pull ghcr.io/{{ .Env.GITHUB_REPO_OWNER_LOWER }}/sub4api:{{ .Version }}
```

**One-line install (Linux):**
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ FROM ${POSTGRES_IMAGE} AS pg-client
FROM ${ALPINE_IMAGE}

# Labels
LABEL maintainer="Wei-Shaw <github.com/Wei-Shaw>"
LABEL description="Sub2API - AI API Gateway Platform"
LABEL org.opencontainers.image.source="https://github.com/MACOS-DO/sub4api"
LABEL maintainer="talent668 <github.com/talent668>"
LABEL description="Sub4API - AI API Gateway Platform"
LABEL org.opencontainers.image.source="https://github.com/talent668/sub4api"

# Install runtime dependencies
RUN apk add --no-cache \
Expand Down
Loading
Loading