|
| 1 | +name: Build Desktop App |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + create-release: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - name: Create release |
| 16 | + uses: softprops/action-gh-release@v2 |
| 17 | + with: |
| 18 | + name: ${{ github.ref_name }} |
| 19 | + draft: false |
| 20 | + prerelease: false |
| 21 | + generate_release_notes: true |
| 22 | + env: |
| 23 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 24 | + |
| 25 | + build: |
| 26 | + needs: create-release |
| 27 | + strategy: |
| 28 | + fail-fast: false |
| 29 | + matrix: |
| 30 | + include: |
| 31 | + - os: macos-latest |
| 32 | + platform: darwin |
| 33 | + arch: arm64 |
| 34 | + eb_flags: --mac --arm64 |
| 35 | + - os: windows-latest |
| 36 | + platform: windows |
| 37 | + arch: amd64 |
| 38 | + eb_flags: --win --x64 |
| 39 | + - os: ubuntu-latest |
| 40 | + platform: linux |
| 41 | + arch: amd64 |
| 42 | + eb_flags: --linux --x64 |
| 43 | + |
| 44 | + runs-on: ${{ matrix.os }} |
| 45 | + |
| 46 | + defaults: |
| 47 | + run: |
| 48 | + shell: bash |
| 49 | + |
| 50 | + # specify bash for windows |
| 51 | + env: |
| 52 | + npm_config_script_shell: bash |
| 53 | + |
| 54 | + steps: |
| 55 | + - name: Checkout |
| 56 | + uses: actions/checkout@v4 |
| 57 | + with: |
| 58 | + submodules: recursive |
| 59 | + |
| 60 | + - name: Setup Node.js |
| 61 | + uses: actions/setup-node@v4 |
| 62 | + with: |
| 63 | + node-version: '20' |
| 64 | + |
| 65 | + - name: Install dependencies |
| 66 | + run: npm ci |
| 67 | + |
| 68 | + - name: Fetch binaries |
| 69 | + run: bash fetch-binaries.sh ${{ matrix.platform }} ${{ matrix.arch }} |
| 70 | + env: |
| 71 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 72 | + |
| 73 | + - name: Remove embedded archives / package test fixtures (mac notarization) |
| 74 | + if: matrix.platform == 'darwin' |
| 75 | + run: | |
| 76 | + PY_SITE="handler/bin/python-runtime/venv/lib/python3.8/site-packages" |
| 77 | + # Some vendored Python packages ship test fixtures as zip/tar archives (and sometimes odd perms). |
| 78 | + # Apple's notarization pipeline can flag these when bundled inside a signed app. |
| 79 | + rm -rf "$PY_SITE/joblib/test" |
| 80 | + rm -rf "$PY_SITE/pooch/tests" |
| 81 | + # remove dcm2niix_binaries to avoid notarization failure. We will point to the bundled dcm2niix in the app. |
| 82 | + # Note that we have pinned pypet2bids to 1.4.6 in requirements.txt, and it uses dcm2niix v1.0.20250505. |
| 83 | + # in the future, if we want to upgrade pypet2bids, we must make sure that our version of dcm2niix is compatible and vice versa. |
| 84 | + rm -rf "$PY_SITE/pypet2bids/dcm2niix_binaries" |
| 85 | +
|
| 86 | + - name: Clean dist |
| 87 | + run: rm -rf electron/dist |
| 88 | + |
| 89 | + - name: Build JS bundles |
| 90 | + working-directory: electron |
| 91 | + run: | |
| 92 | + npm run build:electron-api |
| 93 | + npm run build:electron-handler |
| 94 | + npm run build:electron-handler-scripts |
| 95 | +
|
| 96 | + - name: Copy Python files, BIDS schema, and templates |
| 97 | + working-directory: electron |
| 98 | + run: | |
| 99 | + npm run build:electron-python |
| 100 | + npm run build:electron-bids-spec |
| 101 | + npm run build:electron-templates |
| 102 | +
|
| 103 | + - name: Build frontend |
| 104 | + working-directory: ui |
| 105 | + run: npm run build:electron |
| 106 | + |
| 107 | + - name: Transpile main process |
| 108 | + working-directory: electron |
| 109 | + run: | |
| 110 | + npm run build:electron-preload |
| 111 | + npm run build:electron-main |
| 112 | +
|
| 113 | + - name: Validate Apple signing secrets |
| 114 | + if: matrix.platform == 'darwin' |
| 115 | + run: | |
| 116 | + test -n "${{ secrets.APPLE_CERTIFICATE_P12_BASE64 }}" |
| 117 | + test -n "${{ secrets.APPLE_CERTIFICATE_PASSWORD }}" |
| 118 | + test -n "${{ secrets.APPLE_API_KEY_ID }}" |
| 119 | + test -n "${{ secrets.APPLE_API_ISSUER }}" |
| 120 | + test -n "${{ secrets.APPLE_API_KEY_P8_BASE64 }}" |
| 121 | +
|
| 122 | + - name: Import Apple signing certificate |
| 123 | + if: matrix.platform == 'darwin' |
| 124 | + uses: apple-actions/import-codesign-certs@v3 |
| 125 | + with: |
| 126 | + p12-file-base64: ${{ secrets.APPLE_CERTIFICATE_P12_BASE64 }} |
| 127 | + p12-password: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }} |
| 128 | + |
| 129 | + - name: Create Apple API key file |
| 130 | + if: matrix.platform == 'darwin' |
| 131 | + run: | |
| 132 | + API_KEY_PATH="$RUNNER_TEMP/AuthKey_${APPLE_API_KEY_ID}.p8" |
| 133 | + # Support both GNU and BSD base64 flags on GitHub runners. |
| 134 | + if ! printf '%s' "$APPLE_API_KEY_P8_BASE64" | base64 --decode > "$API_KEY_PATH" 2>/dev/null; then |
| 135 | + printf '%s' "$APPLE_API_KEY_P8_BASE64" | base64 -D > "$API_KEY_PATH" |
| 136 | + fi |
| 137 | + env: |
| 138 | + APPLE_API_KEY_P8_BASE64: ${{ secrets.APPLE_API_KEY_P8_BASE64 }} |
| 139 | + APPLE_API_KEY_ID: ${{ secrets.APPLE_API_KEY_ID }} |
| 140 | + |
| 141 | + - name: Package (macOS signed + notarized) |
| 142 | + if: matrix.platform == 'darwin' |
| 143 | + working-directory: electron |
| 144 | + timeout-minutes: 360 |
| 145 | + run: | |
| 146 | + npx electron-builder ${{ matrix.eb_flags }} & |
| 147 | + EB_PID=$! |
| 148 | + while kill -0 "$EB_PID" 2>/dev/null; do |
| 149 | + echo "[heartbeat] electron-builder still running at $(date -u +'%Y-%m-%dT%H:%M:%SZ')" |
| 150 | + ps -axo pid,ppid,etime,command | grep -E "electron-builder|app-builder|codesign|notarytool" | grep -v grep || true |
| 151 | + sleep 60 |
| 152 | + done |
| 153 | + wait "$EB_PID" |
| 154 | + env: |
| 155 | + # Verbose logs: builder-util registers `electron-builder`; @electron/notarize registers `electron-notarize`. |
| 156 | + DEBUG: 'electron-builder*,electron-notarize*' |
| 157 | + APPLE_API_KEY: ${{ runner.temp }}/AuthKey_${{ secrets.APPLE_API_KEY_ID }}.p8 |
| 158 | + APPLE_API_KEY_ID: ${{ secrets.APPLE_API_KEY_ID }} |
| 159 | + APPLE_API_ISSUER: ${{ secrets.APPLE_API_ISSUER }} |
| 160 | + CSC_KEY_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }} |
| 161 | + |
| 162 | + - name: Package (Windows/Linux) |
| 163 | + if: matrix.platform != 'darwin' |
| 164 | + working-directory: electron |
| 165 | + run: npx electron-builder ${{ matrix.eb_flags }} |
| 166 | + |
| 167 | + - name: Verify macOS code signing and notarization |
| 168 | + if: matrix.platform == 'darwin' |
| 169 | + working-directory: electron |
| 170 | + run: | |
| 171 | + # electron-builder puts the .app under release/mac-<arch>/ (not release/*.app). |
| 172 | + APP_PATH=$(find release -name '*.app' -type d | head -n 1) |
| 173 | + DMG_PATH=$(find release -maxdepth 1 -name '*.dmg' -type f | head -n 1) |
| 174 | + if [[ -z "$APP_PATH" || ! -d "$APP_PATH" ]]; then |
| 175 | + echo "No .app bundle found under electron/release (expected e.g. release/mac-arm64/*.app):" |
| 176 | + find release -maxdepth 4 -type d -print || true |
| 177 | + exit 1 |
| 178 | + fi |
| 179 | + if [[ -z "$DMG_PATH" || ! -f "$DMG_PATH" ]]; then |
| 180 | + echo "No .dmg found under electron/release:" |
| 181 | + ls -la release || true |
| 182 | + exit 1 |
| 183 | + fi |
| 184 | +
|
| 185 | + echo "Verifying app signature: $APP_PATH" |
| 186 | + codesign --verify --deep --strict --verbose=2 "$APP_PATH" |
| 187 | + codesign -dv --verbose=4 "$APP_PATH" 2>&1 |
| 188 | +
|
| 189 | + # electron-notarize staples the .app; the .dmg is built afterward and usually has no separate ticket. |
| 190 | + echo "Validating notarization ticket on app bundle: $APP_PATH" |
| 191 | + xcrun stapler validate "$APP_PATH" |
| 192 | +
|
| 193 | + echo "Gatekeeper assess app bundle: $APP_PATH" |
| 194 | + spctl --assess --verbose=4 "$APP_PATH" |
| 195 | +
|
| 196 | + echo "DMG artifact present (notarization ticket is on the .app, not this wrapper): $DMG_PATH" |
| 197 | + test -f "$DMG_PATH" |
| 198 | +
|
| 199 | + - name: Upload artifacts to release |
| 200 | + uses: softprops/action-gh-release@v2 |
| 201 | + with: |
| 202 | + files: | |
| 203 | + electron/release/*.dmg |
| 204 | + electron/release/*.exe |
| 205 | + electron/release/*.AppImage |
| 206 | + electron/release/*.deb |
| 207 | + env: |
| 208 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments