|
| 1 | +name: Executable Tutorial CI/CD |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, develop ] |
| 6 | + paths: |
| 7 | + - 'apps/desktop/**' |
| 8 | + - 'packages/**' |
| 9 | + - '.github/workflows/executable-tutorial.yml' |
| 10 | + pull_request: |
| 11 | + branches: [ main, develop ] |
| 12 | + paths: |
| 13 | + - 'apps/desktop/**' |
| 14 | + - 'packages/**' |
| 15 | + workflow_dispatch: |
| 16 | + inputs: |
| 17 | + task: |
| 18 | + description: 'Task to execute' |
| 19 | + required: true |
| 20 | + default: 'build' |
| 21 | + type: choice |
| 22 | + options: |
| 23 | + - build |
| 24 | + - test |
| 25 | + - lint |
| 26 | + - release |
| 27 | + |
| 28 | +env: |
| 29 | + CARGO_TERM_COLOR: always |
| 30 | + NODE_VERSION: '20' |
| 31 | + |
| 32 | +jobs: |
| 33 | + # 代码检查和测试 |
| 34 | + check: |
| 35 | + runs-on: ${{ matrix.os }} |
| 36 | + strategy: |
| 37 | + matrix: |
| 38 | + os: [ubuntu-latest, macos-latest, windows-latest] |
| 39 | + |
| 40 | + steps: |
| 41 | + - uses: actions/checkout@v4 |
| 42 | + |
| 43 | + - name: Setup Node.js |
| 44 | + uses: actions/setup-node@v4 |
| 45 | + with: |
| 46 | + node-version: ${{ env.NODE_VERSION }} |
| 47 | + cache: 'npm' |
| 48 | + |
| 49 | + - name: Setup Rust |
| 50 | + uses: dtolnay/rust-action@stable |
| 51 | + |
| 52 | + - name: Install dependencies |
| 53 | + run: | |
| 54 | + npm ci |
| 55 | + cd apps/desktop && npm ci |
| 56 | + |
| 57 | + - name: Run linter |
| 58 | + run: | |
| 59 | + cd apps/desktop |
| 60 | + npm run lint |
| 61 | + continue-on-error: true |
| 62 | + |
| 63 | + - name: Run tests |
| 64 | + run: | |
| 65 | + cd apps/desktop |
| 66 | + npm run test |
| 67 | + continue-on-error: true |
| 68 | + |
| 69 | + # 构建桌面应用 |
| 70 | + build: |
| 71 | + needs: check |
| 72 | + runs-on: ${{ matrix.os }} |
| 73 | + strategy: |
| 74 | + matrix: |
| 75 | + include: |
| 76 | + - os: macos-latest |
| 77 | + target: aarch64-apple-darwin |
| 78 | + args: '--target aarch64-apple-darwin' |
| 79 | + - os: macos-latest |
| 80 | + target: x86_64-apple-darwin |
| 81 | + args: '--target x86_64-apple-darwin' |
| 82 | + - os: windows-latest |
| 83 | + target: x86_64-pc-windows-msvc |
| 84 | + args: '' |
| 85 | + - os: ubuntu-latest |
| 86 | + target: x86_64-unknown-linux-gnu |
| 87 | + args: '' |
| 88 | + |
| 89 | + steps: |
| 90 | + - uses: actions/checkout@v4 |
| 91 | + |
| 92 | + - name: Setup Node.js |
| 93 | + uses: actions/setup-node@v4 |
| 94 | + with: |
| 95 | + node-version: ${{ env.NODE_VERSION }} |
| 96 | + cache: 'npm' |
| 97 | + |
| 98 | + - name: Setup Rust |
| 99 | + uses: dtolnay/rust-action@stable |
| 100 | + with: |
| 101 | + targets: ${{ matrix.target }} |
| 102 | + |
| 103 | + - name: Install Linux dependencies |
| 104 | + if: matrix.os == 'ubuntu-latest' |
| 105 | + run: | |
| 106 | + sudo apt-get update |
| 107 | + sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf |
| 108 | + |
| 109 | + - name: Install dependencies |
| 110 | + run: | |
| 111 | + npm ci |
| 112 | + cd apps/desktop && npm ci |
| 113 | + |
| 114 | + - name: Build Tauri app |
| 115 | + run: | |
| 116 | + cd apps/desktop/src-tauri |
| 117 | + cargo build --release ${{ matrix.args }} |
| 118 | + |
| 119 | + - name: Upload artifacts |
| 120 | + uses: actions/upload-artifact@v4 |
| 121 | + with: |
| 122 | + name: executable-tutorial-${{ matrix.target }} |
| 123 | + path: | |
| 124 | + apps/desktop/src-tauri/target/release/bundle/**/*.dmg |
| 125 | + apps/desktop/src-tauri/target/release/bundle/**/*.app |
| 126 | + apps/desktop/src-tauri/target/release/bundle/**/*.exe |
| 127 | + apps/desktop/src-tauri/target/release/bundle/**/*.msi |
| 128 | + apps/desktop/src-tauri/target/release/bundle/**/*.deb |
| 129 | + apps/desktop/src-tauri/target/release/bundle/**/*.AppImage |
| 130 | +
|
| 131 | + # 发布版本 |
| 132 | + release: |
| 133 | + needs: build |
| 134 | + runs-on: ubuntu-latest |
| 135 | + if: github.ref == 'refs/heads/main' && github.event_name == 'push' |
| 136 | + |
| 137 | + steps: |
| 138 | + - uses: actions/checkout@v4 |
| 139 | + |
| 140 | + - name: Download all artifacts |
| 141 | + uses: actions/download-artifact@v4 |
| 142 | + with: |
| 143 | + path: artifacts |
| 144 | + |
| 145 | + - name: Create Release |
| 146 | + uses: softprops/action-gh-release@v1 |
| 147 | + if: startsWith(github.ref, 'refs/tags/') |
| 148 | + with: |
| 149 | + files: artifacts/**/* |
| 150 | + env: |
| 151 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments