|
| 1 | +name: 'Release 打包' |
| 2 | +on: |
| 3 | + workflow_dispatch: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' |
| 7 | + release: |
| 8 | + types: [published, released] |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: write |
| 12 | + |
| 13 | +jobs: |
| 14 | + build: |
| 15 | + name: '构建 ${{ matrix.target }}' |
| 16 | + runs-on: ubuntu-latest |
| 17 | + strategy: |
| 18 | + fail-fast: false |
| 19 | + matrix: |
| 20 | + include: |
| 21 | + - { target: linux-amd64, goos: linux, goarch: amd64, ext: '' } |
| 22 | + - { target: linux-arm64, goos: linux, goarch: arm64, ext: '' } |
| 23 | + - { target: darwin-amd64, goos: darwin, goarch: amd64, ext: '' } |
| 24 | + - { target: darwin-arm64, goos: darwin, goarch: arm64, ext: '' } |
| 25 | + - { target: windows-amd64, goos: windows, goarch: amd64, ext: .exe } |
| 26 | + - { target: windows-arm64, goos: windows, goarch: arm64, ext: .exe } |
| 27 | + steps: |
| 28 | + - uses: actions/checkout@v4 |
| 29 | + - uses: actions/setup-go@v5 |
| 30 | + with: |
| 31 | + go-version: '1.26' |
| 32 | + - name: '编译 ${{ matrix.target }}' |
| 33 | + run: | |
| 34 | + mkdir -p dist |
| 35 | + CGO_ENABLED=0 GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} \ |
| 36 | + go build -trimpath -ldflags="-s -w" -o dist/simplewebshell-remoteupdate${{ matrix.ext }} . |
| 37 | + - name: '打包' |
| 38 | + run: | |
| 39 | + cd dist |
| 40 | + if [ "${{ matrix.goos }}" = "windows" ]; then |
| 41 | + zip -qr ../simplewebshell-remoteupdate-${{ matrix.target }}.zip simplewebshell-remoteupdate.exe |
| 42 | + else |
| 43 | + tar czf ../simplewebshell-remoteupdate-${{ matrix.target }}.tar.gz simplewebshell-remoteupdate |
| 44 | + fi |
| 45 | + - uses: actions/upload-artifact@v4 |
| 46 | + with: |
| 47 | + name: 'simplewebshell-remoteupdate-${{ matrix.target }}' |
| 48 | + path: '${{ github.workspace }}/simplewebshell-remoteupdate-${{ matrix.target }}.*' |
| 49 | + if-no-files-found: 'error' |
| 50 | + retention-days: 1 |
| 51 | + |
| 52 | + release: |
| 53 | + name: '发布 GitHub Release' |
| 54 | + needs: build |
| 55 | + runs-on: ubuntu-latest |
| 56 | + steps: |
| 57 | + - uses: actions/download-artifact@v4 |
| 58 | + with: |
| 59 | + path: artifacts |
| 60 | + merge-multiple: true |
| 61 | + - name: '整理产物' |
| 62 | + run: | |
| 63 | + mkdir -p release |
| 64 | + find artifacts -type f \( -name '*.tar.gz' -o -name '*.zip' \) -exec cp {} release/ \; |
| 65 | + - name: '生成 MD5/SHA1 校验文件' |
| 66 | + run: | |
| 67 | + set -euo pipefail |
| 68 | + cd release |
| 69 | + find . -type f ! -name 'checksums-md5.txt' ! -name 'checksums-sha1.txt' -print0 \ |
| 70 | + | sort -z | xargs -0 -r md5sum > checksums-md5.txt |
| 71 | + find . -type f ! -name 'checksums-md5.txt' ! -name 'checksums-sha1.txt' -print0 \ |
| 72 | + | sort -z | xargs -0 -r sha1sum > checksums-sha1.txt |
| 73 | + - name: '上传到 Release' |
| 74 | + if: github.event_name != 'workflow_dispatch' || github.event.inputs.tag != '' |
| 75 | + uses: softprops/action-gh-release@v2 |
| 76 | + with: |
| 77 | + tag_name: ${{ github.event.inputs.tag || github.event.release.tag_name || github.ref_name }} |
| 78 | + files: 'release/*' |
| 79 | + generate_release_notes: true |
| 80 | + fail_on_unmatched_files: false |
0 commit comments