增加自动 release 的功能 #55
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: 构建并发布 Docker 镜像 | |
| on: | |
| push: | |
| tags: | |
| - 'v*' # 当推送以 v 开头的 tag 时触发 | |
| env: | |
| # 使用 docker.io 作为 Docker Hub 的注册表 | |
| DOCKER_REGISTRY: docker.io | |
| # 使用 GitHub Container Registry | |
| GHCR_REGISTRY: ghcr.io | |
| # 镜像名称(需要根据实际情况修改) | |
| IMAGE_NAME: ${{ github.repository }} | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| id-token: write | |
| steps: | |
| # 获取版本号 | |
| - name: 获取版本号 | |
| id: get_version | |
| run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV | |
| # 检出代码 | |
| - name: 检出代码 | |
| uses: actions/checkout@v4 | |
| # 安装 make 和 upx | |
| - name: 安装 make 和 upx | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y make upx-ucl | |
| # 设置 Golang | |
| - name: 设置 Golang | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.25.0' | |
| # 设置 Node.js | |
| - name: 设置 Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '22' | |
| # 构建所有组件(前端、agents、服务端) | |
| - name: 构建所有组件 | |
| run: | | |
| make build-release | |
| # 验证 index.html 模板代码 | |
| - name: 验证 index.html 模板代码 | |
| run: | | |
| if grep -q "{{.CustomJS}}" web/dist/index.html && grep -q "{{.CustomCSS}}" web/dist/index.html; then | |
| echo "✓ 自定义模板代码已成功添加到 index.html" | |
| else | |
| echo "✗ 自定义模板代码未找到,重新执行 patch-html" | |
| go run cmd/patch-html/main.go | |
| fi | |
| # 列出编译产物 | |
| - name: 列出编译产物 | |
| run: | | |
| ls -lh ./bin/ | |
| echo "---" | |
| ls -lh ./bin/agents/ | |
| # 设置 QEMU 支持多平台构建 | |
| - name: 设置 QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| # 设置 Docker Buildx | |
| - name: 设置 Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| # 登录 Docker Hub | |
| - name: 登录 Docker Hub | |
| if: github.event_name != 'pull_request' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.DOCKER_REGISTRY }} | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
| # 登录 GitHub Container Registry | |
| - name: 登录 GitHub Container Registry | |
| if: github.event_name != 'pull_request' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.GHCR_REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| # 提取 Docker 元数据 | |
| - name: 提取 Docker 元数据 | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: | | |
| ${{ env.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }} | |
| ${{ env.GHCR_REGISTRY }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=semver,pattern={{version}} | |
| type=semver,pattern={{major}}.{{minor}} | |
| type=semver,pattern={{major}} | |
| type=raw,value=latest | |
| # 构建并推送 Docker 镜像 | |
| - name: 构建并推送 Docker 镜像 | |
| id: build-and-push | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| platforms: linux/amd64,linux/arm64 | |
| file: Dockerfile | |
| push: ${{ github.event_name != 'pull_request' }} | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| build-args: | | |
| VERSION=${{ env.VERSION }} | |
| cache-from: | | |
| type=registry,ref=${{ env.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}:cache | |
| type=local,src=/tmp/.buildx-cache | |
| cache-to: | | |
| type=registry,ref=${{ env.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}:cache,mode=max | |
| type=local,dest=/tmp/.buildx-cache | |
| # 生成构建总结 | |
| - name: 生成构建总结 | |
| run: | | |
| echo "## Docker 镜像构建成功 🎉" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "**版本:** ${{ env.VERSION }}" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "**镜像标签:**" >> $GITHUB_STEP_SUMMARY | |
| echo '```' >> $GITHUB_STEP_SUMMARY | |
| echo "${{ steps.meta.outputs.tags }}" >> $GITHUB_STEP_SUMMARY | |
| echo '```' >> $GITHUB_STEP_SUMMARY |