|
| 1 | +name: Build Release |
| 2 | + |
| 3 | +on: |
| 4 | + # This will trigger when a tag like v1.0.0 is pushed |
| 5 | + # will create a release |
| 6 | + push: |
| 7 | + tags: |
| 8 | + - "v*.*.*" |
| 9 | + # Manual trigger for creating an artifact (button in the UI) |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +permissions: |
| 13 | + packages: write |
| 14 | + contents: write |
| 15 | + |
| 16 | +jobs: |
| 17 | + build-linux: |
| 18 | + name: Build Linux targets |
| 19 | + runs-on: ubuntu-latest |
| 20 | + strategy: |
| 21 | + matrix: |
| 22 | + include: |
| 23 | + - target: x86_64-unknown-linux-musl |
| 24 | + os_name: linux-musl |
| 25 | + arch: x86_64 |
| 26 | + filename: pocket-relay-x86_64-linux-musl |
| 27 | + |
| 28 | + - target: x86_64-unknown-linux-gnu |
| 29 | + os_name: linux-gnu |
| 30 | + arch: x86_64 |
| 31 | + filename: pocket-relay-x86_64-linux-gnu |
| 32 | + |
| 33 | + - target: aarch64-unknown-linux-musl |
| 34 | + os_name: linux-musl |
| 35 | + arch: aarch64 |
| 36 | + filename: pocket-relay-aarch64-linux-musl |
| 37 | + |
| 38 | + - target: aarch64-unknown-linux-gnu |
| 39 | + os_name: linux-gnu |
| 40 | + arch: aarch64 |
| 41 | + filename: pocket-relay-aarch64-linux-gnu |
| 42 | + |
| 43 | + steps: |
| 44 | + # Checkout the repo for building |
| 45 | + - uses: actions/checkout@v4 |
| 46 | + |
| 47 | + # Setup rust for building the service |
| 48 | + - name: Set up Rust |
| 49 | + uses: dtolnay/rust-toolchain@stable |
| 50 | + with: |
| 51 | + toolchain: stable |
| 52 | + targets: ${{ matrix.target }} |
| 53 | + override: true |
| 54 | + |
| 55 | + # Cache Rust dependencies and build artifacts |
| 56 | + - name: Cache Rust dependencies |
| 57 | + id: cache-rust |
| 58 | + uses: actions/cache@v4 |
| 59 | + with: |
| 60 | + path: | |
| 61 | + ~/.cargo/bin/ |
| 62 | + ~/.cargo/registry/index/ |
| 63 | + ~/.cargo/registry/cache/ |
| 64 | + ~/.cargo/git/db/ |
| 65 | + target/ |
| 66 | + key: ${{ runner.os }}-${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }} |
| 67 | + restore-keys: | |
| 68 | + ${{ runner.os }}-${{ matrix.target }}-cargo- |
| 69 | +
|
| 70 | + # Install cross for cross compiling |
| 71 | + - name: Install cross |
| 72 | + if: steps.cache-rust.outputs.cache-hit != 'true' |
| 73 | + run: cargo install cross |
| 74 | + |
| 75 | + # Cross compile the binary |
| 76 | + - name: Build with ${{ matrix.target }} |
| 77 | + run: cross build --release --target ${{ matrix.target }} -p pocket-relay |
| 78 | + |
| 79 | + # Copy built binary to output directory |
| 80 | + - name: Copy binary to output |
| 81 | + run: cp target/${{ matrix.target }}/release/pocket-relay ${{ matrix.filename }} |
| 82 | + shell: bash |
| 83 | + |
| 84 | + # Upload the built artifact |
| 85 | + - name: Upload artifact |
| 86 | + uses: actions/upload-artifact@v4 |
| 87 | + with: |
| 88 | + name: ${{ matrix.filename }} |
| 89 | + path: ${{ matrix.filename }} |
| 90 | + |
| 91 | + build-windows: |
| 92 | + name: Build Windows targets |
| 93 | + runs-on: windows-latest |
| 94 | + strategy: |
| 95 | + matrix: |
| 96 | + include: |
| 97 | + - target: x86_64-pc-windows-gnu |
| 98 | + os_name: windows-gnu |
| 99 | + arch: x86_64 |
| 100 | + filename: pocket-relay-x86_64-windows-gnu.exe |
| 101 | + |
| 102 | + - target: x86_64-pc-windows-msvc |
| 103 | + os_name: windows-msvc |
| 104 | + arch: x86_64 |
| 105 | + filename: pocket-relay-x86_64-windows-msvc.exe |
| 106 | + |
| 107 | + steps: |
| 108 | + # Checkout the repo for building |
| 109 | + - uses: actions/checkout@v4 |
| 110 | + |
| 111 | + # Setup rust for building the service |
| 112 | + - name: Install Rust |
| 113 | + uses: dtolnay/rust-toolchain@stable |
| 114 | + with: |
| 115 | + targets: ${{ matrix.target }} |
| 116 | + |
| 117 | + # Cache Rust dependencies and build artifacts |
| 118 | + - name: Cache Rust dependencies |
| 119 | + uses: actions/cache@v4 |
| 120 | + with: |
| 121 | + path: | |
| 122 | + ~/.cargo/bin/ |
| 123 | + ~/.cargo/registry/index/ |
| 124 | + ~/.cargo/registry/cache/ |
| 125 | + ~/.cargo/git/db/ |
| 126 | + target/ |
| 127 | + key: ${{ runner.os }}-${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }} |
| 128 | + restore-keys: | |
| 129 | + ${{ runner.os }}-${{ matrix.target }}-cargo- |
| 130 | +
|
| 131 | + # Cross compile the binary |
| 132 | + - name: Build |
| 133 | + run: cargo build --release --target ${{ matrix.target }} -p pocket-relay |
| 134 | + |
| 135 | + # Copy built binary to output directory |
| 136 | + - name: Rename and move output binary |
| 137 | + run: cp target/${{ matrix.target }}/release/pocket-relay.exe ${{ matrix.filename }} |
| 138 | + shell: bash |
| 139 | + |
| 140 | + # Prepare signing certificate |
| 141 | + - name: Decode and save certificate |
| 142 | + run: echo "${{ secrets.SIGNING_CERT_BASE64 }}" | base64 -d > cert.pfx |
| 143 | + shell: bash |
| 144 | + |
| 145 | + # Sign binary |
| 146 | + - name: Sign binary |
| 147 | + run: signtool sign /tr http://timestamp.digicert.com /td sha256 /fd SHA256 /f cert.pfx /p "${{ secrets.SIGNING_CERT_PASSWORD }}" ${{ matrix.filename }} |
| 148 | + shell: bash |
| 149 | + |
| 150 | + # Upload the built artifact |
| 151 | + - name: Upload binary artifact |
| 152 | + uses: actions/upload-artifact@v4 |
| 153 | + with: |
| 154 | + name: ${{ matrix.filename }} |
| 155 | + path: ${{ matrix.filename }} |
| 156 | + |
| 157 | + release: |
| 158 | + name: Create Release |
| 159 | + runs-on: ubuntu-latest |
| 160 | + needs: [build-linux, build-windows] |
| 161 | + |
| 162 | + steps: |
| 163 | + # Checkout the repo |
| 164 | + - uses: actions/checkout@v4 |
| 165 | + |
| 166 | + # Download all the compiled artifacts from previous |
| 167 | + # steps |
| 168 | + - name: Download all build artifacts |
| 169 | + uses: actions/download-artifact@v4 |
| 170 | + with: |
| 171 | + path: dist |
| 172 | + merge-multiple: true |
| 173 | + |
| 174 | + # Create the github release if we pushed up a new tag |
| 175 | + - name: Create GitHub Release |
| 176 | + uses: softprops/action-gh-release@v2 |
| 177 | + if: github.event_name == 'push' |
| 178 | + with: |
| 179 | + tag_name: ${{ github.ref_name }} |
| 180 | + name: ${{ github.ref_name }} |
| 181 | + draft: true |
| 182 | + files: dist/* |
| 183 | + env: |
| 184 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments