Files
Prism/.gitea/workflows/ci.yml
T
renjue 9e010c39fc
CI / docker (push) Has been cancelled
CI / test (push) Has been cancelled
feat: Prism HTTP/SOCKS5 代理网关及管理台
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-23 15:01:34 +08:00

134 lines
4.2 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Prism CI:单元测试 + 多架构镜像发布到 Gitea Container Registry
#
# 前置条件:
# 1. 在线 act_runnerruns-on: ubuntu-latest
# 2. 仓库 SecretREGISTRY_TOKENwrite:package 权限的 PAT
#
# 说明:Go/Docker 步骤使用 shell + 国内镜像,避免 actions/setup-go 从 GitHub 下载卡住
name: CI
on:
push:
branches: [main, master]
tags: ['v*']
pull_request:
env:
REGISTRY: git.rc707blog.top
IMAGE_NAME: prism
GOPROXY: https://goproxy.cn,direct
GOSUMDB: sum.golang.google.cn
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
run: |
set -eux
GO_VERSION=$(grep '^go ' go.mod | awk '{print $2}')
ARCH=$(uname -m | sed 's/x86_64/amd64/; s/aarch64/arm64/')
TAR="go${GO_VERSION}.linux-${ARCH}.tar.gz"
if command -v go >/dev/null 2>&1 && go version | grep -q "go${GO_VERSION} "; then
go version
else
downloaded=0
for url in \
"https://mirrors.aliyun.com/golang/${TAR}" \
"https://golang.google.cn/dl/${TAR}" \
"https://go.dev/dl/${TAR}"; do
echo "trying ${url}"
if curl -fsSL --connect-timeout 20 --retry 3 --retry-delay 5 --max-time 600 \
"$url" -o /tmp/go.tgz; then
downloaded=1
break
fi
done
if [ "$downloaded" -ne 1 ]; then
echo "failed to download Go ${GO_VERSION}" >&2
exit 1
fi
rm -rf /usr/local/go
tar -C /usr/local -xzf /tmp/go.tgz
fi
echo "/usr/local/go/bin" >> "$GITHUB_PATH"
/usr/local/go/bin/go version
- name: Run tests
run: go test ./...
docker:
runs-on: ubuntu-latest
# 含 Docker CLI;仍须 runner 挂载 /var/run/docker.sock(见 .gitea/act-runner/README.md
container:
image: catthehacker/ubuntu:act-22.04
needs: test
if: gitea.event_name == 'push'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Docker
run: |
set -eux
if ! command -v docker >/dev/null 2>&1; then
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y docker.io
fi
if [ ! -S /var/run/docker.sock ]; then
echo "ERROR: /var/run/docker.sock 未挂载到 job 容器。" >&2
echo "请在 act_runner 宿主机 config.yaml 中配置:" >&2
echo " container.options: -v /var/run/docker.sock:/var/run/docker.sock" >&2
echo " container.valid_volumes: [/var/run/docker.sock]" >&2
echo "然后重启 runner。" >&2
exit 1
fi
docker info
- name: Log in to Gitea Container Registry
run: |
set -eux
echo "${{ secrets.REGISTRY_TOKEN }}" | \
docker login "${{ env.REGISTRY }}" -u "${{ gitea.actor }}" --password-stdin
- name: Build and push
shell: bash
env:
GITEA_SHA: ${{ gitea.sha }}
GITEA_REF: ${{ gitea.ref }}
GITEA_REPOSITORY_OWNER: ${{ gitea.repository_owner }}
run: |
set -eux
image="${REGISTRY}/${GITEA_REPOSITORY_OWNER}/${IMAGE_NAME}"
tags="${image}:sha-${GITEA_SHA:0:7}"
case "${GITEA_REF}" in
refs/heads/main|refs/heads/master)
tags="${tags},${image}:latest"
;;
refs/tags/v*)
tags="${tags},${image}:${GITEA_REF#refs/tags/}"
;;
esac
docker run --privileged --rm tonistiigi/binfmt --install all 2>/dev/null || true
docker buildx create --name prism-builder --use 2>/dev/null || docker buildx use prism-builder
docker buildx inspect --bootstrap
tag_args=()
IFS=',' read -r -a tag_list <<< "$tags"
for t in "${tag_list[@]}"; do
tag_args+=(-t "$t")
done
docker buildx build \
--platform linux/amd64,linux/arm64 \
-f Dockerfile \
"${tag_args[@]}" \
--push \
.