Repository navigation
build(deps): bump actions/upload-artifact from 4 to 7 #23
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 镜像构建' | |
| # 触发时机: | |
| # 1. push 到 main 或开 PR:构建镜像并上传工件,只做自检,不发布 Release; | |
| # 2. 推送 v* 标签,或用户在 GitHub 上「发布」一个版本:额外把镜像 tar 包挂到那个 Release 上。 | |
| # 说明:release.yml 的 Release 流水线也会构建同名单平台镜像,两条流水线产出同名产物,重复上传只是覆盖。 | |
| on: | |
| workflow_dispatch: | |
| pull_request: | |
| push: | |
| branches: | |
| - main | |
| tags: | |
| - 'v*' | |
| release: | |
| types: [published, released] | |
| permissions: | |
| contents: write | |
| # PR 与 push 可能同时触发,串行执行避免并发争抢同一工件名 | |
| concurrency: | |
| group: 'docker-${{ github.workflow }}-${{ github.ref }}' | |
| cancel-in-progress: false | |
| env: | |
| BIN_NAME: simple-web-shell | |
| jobs: | |
| docker-build: | |
| name: '构建镜像 ${{ matrix.arch }}' | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - { arch: amd64, platform: 'linux/amd64' } | |
| - { arch: arm64, platform: 'linux/arm64' } | |
| steps: | |
| - name: '检出代码' | |
| uses: actions/checkout@v4 | |
| - name: 'Go 单元测试' | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.26' | |
| - name: '运行测试' | |
| run: go test ./... | |
| - name: '静态检查 go vet' | |
| run: go vet ./... | |
| - name: '启用 QEMU(arm64 镜像构建)' | |
| uses: docker/setup-qemu-action@v3 | |
| - name: '启用 Buildx' | |
| uses: docker/setup-buildx-action@v3 | |
| - name: '构建镜像并导出 tar 包' | |
| run: | | |
| set -euo pipefail | |
| out="$BIN_NAME-image-${{ matrix.arch }}.tar" | |
| # docker 导出器只接受单平台结果,所以按矩阵逐个架构导出,而不是一次构建多平台 | |
| docker buildx build \ | |
| --platform ${{ matrix.platform }} \ | |
| --tag "$BIN_NAME:${{ matrix.arch }}" \ | |
| --output "type=docker,dest=$out" \ | |
| . | |
| ls -lh "$out" | |
| gzip -9 -f "$out" | |
| - name: '上传镜像工件' | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: 'docker-image-${{ matrix.arch }}' | |
| path: '${{ env.BIN_NAME }}-image-${{ matrix.arch }}.tar.gz' | |
| if-no-files-found: 'error' | |
| retention-days: 7 | |
| - name: '上传镜像包到 Release' | |
| if: github.event_name == 'release' || startsWith(github.ref, 'refs/tags/') | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ github.event.release.tag_name || github.ref_name }} | |
| files: '${{ env.BIN_NAME }}-image-${{ matrix.arch }}.tar.gz' | |
| fail_on_unmatched_files: false |