|
| 1 | +name: Build and Release Tauri App |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +jobs: |
| 9 | + check-version-and-tag: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - name: Checkout Code |
| 13 | + uses: actions/checkout@v3 |
| 14 | + |
| 15 | + - name: Get Version from package.json |
| 16 | + id: get_version |
| 17 | + run: | |
| 18 | + version="v$(jq -r '.version' package.json)" |
| 19 | + echo "::set-output name=version::$version" |
| 20 | +
|
| 21 | + - name: Check if Tag Exists |
| 22 | + id: check_tag |
| 23 | + run: | |
| 24 | + version="${{ steps.get_version.outputs.version }}" |
| 25 | + if git rev-parse "$version" >/dev/null 2>&1; then |
| 26 | + echo "Tag $version already exists." |
| 27 | + echo "::set-output name=tag_exists::true" |
| 28 | + else |
| 29 | + echo "Tag $version does not exist." |
| 30 | + echo "::set-output name=tag_exists::false" |
| 31 | + fi |
| 32 | +
|
| 33 | + - name: Create Tag |
| 34 | + if: steps.check_tag.outputs.tag_exists == 'false' |
| 35 | + run: | |
| 36 | + version="${{ steps.get_version.outputs.version }}" |
| 37 | + git config user.name "github-actions" |
| 38 | + git config user.email "[email protected]" |
| 39 | + git tag -a "$version" -m "Release version $version" |
| 40 | + git push origin "$version" |
| 41 | +
|
| 42 | + build: |
| 43 | + needs: check-version-and-tag |
| 44 | + runs-on: ${{ matrix.os }} |
| 45 | + strategy: |
| 46 | + matrix: |
| 47 | + os: [macos-latest, windows-latest, ubuntu-22.04] |
| 48 | + steps: |
| 49 | + - name: Checkout Code |
| 50 | + uses: actions/checkout@v3 |
| 51 | + |
| 52 | + - name: Debug the runner OS |
| 53 | + run: echo "Running on ${{ runner.os }}" |
| 54 | + |
| 55 | + - name: Setup Rust |
| 56 | + uses: actions-rs/toolchain@v1 |
| 57 | + with: |
| 58 | + profile: minimal |
| 59 | + toolchain: stable |
| 60 | + override: true |
| 61 | + |
| 62 | + - name: Setup Node.js |
| 63 | + uses: actions/setup-node@v3 |
| 64 | + with: |
| 65 | + node-version: 18 |
| 66 | + |
| 67 | + - name: Install Dependencies |
| 68 | + run: | |
| 69 | + npm install |
| 70 | + npm install tailwindcss-animate |
| 71 | +
|
| 72 | + - name: Run npm audit |
| 73 | + run: npm audit --audit-level=high |
| 74 | + |
| 75 | + - name: Install GTK and Build Tools (Ubuntu only) |
| 76 | + if: runner.os == 'Linux' |
| 77 | + run: | |
| 78 | + sudo apt-get update |
| 79 | + sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf libudev-dev build-essential pkg-config |
| 80 | +
|
| 81 | + - name: Install Tauri CLI (locally) |
| 82 | + run: npm install @tauri-apps/cli |
| 83 | + |
| 84 | + - name: Clean npm cache |
| 85 | + run: npm cache clean --force |
| 86 | + |
| 87 | + - name: Build Tauri App |
| 88 | + run: npx tauri build |
| 89 | + |
| 90 | + # Upload platform-specific artifacts |
| 91 | + - name: Upload Artifact for macOS |
| 92 | + if: runner.os == 'macOS' |
| 93 | + uses: actions/upload-artifact@v3 |
| 94 | + with: |
| 95 | + name: tauri-app-macos |
| 96 | + path: src-tauri/target/release/bundle/dmg/*.dmg |
| 97 | + |
| 98 | + - name: Upload Artifact for Windows |
| 99 | + if: runner.os == 'Windows' |
| 100 | + uses: actions/upload-artifact@v3 |
| 101 | + with: |
| 102 | + name: tauri-app-windows |
| 103 | + path: src-tauri/target/release/bundle/msi/*.msi |
| 104 | + |
| 105 | + - name: Upload Artifact for Linux (deb) |
| 106 | + if: runner.os == 'Linux' |
| 107 | + uses: actions/upload-artifact@v3 |
| 108 | + with: |
| 109 | + name: tauri-app-linux-deb |
| 110 | + path: src-tauri/target/release/bundle/deb/*.deb |
| 111 | + |
| 112 | + - name: Upload Artifact for Linux (rpm) |
| 113 | + if: runner.os == 'Linux' |
| 114 | + uses: actions/upload-artifact@v3 |
| 115 | + with: |
| 116 | + name: tauri-app-linux-rpm |
| 117 | + path: src-tauri/target/release/bundle/rpm |
| 118 | + |
| 119 | + release: |
| 120 | + needs: [build, check-version-and-tag] |
| 121 | + runs-on: ubuntu-latest |
| 122 | + steps: |
| 123 | + - name: Checkout Code |
| 124 | + uses: actions/checkout@v3 |
| 125 | + |
| 126 | + - name: Fetch All Tags |
| 127 | + run: git fetch --tags |
| 128 | + |
| 129 | + - name: Verify Created Tag |
| 130 | + id: verified_version |
| 131 | + run: | |
| 132 | + version="v$(jq -r '.version' package.json)" |
| 133 | + echo "::set-output name=version::$version" |
| 134 | + echo "Verifying tag $version" |
| 135 | + if ! git tag -l | grep -q "$version"; then |
| 136 | + echo "Error: Tag $version not found locally." |
| 137 | + exit 1 |
| 138 | + fi |
| 139 | +
|
| 140 | + # Download platform-specific artifacts |
| 141 | + - name: Download macOS Artifact |
| 142 | + uses: actions/download-artifact@v3 |
| 143 | + with: |
| 144 | + name: tauri-app-macos |
| 145 | + path: src-tauri/target/release/bundle/dmg |
| 146 | + |
| 147 | + - name: Download Windows Artifact |
| 148 | + uses: actions/download-artifact@v3 |
| 149 | + with: |
| 150 | + name: tauri-app-windows |
| 151 | + path: src-tauri/target/release/bundle/msi |
| 152 | + |
| 153 | + - name: Download Linux Artifact (deb) |
| 154 | + uses: actions/download-artifact@v3 |
| 155 | + with: |
| 156 | + name: tauri-app-linux-deb |
| 157 | + path: src-tauri/target/release/bundle/deb |
| 158 | + |
| 159 | + - name: Download Linux Artifact (rpm) |
| 160 | + uses: actions/download-artifact@v3 |
| 161 | + with: |
| 162 | + name: tauri-app-linux-rpm |
| 163 | + path: src-tauri/target/release/bundle/rpm |
| 164 | + |
| 165 | + # Create GitHub Release with only artifacts |
| 166 | + - name: Create Release |
| 167 | + uses: softprops/action-gh-release@v1 |
| 168 | + with: |
| 169 | + tag_name: "${{ steps.verified_version.outputs.version }}" |
| 170 | + files: | |
| 171 | + src-tauri/target/release/bundle/dmg/*.dmg |
| 172 | + src-tauri/target/release/bundle/msi/*.msi |
| 173 | + src-tauri/target/release/bundle/deb/*.deb |
| 174 | + src-tauri/target/release/bundle/rpm/*.rpm |
| 175 | + draft: false |
| 176 | + env: |
| 177 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments