# Prism CI:单元测试 + 多架构镜像发布到 Gitea Container Registry # # 前置条件: # 1. 在线 act_runner(runs-on 须与 Runners 页「标签」列一致,非「名称」列) # 2. 仓库 Secret:REGISTRY_TOKEN(write:package 权限的 PAT) # # 镜像命名:{REGISTRY}/{owner}/prism:{tag} # 默认 REGISTRY=git.rc707blog.top(Gitea 实例域名,Container Registry 与代码仓库同域) name: CI on: push: branches: [main, master] tags: ['v*'] pull_request: env: REGISTRY: git.rc707blog.top IMAGE_NAME: prism jobs: test: runs-on: docker steps: - name: Checkout uses: actions/checkout@v4 - name: Setup Go uses: actions/setup-go@v5 with: go-version-file: go.mod cache: true - name: Run tests run: go test ./... docker: runs-on: docker needs: test if: gitea.event_name == 'push' steps: - name: Checkout 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 Gitea Container Registry uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ gitea.actor }} password: ${{ secrets.REGISTRY_TOKEN }} - name: Resolve image tags id: meta run: | 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*) tag="${GITEA_REF#refs/tags/}" tags="${tags},${image}:${tag}" ;; esac echo "tags=${tags}" >> "${GITHUB_OUTPUT}" env: REGISTRY: ${{ env.REGISTRY }} IMAGE_NAME: ${{ env.IMAGE_NAME }} GITEA_SHA: ${{ gitea.sha }} GITEA_REF: ${{ gitea.ref }} GITEA_REPOSITORY_OWNER: ${{ gitea.repository_owner }} - name: Build and push uses: docker/build-push-action@v6 with: context: . file: Dockerfile platforms: linux/amd64,linux/arm64 push: true tags: ${{ steps.meta.outputs.tags }}