增加代码格式化 #49
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: Build & Publish Docker | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: # 可选,允许手动触发 | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| # 1️⃣ 拉取代码 | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| # 2️⃣ 设置 Docker Buildx | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| # 3️⃣ 登录 GHCR(自动使用 GitHub Token) | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GH_TOKEN }} | |
| # 4️⃣ 构建并推送合并镜像(包含前端+后端) | |
| - name: Build and push full-stack image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| push: true | |
| tags: | | |
| ghcr.io/${{ github.repository }}:latest | |
| ghcr.io/${{ github.repository }}:${{ github.sha }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| platforms: linux/amd64,linux/arm64 # 支持多架构 | |
| # 5️⃣ 输出镜像信息 | |
| - name: Image digest | |
| run: | | |
| echo "Full-stack image: ghcr.io/${{ github.repository }}:latest" | |
| echo "Tagged with SHA: ghcr.io/${{ github.repository }}:${{ github.sha }}" |