|
| 1 | +name: Build All Platforms |
| 2 | +on: |
| 3 | + workflow_dispatch: |
| 4 | + inputs: |
| 5 | + release_tag: |
| 6 | + description: "Release tag (格式 v1.0.0)" |
| 7 | + required: true |
| 8 | + default: "v1.0.0" |
| 9 | + push: |
| 10 | + tags: |
| 11 | + - "v*" |
| 12 | +permissions: |
| 13 | + contents: write |
| 14 | + actions: read |
| 15 | +jobs: |
| 16 | + build: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + strategy: |
| 19 | + fail-fast: false |
| 20 | + matrix: |
| 21 | + include: |
| 22 | + - goos: android |
| 23 | + goarch: arm64 |
| 24 | + - goos: darwin |
| 25 | + goarch: amd64 |
| 26 | + - goos: darwin |
| 27 | + goarch: arm64 |
| 28 | + - goos: dragonfly |
| 29 | + goarch: amd64 |
| 30 | + - goos: freebsd |
| 31 | + goarch: 386 |
| 32 | + - goos: freebsd |
| 33 | + goarch: amd64 |
| 34 | + - goos: freebsd |
| 35 | + goarch: arm |
| 36 | + - goos: freebsd |
| 37 | + goarch: arm64 |
| 38 | + - goos: linux |
| 39 | + goarch: 386 |
| 40 | + - goos: linux |
| 41 | + goarch: amd64 |
| 42 | + - goos: linux |
| 43 | + goarch: arm |
| 44 | + - goos: linux |
| 45 | + goarch: arm64 |
| 46 | + - goos: linux |
| 47 | + goarch: mips |
| 48 | + - goos: linux |
| 49 | + goarch: mips64 |
| 50 | + - goos: linux |
| 51 | + goarch: mips64le |
| 52 | + - goos: linux |
| 53 | + goarch: mipsle |
| 54 | + - goos: linux |
| 55 | + goarch: ppc64 |
| 56 | + - goos: linux |
| 57 | + goarch: ppc64le |
| 58 | + - goos: linux |
| 59 | + goarch: riscv64 |
| 60 | + - goos: linux |
| 61 | + goarch: s390x |
| 62 | + - goos: netbsd |
| 63 | + goarch: 386 |
| 64 | + - goos: netbsd |
| 65 | + goarch: amd64 |
| 66 | + - goos: netbsd |
| 67 | + goarch: arm |
| 68 | + - goos: netbsd |
| 69 | + goarch: arm64 |
| 70 | + - goos: openbsd |
| 71 | + goarch: 386 |
| 72 | + - goos: openbsd |
| 73 | + goarch: amd64 |
| 74 | + - goos: openbsd |
| 75 | + goarch: arm |
| 76 | + - goos: openbsd |
| 77 | + goarch: arm64 |
| 78 | + - goos: plan9 |
| 79 | + goarch: 386 |
| 80 | + - goos: plan9 |
| 81 | + goarch: amd64 |
| 82 | + - goos: solaris |
| 83 | + goarch: amd64 |
| 84 | + - goos: windows |
| 85 | + goarch: 386 |
| 86 | + ext: ".exe" |
| 87 | + - goos: windows |
| 88 | + goarch: amd64 |
| 89 | + ext: ".exe" |
| 90 | + - goos: windows |
| 91 | + goarch: arm |
| 92 | + ext: ".exe" |
| 93 | + - goos: windows |
| 94 | + goarch: arm64 |
| 95 | + ext: ".exe" |
| 96 | + outputs: # 添加作业输出 |
| 97 | + build_time: ${{ steps.set-build-time.outputs.BUILD_TIME }} |
| 98 | + steps: |
| 99 | + - name: Checkout code |
| 100 | + uses: actions/checkout@v4 |
| 101 | + with: |
| 102 | + fetch-depth: 0 # 获取完整提交历史 |
| 103 | + |
| 104 | + - name: Setup Go |
| 105 | + uses: actions/setup-go@v4 |
| 106 | + with: |
| 107 | + go-version: "1.20" # 根据你的需求设置Go版本 |
| 108 | + cache: false |
| 109 | + |
| 110 | + - name: Create Release Assets Directory |
| 111 | + run: mkdir -p "${{ github.workspace }}/release_assets" |
| 112 | + |
| 113 | + - name: Set Build Time |
| 114 | + id: set-build-time # 给步骤设置ID |
| 115 | + run: | |
| 116 | + build_time=$(date -u +'%Y-%m-%d %H:%M:%S UTC') |
| 117 | + echo "BUILD_TIME=$build_time" >> $GITHUB_OUTPUT |
| 118 | +
|
| 119 | + - name: Build |
| 120 | + run: | |
| 121 | + echo "Building cfdata-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.ext || '' }} from cfdata.go..." |
| 122 | + go build -o ${{ github.workspace }}/release_assets/cfdata-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.ext || '' }} cfdata.go |
| 123 | + env: |
| 124 | + GOARCH: ${{ matrix.goarch }} |
| 125 | + GOOS: ${{ matrix.goos }} |
| 126 | + |
| 127 | + - name: Generate SHA256 |
| 128 | + run: | |
| 129 | + cd "${{ github.workspace }}/release_assets" |
| 130 | + for file in $(find . -type f ! -name '*.sha256'); do |
| 131 | + sha256sum "$file" | awk '{print $1}' > "${file}.sha256" |
| 132 | + done |
| 133 | + echo "SHA256 files generated:" |
| 134 | + ls -1 *.sha256 |
| 135 | +
|
| 136 | + - name: Upload Artifact |
| 137 | + uses: actions/upload-artifact@v4 |
| 138 | + with: |
| 139 | + name: cfdata-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.ext || '' }} |
| 140 | + path: ${{ github.workspace }}/release_assets/* |
| 141 | + |
| 142 | + release: |
| 143 | + name: Release |
| 144 | + needs: build |
| 145 | + runs-on: ubuntu-latest |
| 146 | + steps: |
| 147 | + - name: Checkout code |
| 148 | + uses: actions/download-artifact@v4 |
| 149 | + with: |
| 150 | + path: artifacts |
| 151 | + |
| 152 | + - name: Move Release Assets |
| 153 | + run: | |
| 154 | + mkdir -p release_assets |
| 155 | + find artifacts -type f ! -name "*.txt" -exec mv {} release_assets/ \; |
| 156 | + echo "Files to release:" |
| 157 | + ls -lh release_assets/ |
| 158 | +
|
| 159 | + - name: Create Release |
| 160 | + uses: softprops/action-gh-release@v2 |
| 161 | + with: |
| 162 | + tag_name: ${{ github.event.inputs.release_tag || github.ref_name }} |
| 163 | + name: "Release ${{ github.event.inputs.release_tag || github.ref_name }}" |
| 164 | + body: | |
| 165 | + ## 多平台构建版本 |
| 166 | + **构建时间:** ${{ needs.build.outputs.build_time }} |
| 167 | +
|
| 168 | + 完整变更日志: |
| 169 | + https://github.com/Kwisma/cfdata/commits/${{ github.event.inputs.release_tag || github.ref_name }} |
| 170 | + files: | |
| 171 | + ${{ github.workspace }}/release_assets/* |
| 172 | + draft: false |
| 173 | + prerelease: ${{ contains(github.event.inputs.release_tag, '-rc') || contains(github.ref_name, '-rc') }} |
| 174 | + generate_release_notes: true |
| 175 | + fail_on_unmatched_files: true |
| 176 | + env: |
| 177 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments