# Prism CI:单元测试 + 多架构镜像发布到 Gitea Container Registry # # 前置条件: # 1. 在线 act_runner(runs-on: ubuntu-latest) # 2. 仓库 Secret:REGISTRY_TOKEN(write: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 needs: test if: gitea.event_name == 'push' steps: - name: Checkout uses: actions/checkout@v4 - 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 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 \ .