Upload to Docker #41
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: Upload to Docker | |
| # Controls when the action will run. | |
| on: | |
| release: | |
| types: [created] | |
| # Allows you to run this workflow manually from the Actions tab | |
| workflow_dispatch: | |
| jobs: | |
| docker: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - | |
| name: Checkout | |
| uses: actions/checkout@v3 | |
| - | |
| name: Docker meta | |
| id: meta | |
| uses: docker/metadata-action@v4 | |
| with: | |
| # list of Docker images to use as base name for tags | |
| images: | | |
| ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.APP_NAME }} | |
| # generate Docker tags based on the following events/attributes | |
| tags: | | |
| type=semver,pattern={{version}} | |
| type=semver,pattern={{major}}.{{minor}} | |
| type=semver,pattern={{major}} | |
| type=sha | |
| # 新增:release 触发时添加 latest 标签 | |
| type=raw,value=latest,enable=${{ github.event_name == 'release' }} | |
| # 可选:手动触发时也添加 latest 标签 | |
| type=raw,value=latest,enable=${{ github.event_name == 'workflow_dispatch' }} | |
| - | |
| name: Set up QEMU | |
| uses: docker/setup-qemu-action@v2 | |
| - | |
| name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v2 | |
| id: buildx | |
| with: | |
| install: true # 确保安装最新版 Buildx | |
| - | |
| name: Login to Docker Hub | |
| uses: docker/login-action@v2 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - | |
| name: Build and push | |
| uses: docker/build-push-action@v4 | |
| with: | |
| context: . | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| platforms: linux/amd64,linux/arm64 # 关键:指定amd64和arm64架构 | |
| builder: ${{ steps.buildx.outputs.name }} # 使用Buildx构建器 | |
| # Send Feishu notification | |
| - name: "Send Feishu notification" | |
| if: always() | |
| run: | | |
| STATUS="${{ job.status }}" | |
| if [ "$STATUS" == "success" ]; then | |
| STATUS_TEXT="成功" | |
| elif [ "$STATUS" == "failure" ]; then | |
| STATUS_TEXT="失败" | |
| else | |
| STATUS_TEXT="取消" | |
| fi | |
| curl -X POST "${{ secrets.FEISHU_WEBHOOK }}" \ | |
| -H "Content-Type: application/json" \ | |
| -d "{ | |
| \"msg_type\": \"text\", | |
| \"content\": { | |
| \"text\": \"GitHub workflow 通知:\\n- 工作流:Upload to Docker\\n- 状态:$STATUS_TEXT\\n- 触发事件:${{ github.event_name }}\\n- 提交:${{ github.sha }}\\n- 分支:${{ github.ref }}\\n- 仓库:${{ github.repository }}\" | |
| } | |
| }" |