name: Go Build & Release on: push: branches: [ "main" ] tags: - 'v*' # 监听形如 v1.0, v2.0 的提交签发事件以触发正式 Release pull_request: branches: [ "main" ] # 【必需权限声明】:默认情况下的 GitHub Token 只有读能力。赋予 contents: write 才能创建 Release 页面并上传附件 permissions: contents: write jobs: build: runs-on: ubuntu-latest strategy: matrix: include: - os: linux arch: amd64 name: imagehost-linux-amd64 - os: linux arch: arm64 name: imagehost-linux-arm64 - os: windows arch: amd64 name: imagehost-windows-amd64.exe - os: darwin arch: amd64 name: imagehost-macos-amd64 - os: darwin arch: arm64 name: imagehost-macos-arm64 steps: - uses: actions/checkout@v4 - name: Set up Go uses: actions/setup-go@v4 with: go-version: '1.21' cache: true - name: Build Binary env: GOOS: ${{ matrix.os }} GOARCH: ${{ matrix.arch }} run: | mkdir -p dist go build -v -o dist/${{ matrix.name }} ./cmd/main.go - name: Upload Artifact (For standard push) uses: actions/upload-artifact@v4 with: name: ${{ matrix.name }} path: dist/${{ matrix.name }} # 关键追加:当检测到 Tag 标签推入时,自动化传给 Release! - name: Upload to GitHub Releases uses: softprops/action-gh-release@v2 if: startsWith(github.ref, 'refs/tags/') with: files: dist/${{ matrix.name }} generate_release_notes: true # ==== 🌟 新增的 DockerHub 全自动推送组 ==== docker: # 避免在其他人的野鸡 PR 测试中乱发 if: github.event_name != 'pull_request' runs-on: ubuntu-latest steps: - name: Checkout codebase 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: Login to DockerHub uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Extract Docker metadata (自动打标签系统) id: meta uses: docker/metadata-action@v5 with: # 自动组合 "你的名字 / 项目名" images: ${{ secrets.DOCKERHUB_USERNAME }}/123pan-imagehost tags: | type=ref,event=branch type=ref,event=tag # 原本的 latest 标签会在 master/main 分支时被自动赋予 type=raw,value=latest,enable={{is_default_branch}} - name: Build and push to Space (核心推流指令) uses: docker/build-push-action@v5 with: context: . push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} # 借用 Github 的高速缓存,让你后续的打包时间缩短成几秒! cache-from: type=gha cache-to: type=gha,mode=max - name: Sync README to DockerHub (自动更新主页排版) uses: peter-evans/dockerhub-description@v4 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} repository: ${{ secrets.DOCKERHUB_USERNAME }}/123pan-imagehost readme-filepath: ./README.md