|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + go-build: |
| 13 | + name: Go Release Artifacts |
| 14 | + runs-on: ${{ matrix.os }} |
| 15 | + strategy: |
| 16 | + fail-fast: false |
| 17 | + matrix: |
| 18 | + os: [ubuntu-latest, macos-latest, windows-latest] |
| 19 | + defaults: |
| 20 | + run: |
| 21 | + working-directory: go |
| 22 | + steps: |
| 23 | + - uses: actions/checkout@v4 |
| 24 | + - uses: actions/setup-go@v5 |
| 25 | + with: |
| 26 | + go-version: stable |
| 27 | + cache: true |
| 28 | + |
| 29 | + - name: Build (native) |
| 30 | + run: go build ./cmd/gzip-go |
| 31 | + |
| 32 | + - name: Package (Linux/macOS) |
| 33 | + if: runner.os != 'Windows' |
| 34 | + shell: bash |
| 35 | + run: | |
| 36 | + set -euo pipefail |
| 37 | + VERSION="${GITHUB_REF_NAME}" |
| 38 | + GOOS=$(go env GOOS) |
| 39 | + GOARCH=$(go env GOARCH) |
| 40 | + DIST="${GITHUB_WORKSPACE}/dist" |
| 41 | + mkdir -p "$DIST" |
| 42 | + BIN="gzip-go" |
| 43 | + TAR="${DIST}/gzip-go_${VERSION}_${GOOS}_${GOARCH}.tar.gz" |
| 44 | + tar -C . -czf "$TAR" "$BIN" |
| 45 | +
|
| 46 | + - name: Package (Windows) |
| 47 | + if: runner.os == 'Windows' |
| 48 | + shell: pwsh |
| 49 | + run: | |
| 50 | + $ErrorActionPreference = "Stop" |
| 51 | + $version = "$env:GITHUB_REF_NAME" |
| 52 | + $goos = & go env GOOS |
| 53 | + $goarch = & go env GOARCH |
| 54 | + $dist = Join-Path $env:GITHUB_WORKSPACE "dist" |
| 55 | + New-Item -ItemType Directory -Force -Path $dist | Out-Null |
| 56 | + $bin = "gzip-go.exe" |
| 57 | + $zip = Join-Path $dist ("gzip-go_{0}_{1}_{2}.zip" -f $version, $goos, $goarch) |
| 58 | + Compress-Archive -Path $bin -DestinationPath $zip -Force |
| 59 | +
|
| 60 | + - name: Upload artifact |
| 61 | + uses: actions/upload-artifact@v4 |
| 62 | + with: |
| 63 | + name: go-${{ runner.os }} |
| 64 | + path: ${{ github.workspace }}/dist/* |
| 65 | + |
| 66 | + rust-build: |
| 67 | + name: Rust Release Artifacts |
| 68 | + runs-on: ${{ matrix.os }} |
| 69 | + strategy: |
| 70 | + fail-fast: false |
| 71 | + matrix: |
| 72 | + os: [ubuntu-latest, macos-latest, windows-latest] |
| 73 | + defaults: |
| 74 | + run: |
| 75 | + working-directory: rust |
| 76 | + steps: |
| 77 | + - uses: actions/checkout@v4 |
| 78 | + - uses: dtolnay/rust-toolchain@stable |
| 79 | + |
| 80 | + - name: Build (native) |
| 81 | + run: cargo build --release --locked |
| 82 | + |
| 83 | + - name: Package (Linux/macOS) |
| 84 | + if: runner.os != 'Windows' |
| 85 | + shell: bash |
| 86 | + run: | |
| 87 | + set -euo pipefail |
| 88 | + VERSION="${GITHUB_REF_NAME}" |
| 89 | + DIST="${GITHUB_WORKSPACE}/dist" |
| 90 | + mkdir -p "$DIST" |
| 91 | + OS=$(uname -s | tr '[:upper:]' '[:lower:]') |
| 92 | + ARCH=$(uname -m) |
| 93 | + case "$ARCH" in x86_64) ARCH=amd64 ;; aarch64) ARCH=arm64 ;; arm64) ARCH=arm64 ;; esac |
| 94 | + TAR="${DIST}/rgzip_${VERSION}_${OS}_${ARCH}.tar.gz" |
| 95 | + tar -C target/release -czf "$TAR" rgzip |
| 96 | +
|
| 97 | + - name: Package (Windows) |
| 98 | + if: runner.os == 'Windows' |
| 99 | + shell: pwsh |
| 100 | + run: | |
| 101 | + $ErrorActionPreference = "Stop" |
| 102 | + $version = "$env:GITHUB_REF_NAME" |
| 103 | + $os = "windows" |
| 104 | + $arch = "amd64" |
| 105 | + $dist = Join-Path $env:GITHUB_WORKSPACE "dist" |
| 106 | + New-Item -ItemType Directory -Force -Path $dist | Out-Null |
| 107 | + $exe = "target/release/rgzip.exe" |
| 108 | + $zip = Join-Path $dist ("rgzip_{0}_{1}_{2}.zip" -f $version, $os, $arch) |
| 109 | + Compress-Archive -Path $exe -DestinationPath $zip -Force |
| 110 | +
|
| 111 | + - name: Upload artifact |
| 112 | + uses: actions/upload-artifact@v4 |
| 113 | + with: |
| 114 | + name: rust-${{ runner.os }} |
| 115 | + path: ${{ github.workspace }}/dist/* |
| 116 | + |
| 117 | + publish: |
| 118 | + name: Publish GitHub Release |
| 119 | + runs-on: ubuntu-latest |
| 120 | + needs: [go-build, rust-build] |
| 121 | + steps: |
| 122 | + - name: Download all artifacts |
| 123 | + uses: actions/download-artifact@v4 |
| 124 | + with: |
| 125 | + path: dist |
| 126 | + merge-multiple: true |
| 127 | + |
| 128 | + - name: Generate SHA256SUMS |
| 129 | + run: | |
| 130 | + set -euo pipefail |
| 131 | + cd dist |
| 132 | + shopt -s nullglob |
| 133 | + files=( *.zip *.tar.gz ) |
| 134 | + if [ ${#files[@]} -gt 0 ]; then |
| 135 | + sha256sum "${files[@]}" > SHA256SUMS |
| 136 | + else |
| 137 | + echo "No artifacts to checksum" >&2 |
| 138 | + fi |
| 139 | +
|
| 140 | + - name: Create GitHub Release and upload assets |
| 141 | + uses: softprops/action-gh-release@v2 |
| 142 | + with: |
| 143 | + tag_name: ${{ github.ref_name }} |
| 144 | + name: ${{ github.ref_name }} |
| 145 | + draft: false |
| 146 | + prerelease: ${{ contains(github.ref_name, '-') }} |
| 147 | + files: | |
| 148 | + dist/*.zip |
| 149 | + dist/*.tar.gz |
| 150 | + dist/SHA256SUMS |
0 commit comments