# This workflow will build a golang project # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go name: Release on: push: tags: - 'v*.*.*' workflow_dispatch: permissions: contents: write jobs: build: # runs-on指定了运行作业的虚拟机环境类型 # 即使使用container,runs-on仍然是必要的配置 runs-on: ubuntu-latest # 移除容器配置以避免Docker Hub拉取超时问题 # 直接在GitHub托管的runner环境中执行任务 steps: - name: Checkout uses: actions/checkout@v4 # 使用最新稳定的v4版本 # GitHub Actions的runner环境通常已预装Go,Setup Go步骤会处理版本管理 - name: Setup Go uses: actions/setup-go@v5 with: go-version: 'stable' # 使用最新稳定版本的Go,无需手动更新版本号 - name: Install gf CLI run: | # 直接下载GF CLI,不使用缓存以避免超时问题 echo "Downloading GF CLI" curl -L -o gf https://github.com/gogf/gf/releases/latest/download/gf_linux_amd64 chmod +x gf mkdir -p "$HOME/bin" mv gf "$HOME/bin/gf" echo "$HOME/bin" >> $GITHUB_PATH - name: Verify gf run: gf -v - name: Build with gf run: gf build -ew -v "${{ github.ref_name }}" - name: Upload build artifacts (GitHub) if: contains(github.server_url, 'github.com') uses: actions/upload-artifact@v4 # GitHub使用v4版本以避免废弃警告 with: name: p2p-${{ github.ref_name }} path: | bin/** - name: Upload build artifacts (Gitea) if: ${{ github.server_url != 'https://github.com' || env.GITEA_ACTIONS == 'true' }} uses: actions/upload-artifact@v3 # Gitea使用v3版本以兼容GHES with: name: p2p-${{ github.ref_name }} path: | bin/** release: needs: build # runs-on指定了运行作业的虚拟机环境类型 # 即使使用container,runs-on仍然是必要的配置 runs-on: ubuntu-latest # 移除容器配置以避免Docker Hub拉取超时问题 # 直接在GitHub托管的runner环境中执行任务 steps: - name: Checkout uses: actions/checkout@v4 - name: Download artifacts (GitHub) if: contains(github.server_url, 'github.com') uses: actions/download-artifact@v4 # GitHub使用v4版本以避免废弃警告 with: name: p2p-${{ github.ref_name }} path: bin - name: Download artifacts (Gitea) if: contains(github.server_url, 'gitea') uses: actions/download-artifact@v3 # Gitea使用v3版本以兼容GHES with: name: p2p-${{ github.ref_name }} path: bin - name: Package artifacts run: | set -euo pipefail mkdir -p dist # Find all built binaries recursively and package with unique names per platform/arch mapfile -t files < <(find bin -type f \( -name 'p2p' -o -name 'p2p.exe' \)) for f in "${files[@]}"; do dir="$(dirname "$f")" base="$(basename "$f")" plat_arch="$(basename "$dir")" # expects linux_amd64, windows_amd64, etc. case "$plat_arch" in windows_*) zip_name="p2p_${{ github.ref_name }}_${plat_arch}.zip" (cd "$dir" && zip -9 "${GITHUB_WORKSPACE}/dist/${zip_name}" "$base") ;; *) tar_name="p2p_${{ github.ref_name }}_${plat_arch}.tar.gz" (cd "$dir" && tar -czf "${GITHUB_WORKSPACE}/dist/${tar_name}" "$base") ;; esac done # Checksums (cd dist && sha256sum * > SHA256SUMS.txt) ls -al dist - name: Create GitHub Release uses: softprops/action-gh-release@v2 # 更新到最新稳定的v2版本 with: token: ${{ secrets.GITHUB_TOKEN }} tag_name: ${{ github.ref_name }} name: ${{ github.ref_name }} draft: false prerelease: false files: | dist/*