diff --git a/.github/workflows/tauri-release.yml b/.github/workflows/tauri-release.yml index e4ff3258..6beb15f5 100644 --- a/.github/workflows/tauri-release.yml +++ b/.github/workflows/tauri-release.yml @@ -1,4 +1,4 @@ -name: Vue Simulator Desktop Release +name: Vue + Tauri Simulator Desktop Release on: push: @@ -17,41 +17,70 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v3 -# node 22 is been used in circuitverse primary code base. + - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: 22 - - name: Install Dependencies (Vue + Tauri CLI) + - name: Cache Node.js Dependencies + uses: actions/cache@v4 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: ${{ runner.os }}-node- + + - name: Install Dependencies + run: npm install + shell: bash + + - name: Install Tauri CLI and API run: | - npm install npm install -g @tauri-apps/cli - working-directory: ./src + npm install @tauri-apps/cli @tauri-apps/api @tauri-apps/plugin-fs --save-dev + shell: bash - - name: Build Frontend (Vue) - run: | - npm run build - working-directory: ./src + - name: Run Cross-Platform Build Script + run: node tauri-build.js + shell: bash - name: Setup Rust if: matrix.os != 'windows-latest' run: | rustup update stable rustup default stable + shell: bash + + - name: Install Linux Dependencies (Ubuntu) + if: matrix.os == 'ubuntu-latest' + run: | + sudo apt update + sudo apt install libwebkit2gtk-4.1-dev \ + build-essential \ + curl \ + wget \ + file \ + libxdo-dev \ + libssl-dev \ + libayatana-appindicator3-dev \ + librsvg2-dev + shell: bash + + - name: Install macOS Dependencies + if: matrix.os == 'macos-latest' + run: | + brew update + brew install pkg-config + shell: bash - name: Cache Rust Dependencies uses: Swatinem/rust-cache@v2 + with: + workspaces: "./src-tauri" - name: Build Tauri App - uses: tauri-apps/tauri-action@v0 - with: - projectPath: ./src-tauri - tagName: ${{ github.ref_name }} - releaseName: "Tauri Desktop Release ${{ github.ref_name }}" - releaseBody: "See the assets below to download this release." - releaseDraft: false - prerelease: false + run: npm run tauri build + shell: bash - name: Upload Tauri Build Artifacts uses: actions/upload-artifact@v4 @@ -59,3 +88,83 @@ jobs: name: Tauri Build Artifacts (${{ matrix.os }}) path: | src-tauri/target/release/bundle + + create-release: + runs-on: ubuntu-latest + needs: build-tauri + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Download Artifacts + uses: actions/download-artifact@v4 + with: + path: artifacts + + - name: Prepare Release Assets + run: | + mkdir -p release-assets + + # For Ubuntu (Linux) + if [ -d "artifacts/Tauri Build Artifacts (ubuntu-latest)/deb" ]; then + cp artifacts/Tauri\ Build\ Artifacts\ \(ubuntu-latest\)/deb/*.deb release-assets/ || true + fi + if [ -d "artifacts/Tauri Build Artifacts (ubuntu-latest)/appimage" ]; then + cp artifacts/Tauri\ Build\ Artifacts\ \(ubuntu-latest\)/appimage/*.AppImage release-assets/ || true + fi + + # For Windows + if [ -d "artifacts/Tauri Build Artifacts (windows-latest)/msi" ]; then + cp artifacts/Tauri\ Build\ Artifacts\ \(windows-latest\)/msi/*.msi release-assets/ || true + fi + + # For macOS + if [ -d "artifacts/Tauri Build Artifacts (macos-latest)/dmg" ]; then + cp artifacts/Tauri\ Build\ Artifacts\ \(macos-latest\)/dmg/*.dmg release-assets/ || true + fi + if [ -d "artifacts/Tauri Build Artifacts (macos-latest)/app" ]; then + cd artifacts/Tauri\ Build\ Artifacts\ \(macos-latest\)/app + for app in *.app; do + zip -r "../../../release-assets/${app%.app}.zip" "$app" + done + cd - || exit + fi + + ls -la release-assets/ + shell: bash + + - name: Install GitHub CLI + run: | + curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg + echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null + sudo apt update + sudo apt install gh -y + shell: bash + + - name: Auto-increment version and create GitHub Release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + # Fetch latest tag + LATEST_TAG=$(git tag --sort=-v:refname | head -n 1) + + # Extract major, minor, patch versions + if [[ "$LATEST_TAG" =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then + MAJOR=${BASH_REMATCH[1]} + MINOR=${BASH_REMATCH[2]} + PATCH=${BASH_REMATCH[3]} + else + MAJOR=0 + MINOR=0 + PATCH=0 + fi + + # Increment patch version + NEW_VERSION="v$MAJOR.$MINOR.$((PATCH + 1))" + + # Create release + gh release create "$NEW_VERSION" \ + --title "CircuitVerse Desktop $NEW_VERSION" \ + --notes "Official CircuitVerse desktop app release. Download the binaries below for your platform." \ + release-assets/* + shell: bash diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 45ef1170..5f7d34d9 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -24,3 +24,16 @@ log = "0.4" tauri = { version = "2.3.1", features = ["devtools"] } tauri-plugin-log = "2.0.0-rc" tauri-plugin-fs = "2" + +[profile.dev] +incremental = true # Fast rebuilds during development + +[profile.release] +incremental = false +codegen-units = 1 # Use one code generation unit to improve cross-module optimization +lto = true # Enable Link Time Optimization to optimize across the entire binary +opt-level = "s" # Optimize for small binary size. +panic = "abort" +strip = true +debug = false +debug-assertions = false diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 76a1b5ba..a9ebb5cc 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -7,7 +7,7 @@ "frontendDist": "../dist", "devUrl": "http://localhost:4000/simulatorvue/", "beforeDevCommand": "npm run dev", - "beforeBuildCommand": "DESKTOP_MODE=true npm run build && cp ./dist/index-cv.html ./dist/index.html" + "beforeBuildCommand": "node tauri-build.js" }, "app": { "windows": [ diff --git a/tauri-build.js b/tauri-build.js new file mode 100644 index 00000000..e46d03c0 --- /dev/null +++ b/tauri-build.js @@ -0,0 +1,36 @@ +const os = require('os'); +const { execSync } = require('child_process'); + + +function runCommand(command) { + try { + const output = execSync(command, { encoding: 'utf8', stdio: 'pipe' }); + if (output) { + console.log(output); + } + } catch (error) { + console.error(`Error executing command: ${command}`); + if (error.stdout) { + console.error(`Stdout: ${error.stdout}`); + } + if (error.stderr) { + console.error(`Stderr: ${error.stderr}`); + } + process.exit(1); + } +} + + +process.env.DESKTOP_MODE = "true"; + +const platform = os.platform(); +console.log(`Building for ${platform === 'win32' ? 'Windows' : 'Unix-based system'}...`); + + +runCommand('npm run build'); + +if (platform === 'win32') { + runCommand('copy dist\\index-cv.html dist\\index.html'); +} else { + runCommand('cp dist/index-cv.html dist/index.html'); +} \ No newline at end of file