|
| 1 | +name: "Build" |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + platform: |
| 7 | + required: true |
| 8 | + type: string |
| 9 | + target: |
| 10 | + required: true |
| 11 | + type: string |
| 12 | + build-args: |
| 13 | + required: false |
| 14 | + type: string |
| 15 | + default: "" |
| 16 | + release-id: |
| 17 | + required: false |
| 18 | + type: string |
| 19 | + asset-prefix: |
| 20 | + required: false |
| 21 | + type: string |
| 22 | + default: "handy" |
| 23 | + upload-artifacts: |
| 24 | + required: false |
| 25 | + type: boolean |
| 26 | + default: false |
| 27 | + sign-binaries: |
| 28 | + required: false |
| 29 | + type: boolean |
| 30 | + default: false |
| 31 | + repository: |
| 32 | + required: false |
| 33 | + type: string |
| 34 | + ref: |
| 35 | + required: false |
| 36 | + type: string |
| 37 | + default: ${{ github.ref }} |
| 38 | + |
| 39 | +jobs: |
| 40 | + build: |
| 41 | + permissions: |
| 42 | + contents: write |
| 43 | + runs-on: ${{ inputs.platform }} |
| 44 | + steps: |
| 45 | + - name: Checkout repository |
| 46 | + uses: actions/checkout@v4 |
| 47 | + with: |
| 48 | + repository: ${{ inputs.repository }} |
| 49 | + ref: ${{ inputs.ref }} |
| 50 | + fetch-depth: 0 |
| 51 | + |
| 52 | + - name: Determine Version |
| 53 | + id: determine-version |
| 54 | + shell: bash |
| 55 | + run: | |
| 56 | + APP_VERSION="" |
| 57 | + REF="${{ inputs.ref }}" |
| 58 | +
|
| 59 | + if [[ "$REF" == refs/tags/v* ]]; then |
| 60 | + APP_VERSION="${REF#refs/tags/v}" |
| 61 | + echo "Release version determined from tag: $APP_VERSION" |
| 62 | + else |
| 63 | + DESCRIBE=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") |
| 64 | + APP_VERSION="${DESCRIBE#v}" |
| 65 | + echo "CI version determined from latest tag or fallback: $APP_VERSION" |
| 66 | + fi |
| 67 | +
|
| 68 | + echo "version=${APP_VERSION}" >> "$GITHUB_OUTPUT" |
| 69 | +
|
| 70 | + - uses: oven-sh/setup-bun@v2 |
| 71 | + |
| 72 | + - name: install Rust stable |
| 73 | + uses: dtolnay/rust-toolchain@stable |
| 74 | + with: |
| 75 | + # Those targets are only used on macos runners so it's in an `if` to slightly speed up windows and linux builds. |
| 76 | + targets: ${{ contains(inputs.platform, 'macos') && 'aarch64-apple-darwin,x86_64-apple-darwin' || '' }} |
| 77 | + |
| 78 | + - name: Rust cache |
| 79 | + uses: swatinem/rust-cache@v2 |
| 80 | + with: |
| 81 | + workspaces: "./src-tauri -> target" |
| 82 | + key: ${{ inputs.platform }}-${{ inputs.target }} |
| 83 | + |
| 84 | + - name: install dependencies (ubuntu only) |
| 85 | + if: contains(inputs.platform, 'ubuntu') |
| 86 | + run: | |
| 87 | + sudo apt-get update |
| 88 | + sudo apt-get install -y libappindicator3-dev librsvg2-dev patchelf libasound2-dev libopenblas-dev libx11-dev libxtst-dev libxrandr-dev \ |
| 89 | + libwebkit2gtk-4.1-0=2.44.0-2 \ |
| 90 | + libwebkit2gtk-4.1-dev=2.44.0-2 \ |
| 91 | + libjavascriptcoregtk-4.1-0=2.44.0-2 \ |
| 92 | + libjavascriptcoregtk-4.1-dev=2.44.0-2 \ |
| 93 | + gir1.2-javascriptcoregtk-4.1=2.44.0-2 \ |
| 94 | + gir1.2-webkit2-4.1=2.44.0-2 |
| 95 | +
|
| 96 | + - name: Install Vulkan SDK (Windows) |
| 97 | + if: contains(inputs.platform, 'windows') |
| 98 | + |
| 99 | + with: |
| 100 | + version: 1.4.309.0 |
| 101 | + cache: true |
| 102 | + |
| 103 | + - name: Install trusted-signing-cli |
| 104 | + if: contains(inputs.platform, 'windows') && inputs.sign-binaries |
| 105 | + run: cargo install trusted-signing-cli |
| 106 | + |
| 107 | + - name: Prepare Vulkan SDK for Ubuntu |
| 108 | + if: contains(inputs.platform, 'ubuntu') |
| 109 | + run: | |
| 110 | + wget -qO- https://packages.lunarg.com/lunarg-signing-key-pub.asc | sudo tee /etc/apt/trusted.gpg.d/lunarg.asc |
| 111 | + sudo wget -qO /etc/apt/sources.list.d/lunarg-vulkan-1.3.290-noble.list https://packages.lunarg.com/vulkan/1.3.290/lunarg-vulkan-1.3.290-noble.list |
| 112 | + sudo apt update |
| 113 | + sudo apt install vulkan-sdk -y |
| 114 | + sudo apt-get install -y mesa-vulkan-drivers |
| 115 | +
|
| 116 | + - name: install frontend dependencies |
| 117 | + run: bun install |
| 118 | + |
| 119 | + - name: rustup install target |
| 120 | + if: ${{ inputs.target != '' && !contains(inputs.target, 'unknown-linux-gnu') && !contains(inputs.target, 'pc-windows-msvc') }} |
| 121 | + run: rustup target add ${{ inputs.target }} |
| 122 | + |
| 123 | + - name: import Apple Developer Certificate |
| 124 | + if: contains(inputs.platform, 'macos') && inputs.sign-binaries |
| 125 | + env: |
| 126 | + APPLE_CERTIFICATE: ${{ secrets.APPLE_CERTIFICATE }} |
| 127 | + APPLE_CERTIFICATE_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }} |
| 128 | + KEYCHAIN_PASSWORD: ${{ secrets.KEYCHAIN_PASSWORD }} |
| 129 | + run: | |
| 130 | + echo $APPLE_CERTIFICATE | base64 --decode > certificate.p12 |
| 131 | + security create-keychain -p "$KEYCHAIN_PASSWORD" build.keychain |
| 132 | + security default-keychain -s build.keychain |
| 133 | + security unlock-keychain -p "$KEYCHAIN_PASSWORD" build.keychain |
| 134 | + security set-keychain-settings -t 3600 -u build.keychain |
| 135 | + security import certificate.p12 -k build.keychain -P "$APPLE_CERTIFICATE_PASSWORD" -T /usr/bin/codesign |
| 136 | + security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$KEYCHAIN_PASSWORD" build.keychain |
| 137 | + security find-identity -v -p codesigning build.keychain |
| 138 | +
|
| 139 | + - name: verify certificate |
| 140 | + if: contains(inputs.platform, 'macos') && inputs.sign-binaries |
| 141 | + run: | |
| 142 | + CERT_INFO=$(security find-identity -v -p codesigning build.keychain | grep "Developer ID Application") |
| 143 | + CERT_ID=$(echo "$CERT_INFO" | awk -F'"' '{print $2}') |
| 144 | + echo "CERT_ID=$CERT_ID" >> $GITHUB_ENV |
| 145 | + echo "Certificate imported." |
| 146 | +
|
| 147 | + - name: Set application version |
| 148 | + shell: bash |
| 149 | + run: | |
| 150 | + echo "Setting version to: ${{ steps.determine-version.outputs.version }}" |
| 151 | + # Update version in tauri.conf.json |
| 152 | + sed -i.bak 's/"version": "[^"]*"/"version": "${{ steps.determine-version.outputs.version }}"/' src-tauri/tauri.conf.json |
| 153 | +
|
| 154 | + - name: Build with Tauri |
| 155 | + uses: tauri-apps/tauri-action@v0 |
| 156 | + env: |
| 157 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 158 | + APPLE_ID: ${{ inputs.sign-binaries && secrets.APPLE_ID || '' }} |
| 159 | + APPLE_ID_PASSWORD: ${{ inputs.sign-binaries && secrets.APPLE_ID_PASSWORD || '' }} |
| 160 | + APPLE_PASSWORD: ${{ inputs.sign-binaries && secrets.APPLE_PASSWORD || '' }} |
| 161 | + APPLE_TEAM_ID: ${{ inputs.sign-binaries && secrets.APPLE_TEAM_ID || '' }} |
| 162 | + APPLE_CERTIFICATE: ${{ inputs.sign-binaries && secrets.APPLE_CERTIFICATE || '' }} |
| 163 | + APPLE_CERTIFICATE_PASSWORD: ${{ inputs.sign-binaries && secrets.APPLE_CERTIFICATE_PASSWORD || '' }} |
| 164 | + APPLE_SIGNING_IDENTITY: ${{ inputs.sign-binaries && env.CERT_ID || '' }} |
| 165 | + AZURE_CLIENT_ID: ${{ inputs.sign-binaries && secrets.AZURE_CLIENT_ID || '' }} |
| 166 | + AZURE_CLIENT_SECRET: ${{ inputs.sign-binaries && secrets.AZURE_CLIENT_SECRET || '' }} |
| 167 | + AZURE_TENANT_ID: ${{ inputs.sign-binaries && secrets.AZURE_TENANT_ID || '' }} |
| 168 | + TAURI_SIGNING_PRIVATE_KEY: ${{ inputs.sign-binaries && secrets.TAURI_SIGNING_PRIVATE_KEY || '' }} |
| 169 | + TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ inputs.sign-binaries && secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD || '' }} |
| 170 | + with: |
| 171 | + tagName: ${{ inputs.release-id && format('v{0}', steps.determine-version.outputs.version) || '' }} |
| 172 | + releaseName: ${{ inputs.release-id && format('v{0}', steps.determine-version.outputs.version) || '' }} |
| 173 | + releaseId: ${{ inputs.release-id }} |
| 174 | + args: ${{ inputs.build-args }} |
| 175 | + |
| 176 | + - name: Upload artifacts (macOS) |
| 177 | + if: inputs.upload-artifacts && contains(inputs.platform, 'macos') |
| 178 | + uses: actions/upload-artifact@v4 |
| 179 | + with: |
| 180 | + name: ${{ inputs.asset-prefix }}-${{ inputs.target }} |
| 181 | + path: | |
| 182 | + src-tauri/target/${{ inputs.target }}/release/bundle/dmg/*.dmg |
| 183 | + src-tauri/target/${{ inputs.target }}/release/bundle/macos/*.app |
| 184 | + retention-days: 30 |
| 185 | + |
| 186 | + - name: Upload artifacts (Linux) |
| 187 | + if: inputs.upload-artifacts && contains(inputs.platform, 'ubuntu') |
| 188 | + uses: actions/upload-artifact@v4 |
| 189 | + with: |
| 190 | + name: ${{ inputs.asset-prefix }}-${{ inputs.target }} |
| 191 | + path: | |
| 192 | + src-tauri/target/release/bundle/deb/*.deb |
| 193 | + src-tauri/target/release/bundle/appimage/*.AppImage |
| 194 | + retention-days: 30 |
| 195 | + |
| 196 | + - name: Upload artifacts (Windows) |
| 197 | + if: inputs.upload-artifacts && contains(inputs.platform, 'windows') |
| 198 | + uses: actions/upload-artifact@v4 |
| 199 | + with: |
| 200 | + name: ${{ inputs.asset-prefix }}-${{ inputs.target }} |
| 201 | + path: | |
| 202 | + src-tauri/target/release/bundle/msi/*.msi |
| 203 | + src-tauri/target/release/bundle/nsis/*.exe |
| 204 | + retention-days: 30 |
0 commit comments