|
| 1 | +name: 'Build and Release' |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: ['v*'] |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + tag: |
| 9 | + description: 'Tag to release' |
| 10 | + required: true |
| 11 | + default: 'v1.0.0' |
| 12 | + |
| 13 | +jobs: |
| 14 | + create-release: |
| 15 | + permissions: |
| 16 | + contents: write |
| 17 | + runs-on: ubuntu-22.04 |
| 18 | + outputs: |
| 19 | + release_id: ${{ steps.create-release.outputs.result }} |
| 20 | + |
| 21 | + steps: |
| 22 | + - name: Checkout repository |
| 23 | + uses: actions/checkout@v4 |
| 24 | + |
| 25 | + - name: Create release |
| 26 | + id: create-release |
| 27 | + uses: actions/github-script@v7 |
| 28 | + with: |
| 29 | + script: | |
| 30 | + const { data } = await github.rest.repos.createRelease({ |
| 31 | + owner: context.repo.owner, |
| 32 | + repo: context.repo.repo, |
| 33 | + tag_name: context.ref.replace('refs/tags/', '') || '${{ github.event.inputs.tag }}', |
| 34 | + name: `MDX Notes ${context.ref.replace('refs/tags/', '') || '${{ github.event.inputs.tag }}'}`, |
| 35 | + body: 'Auto-generated release', |
| 36 | + draft: true, |
| 37 | + prerelease: false |
| 38 | + }) |
| 39 | + return data.id |
| 40 | +
|
| 41 | + build-tauri: |
| 42 | + needs: create-release |
| 43 | + permissions: |
| 44 | + contents: write |
| 45 | + strategy: |
| 46 | + fail-fast: false |
| 47 | + matrix: |
| 48 | + include: |
| 49 | + - platform: 'macos-latest' |
| 50 | + args: '--target aarch64-apple-darwin' |
| 51 | + target: 'aarch64-apple-darwin' |
| 52 | + name: 'macOS-ARM64' |
| 53 | + - platform: 'macos-latest' |
| 54 | + args: '--target x86_64-apple-darwin' |
| 55 | + target: 'x86_64-apple-darwin' |
| 56 | + name: 'macOS-Intel' |
| 57 | + - platform: 'ubuntu-22.04' |
| 58 | + args: '' |
| 59 | + target: 'x86_64-unknown-linux-gnu' |
| 60 | + name: 'Linux-x86_64' |
| 61 | + - platform: 'windows-latest' |
| 62 | + args: '' |
| 63 | + target: 'x86_64-pc-windows-msvc' |
| 64 | + name: 'Windows-x86_64' |
| 65 | + |
| 66 | + runs-on: ${{ matrix.platform }} |
| 67 | + steps: |
| 68 | + - name: Checkout repository |
| 69 | + uses: actions/checkout@v4 |
| 70 | + |
| 71 | + - name: Install dependencies (Ubuntu only) |
| 72 | + if: matrix.platform == 'ubuntu-22.04' |
| 73 | + run: | |
| 74 | + sudo apt-get update |
| 75 | + sudo apt-get install -y libwebkit2gtk-4.0-dev libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf |
| 76 | +
|
| 77 | + - name: Setup Node.js |
| 78 | + uses: actions/setup-node@v4 |
| 79 | + with: |
| 80 | + node-version: '18' |
| 81 | + cache: 'npm' |
| 82 | + |
| 83 | + - name: Install Rust stable |
| 84 | + uses: dtolnay/rust-toolchain@stable |
| 85 | + with: |
| 86 | + targets: ${{ matrix.target }} |
| 87 | + |
| 88 | + - name: Rust cache |
| 89 | + uses: swatinem/rust-cache@v2 |
| 90 | + with: |
| 91 | + workspaces: './src-tauri -> target' |
| 92 | + |
| 93 | + - name: Install frontend dependencies |
| 94 | + run: npm ci |
| 95 | + |
| 96 | + - name: Build application |
| 97 | + env: |
| 98 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 99 | + TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }} |
| 100 | + TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }} |
| 101 | + run: | |
| 102 | + if [ -n "${{ matrix.args }}" ]; then |
| 103 | + npm run tauri build -- ${{ matrix.args }} |
| 104 | + else |
| 105 | + npm run tauri build |
| 106 | + fi |
| 107 | +
|
| 108 | + - name: Find and upload assets (macOS) |
| 109 | + if: matrix.platform == 'macos-latest' |
| 110 | + uses: actions/github-script@v7 |
| 111 | + with: |
| 112 | + script: | |
| 113 | + const fs = require('fs').promises; |
| 114 | + const path = require('path'); |
| 115 | + |
| 116 | + const targetDir = 'src-tauri/target/${{ matrix.target }}/release/bundle'; |
| 117 | + |
| 118 | + // Upload DMG |
| 119 | + try { |
| 120 | + const dmgDir = `${targetDir}/dmg`; |
| 121 | + const dmgFiles = await fs.readdir(dmgDir); |
| 122 | + for (const file of dmgFiles.filter(f => f.endsWith('.dmg'))) { |
| 123 | + const filePath = path.join(dmgDir, file); |
| 124 | + const stats = await fs.stat(filePath); |
| 125 | + const fileData = await fs.readFile(filePath); |
| 126 | + |
| 127 | + await github.rest.repos.uploadReleaseAsset({ |
| 128 | + owner: context.repo.owner, |
| 129 | + repo: context.repo.repo, |
| 130 | + release_id: ${{ needs.create-release.outputs.release_id }}, |
| 131 | + name: `MDX-Notes-${{ matrix.name }}.dmg`, |
| 132 | + data: fileData, |
| 133 | + }); |
| 134 | + console.log(`Uploaded ${file} as MDX-Notes-${{ matrix.name }}.dmg`); |
| 135 | + } |
| 136 | + } catch (error) { |
| 137 | + console.log('No DMG files found or error uploading:', error.message); |
| 138 | + } |
| 139 | +
|
| 140 | + - name: Find and upload assets (Ubuntu) |
| 141 | + if: matrix.platform == 'ubuntu-22.04' |
| 142 | + uses: actions/github-script@v7 |
| 143 | + with: |
| 144 | + script: | |
| 145 | + const fs = require('fs').promises; |
| 146 | + const path = require('path'); |
| 147 | + |
| 148 | + const targetDir = 'src-tauri/target/release/bundle'; |
| 149 | + |
| 150 | + // Upload DEB |
| 151 | + try { |
| 152 | + const debDir = `${targetDir}/deb`; |
| 153 | + const debFiles = await fs.readdir(debDir); |
| 154 | + for (const file of debFiles.filter(f => f.endsWith('.deb'))) { |
| 155 | + const filePath = path.join(debDir, file); |
| 156 | + const fileData = await fs.readFile(filePath); |
| 157 | + |
| 158 | + await github.rest.repos.uploadReleaseAsset({ |
| 159 | + owner: context.repo.owner, |
| 160 | + repo: context.repo.repo, |
| 161 | + release_id: ${{ needs.create-release.outputs.release_id }}, |
| 162 | + name: `MDX-Notes-${{ matrix.name }}.deb`, |
| 163 | + data: fileData, |
| 164 | + }); |
| 165 | + console.log(`Uploaded ${file} as MDX-Notes-${{ matrix.name }}.deb`); |
| 166 | + } |
| 167 | + } catch (error) { |
| 168 | + console.log('No DEB files found or error uploading:', error.message); |
| 169 | + } |
| 170 | + |
| 171 | + // Upload AppImage |
| 172 | + try { |
| 173 | + const appImageDir = `${targetDir}/appimage`; |
| 174 | + const appImageFiles = await fs.readdir(appImageDir); |
| 175 | + for (const file of appImageFiles.filter(f => f.endsWith('.AppImage'))) { |
| 176 | + const filePath = path.join(appImageDir, file); |
| 177 | + const fileData = await fs.readFile(filePath); |
| 178 | + |
| 179 | + await github.rest.repos.uploadReleaseAsset({ |
| 180 | + owner: context.repo.owner, |
| 181 | + repo: context.repo.repo, |
| 182 | + release_id: ${{ needs.create-release.outputs.release_id }}, |
| 183 | + name: `MDX-Notes-${{ matrix.name }}.AppImage`, |
| 184 | + data: fileData, |
| 185 | + }); |
| 186 | + console.log(`Uploaded ${file} as MDX-Notes-${{ matrix.name }}.AppImage`); |
| 187 | + } |
| 188 | + } catch (error) { |
| 189 | + console.log('No AppImage files found or error uploading:', error.message); |
| 190 | + } |
| 191 | +
|
| 192 | + - name: Find and upload assets (Windows) |
| 193 | + if: matrix.platform == 'windows-latest' |
| 194 | + uses: actions/github-script@v7 |
| 195 | + with: |
| 196 | + script: | |
| 197 | + const fs = require('fs').promises; |
| 198 | + const path = require('path'); |
| 199 | + |
| 200 | + const targetDir = 'src-tauri/target/release/bundle'; |
| 201 | + |
| 202 | + // Upload MSI |
| 203 | + try { |
| 204 | + const msiDir = `${targetDir}/msi`; |
| 205 | + const msiFiles = await fs.readdir(msiDir); |
| 206 | + for (const file of msiFiles.filter(f => f.endsWith('.msi'))) { |
| 207 | + const filePath = path.join(msiDir, file); |
| 208 | + const fileData = await fs.readFile(filePath); |
| 209 | + |
| 210 | + await github.rest.repos.uploadReleaseAsset({ |
| 211 | + owner: context.repo.owner, |
| 212 | + repo: context.repo.repo, |
| 213 | + release_id: ${{ needs.create-release.outputs.release_id }}, |
| 214 | + name: `MDX-Notes-${{ matrix.name }}.msi`, |
| 215 | + data: fileData, |
| 216 | + }); |
| 217 | + console.log(`Uploaded ${file} as MDX-Notes-${{ matrix.name }}.msi`); |
| 218 | + } |
| 219 | + } catch (error) { |
| 220 | + console.log('No MSI files found or error uploading:', error.message); |
| 221 | + } |
| 222 | + |
| 223 | + // Upload NSIS installer |
| 224 | + try { |
| 225 | + const nsisDir = `${targetDir}/nsis`; |
| 226 | + const nsisFiles = await fs.readdir(nsisDir); |
| 227 | + for (const file of nsisFiles.filter(f => f.endsWith('.exe'))) { |
| 228 | + const filePath = path.join(nsisDir, file); |
| 229 | + const fileData = await fs.readFile(filePath); |
| 230 | + |
| 231 | + await github.rest.repos.uploadReleaseAsset({ |
| 232 | + owner: context.repo.owner, |
| 233 | + repo: context.repo.repo, |
| 234 | + release_id: ${{ needs.create-release.outputs.release_id }}, |
| 235 | + name: `MDX-Notes-${{ matrix.name }}-Setup.exe`, |
| 236 | + data: fileData, |
| 237 | + }); |
| 238 | + console.log(`Uploaded ${file} as MDX-Notes-${{ matrix.name }}-Setup.exe`); |
| 239 | + } |
| 240 | + } catch (error) { |
| 241 | + console.log('No NSIS files found or error uploading:', error.message); |
| 242 | + } |
| 243 | +
|
| 244 | + publish-release: |
| 245 | + permissions: |
| 246 | + contents: write |
| 247 | + runs-on: ubuntu-22.04 |
| 248 | + needs: [create-release, build-tauri] |
| 249 | + |
| 250 | + steps: |
| 251 | + - name: Publish release |
| 252 | + uses: actions/github-script@v7 |
| 253 | + with: |
| 254 | + script: | |
| 255 | + github.rest.repos.updateRelease({ |
| 256 | + owner: context.repo.owner, |
| 257 | + repo: context.repo.repo, |
| 258 | + release_id: ${{ needs.create-release.outputs.release_id }}, |
| 259 | + draft: false |
| 260 | + }) |
0 commit comments