|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: read |
| 10 | + |
| 11 | +env: |
| 12 | + CARGO_TERM_COLOR: always |
| 13 | + |
| 14 | +jobs: |
| 15 | + build: |
| 16 | + name: Build ${{ matrix.target }} |
| 17 | + runs-on: ${{ matrix.runner }} |
| 18 | + strategy: |
| 19 | + fail-fast: false |
| 20 | + matrix: |
| 21 | + include: |
| 22 | + - runner: ubuntu-24.04 |
| 23 | + target: x86_64-unknown-linux-gnu |
| 24 | + binary_name: pacman |
| 25 | + asset_ext: tar.gz |
| 26 | + - runner: ubuntu-24.04-arm |
| 27 | + target: aarch64-unknown-linux-gnu |
| 28 | + binary_name: pacman |
| 29 | + asset_ext: tar.gz |
| 30 | + - runner: windows-2025 |
| 31 | + target: x86_64-pc-windows-msvc |
| 32 | + binary_name: pacman.exe |
| 33 | + asset_ext: exe |
| 34 | + - runner: macos-15 |
| 35 | + target: aarch64-apple-darwin |
| 36 | + binary_name: pacman |
| 37 | + asset_ext: tar.gz |
| 38 | + |
| 39 | + steps: |
| 40 | + - name: Check out repository |
| 41 | + uses: actions/checkout@v6 |
| 42 | + with: |
| 43 | + fetch-depth: 0 |
| 44 | + |
| 45 | + - name: Install Linux build dependencies |
| 46 | + if: runner.os == 'Linux' |
| 47 | + run: sudo apt-get update && sudo apt-get install -y libasound2-dev |
| 48 | + |
| 49 | + - name: Set up Rust |
| 50 | + uses: dtolnay/rust-toolchain@stable |
| 51 | + |
| 52 | + - name: Add target |
| 53 | + run: rustup target add ${{ matrix.target }} |
| 54 | + |
| 55 | + - name: Build release binary |
| 56 | + run: cargo build --locked --release --bin pacman --target ${{ matrix.target }} |
| 57 | + |
| 58 | + - name: Compute asset name |
| 59 | + id: asset |
| 60 | + shell: bash |
| 61 | + run: echo "name=pacman-${GITHUB_REF_NAME}-${{ matrix.target }}.${{ matrix.asset_ext }}" >> "$GITHUB_OUTPUT" |
| 62 | + |
| 63 | + - name: Package Unix archive |
| 64 | + if: runner.os != 'Windows' |
| 65 | + shell: bash |
| 66 | + run: | |
| 67 | + set -euo pipefail |
| 68 | + mkdir -p dist |
| 69 | + tar -C "target/${{ matrix.target }}/release" -czf "dist/${{ steps.asset.outputs.name }}" "${{ matrix.binary_name }}" |
| 70 | +
|
| 71 | + - name: Package Windows archive |
| 72 | + if: runner.os == 'Windows' |
| 73 | + shell: pwsh |
| 74 | + run: | |
| 75 | + New-Item -ItemType Directory -Force -Path dist | Out-Null |
| 76 | + Copy-Item "target\${{ matrix.target }}\release\${{ matrix.binary_name }}" "dist\${{ steps.asset.outputs.name }}" |
| 77 | +
|
| 78 | + - name: Upload packaged binary |
| 79 | + uses: actions/upload-artifact@v4 |
| 80 | + with: |
| 81 | + name: ${{ steps.asset.outputs.name }} |
| 82 | + path: dist/${{ steps.asset.outputs.name }} |
| 83 | + if-no-files-found: error |
| 84 | + |
| 85 | + release: |
| 86 | + name: Publish GitHub Release |
| 87 | + runs-on: ubuntu-24.04 |
| 88 | + needs: build |
| 89 | + permissions: |
| 90 | + actions: read |
| 91 | + contents: write |
| 92 | + env: |
| 93 | + GH_REPO: ${{ github.repository }} |
| 94 | + GH_TOKEN: ${{ github.token }} |
| 95 | + steps: |
| 96 | + - name: Download packaged binaries |
| 97 | + uses: actions/download-artifact@v5 |
| 98 | + with: |
| 99 | + path: dist |
| 100 | + |
| 101 | + - name: Create or update release |
| 102 | + shell: bash |
| 103 | + run: | |
| 104 | + set -euo pipefail |
| 105 | + tag="${GITHUB_REF_NAME}" |
| 106 | + mapfile -t assets < <(find dist -type f | sort) |
| 107 | +
|
| 108 | + if [ "${#assets[@]}" -eq 0 ]; then |
| 109 | + echo "No release assets were downloaded" >&2 |
| 110 | + exit 1 |
| 111 | + fi |
| 112 | +
|
| 113 | + checksum_file="dist/pacman-${tag}-SHA256SUMS.txt" |
| 114 | + : > "$checksum_file" |
| 115 | + for asset in "${assets[@]}"; do |
| 116 | + printf "%s %s\n" "$(sha256sum "$asset" | cut -d' ' -f1)" "$(basename "$asset")" >> "$checksum_file" |
| 117 | + done |
| 118 | + assets+=("$checksum_file") |
| 119 | +
|
| 120 | + if gh release view "$tag" >/dev/null 2>&1; then |
| 121 | + gh release upload "$tag" "${assets[@]}" --clobber |
| 122 | + else |
| 123 | + gh release create "$tag" "${assets[@]}" --verify-tag --generate-notes |
| 124 | + fi |
0 commit comments