|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + build: |
| 13 | + name: Build ${{ matrix.target }} |
| 14 | + runs-on: ${{ matrix.os }} |
| 15 | + timeout-minutes: 30 |
| 16 | + strategy: |
| 17 | + fail-fast: false |
| 18 | + matrix: |
| 19 | + include: |
| 20 | + # Linux x86_64 |
| 21 | + - target: x86_64-unknown-linux-gnu |
| 22 | + os: ubuntu-latest |
| 23 | + artifact_name: componentize-go |
| 24 | + asset_name: componentize-go-linux-amd64 |
| 25 | + # Linux aarch64 |
| 26 | + - target: aarch64-unknown-linux-gnu |
| 27 | + os: ubuntu-latest |
| 28 | + artifact_name: componentize-go |
| 29 | + asset_name: componentize-go-linux-arm64 |
| 30 | + # macOS x86_64 |
| 31 | + - target: x86_64-apple-darwin |
| 32 | + os: macos-latest |
| 33 | + artifact_name: componentize-go |
| 34 | + asset_name: componentize-go-darwin-amd64 |
| 35 | + # macOS aarch64 |
| 36 | + - target: aarch64-apple-darwin |
| 37 | + os: macos-latest |
| 38 | + artifact_name: componentize-go |
| 39 | + asset_name: componentize-go-darwin-arm64 |
| 40 | + # Windows x86_64 |
| 41 | + - target: x86_64-pc-windows-msvc |
| 42 | + os: windows-latest |
| 43 | + artifact_name: componentize-go.exe |
| 44 | + asset_name: componentize-go-windows-amd64 |
| 45 | + |
| 46 | + steps: |
| 47 | + - name: Checkout code |
| 48 | + uses: actions/checkout@v6 |
| 49 | + |
| 50 | + - name: Setup Rust |
| 51 | + uses: dtolnay/rust-toolchain@stable |
| 52 | + with: |
| 53 | + targets: ${{ matrix.target }} |
| 54 | + |
| 55 | + - name: Install cross-compilation tools (Linux aarch64) |
| 56 | + if: matrix.target == 'aarch64-unknown-linux-gnu' |
| 57 | + run: | |
| 58 | + sudo apt-get update |
| 59 | + sudo apt-get install -y gcc-aarch64-linux-gnu |
| 60 | +
|
| 61 | + - name: Cache Rust |
| 62 | + uses: Swatinem/rust-cache@v2 |
| 63 | + with: |
| 64 | + key: ${{ matrix.target }} |
| 65 | + |
| 66 | + - name: Build binary |
| 67 | + run: cargo build --release --target ${{ matrix.target }} |
| 68 | + env: |
| 69 | + CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc |
| 70 | + |
| 71 | + - name: Strip binary (Linux and macOS) |
| 72 | + if: runner.os != 'Windows' |
| 73 | + run: | |
| 74 | + if [ "${{ matrix.target }}" = "aarch64-unknown-linux-gnu" ]; then |
| 75 | + aarch64-linux-gnu-strip target/${{ matrix.target }}/release/${{ matrix.artifact_name }} |
| 76 | + else |
| 77 | + strip target/${{ matrix.target }}/release/${{ matrix.artifact_name }} |
| 78 | + fi |
| 79 | +
|
| 80 | + - name: Upload binary |
| 81 | + uses: actions/upload-artifact@v6 |
| 82 | + with: |
| 83 | + name: ${{ matrix.asset_name }} |
| 84 | + path: target/${{ matrix.target }}/release/${{ matrix.artifact_name }} |
| 85 | + |
| 86 | + release: |
| 87 | + name: Create Release |
| 88 | + needs: build |
| 89 | + runs-on: ubuntu-latest |
| 90 | + timeout-minutes: 10 |
| 91 | + steps: |
| 92 | + - name: Checkout code |
| 93 | + uses: actions/checkout@v6 |
| 94 | + |
| 95 | + - name: Download all artifacts |
| 96 | + uses: actions/download-artifact@v7 |
| 97 | + with: |
| 98 | + path: artifacts |
| 99 | + |
| 100 | + - name: Flatten, rename, and compress artifacts |
| 101 | + run: | |
| 102 | + mkdir -p release |
| 103 | + for dir in artifacts/*/; do |
| 104 | + asset_name=$(basename "$dir") |
| 105 | + binary=$(ls "$dir") |
| 106 | + if [[ "$asset_name" == *windows* ]]; then |
| 107 | + cd "$dir" |
| 108 | + zip -9 "../../release/${asset_name}.zip" "$binary" |
| 109 | + cd ../.. |
| 110 | + else |
| 111 | + cd "$dir" |
| 112 | + tar -czvf "../../release/${asset_name}.tar.gz" "$binary" |
| 113 | + cd ../.. |
| 114 | + fi |
| 115 | + done |
| 116 | +
|
| 117 | + - name: Generate checksums |
| 118 | + run: | |
| 119 | + cd release |
| 120 | + sha256sum * > checksums.txt |
| 121 | +
|
| 122 | + - name: Create Release |
| 123 | + run: gh release create --generate-notes ${{ github.ref_name }} release/* |
| 124 | + env: |
| 125 | + GH_TOKEN: ${{ github.token }} |
0 commit comments