diff --git a/.github/workflows/build-and-release.yml b/.github/workflows/build-and-release.yml index 2f61a62a6..0ee92a91e 100644 --- a/.github/workflows/build-and-release.yml +++ b/.github/workflows/build-and-release.yml @@ -10,50 +10,32 @@ on: type: string jobs: - build-server-windows: - runs-on: windows-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Setup Python - uses: actions/setup-python@v4 - with: - python-version: 3.12 - - - name: Install dependencies - run: | - cd backend - python -m pip install --upgrade pip - pip install -r requirements.txt - pip uninstall -y onnxruntime - pip install onnxruntime-directml - - - name: Build executable with PyInstaller - run: | - cd backend - pyinstaller main.py --name PictoPy_Server --onedir --distpath dist - - - name: Copy app folder - run: | - cd backend - mkdir dist/PictoPy_Server/images - robocopy app dist\PictoPy_Server\app /e - if ($LASTEXITCODE -le 1) { exit 0 } - - - name: Create ZIP package - run: | - cd backend/dist/PictoPy_Server - tar -a -c -f PictoPy-Windows.zip . - - - name: Upload artifact - uses: actions/upload-artifact@v4 - with: - name: PictoPy-Windows - path: backend/dist/PictoPy_Server/PictoPy-Windows.zip - - build-server-ubuntu: - runs-on: ubuntu-22.04 + build-server: + strategy: + fail-fast: false + matrix: + include: + - platform: windows-latest + artifact-name: PictoPy-Windows + onnx-package: onnxruntime-directml + mkdir-cmd: mkdir dist/PictoPy_Server/images + copy-cmd: | + robocopy app dist\PictoPy_Server\app /e + if ($LASTEXITCODE -le 1) { exit 0 } + zip-cmd: tar -a -c -f PictoPy-Windows.zip . + - platform: ubuntu-22.04 + artifact-name: PictoPy-Ubuntu + onnx-package: onnxruntime-gpu + mkdir-cmd: mkdir -p dist/PictoPy_Server/images && mkdir -p dist/PictoPy_Server/app + copy-cmd: cp -r app/* dist/PictoPy_Server/app/ + zip-cmd: zip -r PictoPy-Ubuntu.zip . + - platform: macos-latest + artifact-name: PictoPy-MacOS + onnx-package: "" + mkdir-cmd: mkdir -p dist/PictoPy_Server/images && mkdir -p dist/PictoPy_Server/app + copy-cmd: cp -r app/* dist/PictoPy_Server/app/ + zip-cmd: zip -r PictoPy-MacOS.zip . + runs-on: ${{ matrix.platform }} steps: - name: Checkout code uses: actions/checkout@v4 @@ -62,120 +44,65 @@ jobs: uses: actions/setup-python@v4 with: python-version: 3.12 + cache: 'pip' + cache-dependency-path: backend/requirements.txt - name: Install dependencies + working-directory: backend + shell: bash run: | - cd backend python -m pip install --upgrade pip pip install -r requirements.txt - pip uninstall -y onnxruntime - pip install onnxruntime-gpu + if [ -n "${{ matrix.onnx-package }}" ]; then + pip uninstall -y onnxruntime + pip install ${{ matrix.onnx-package }} + fi - name: Build executable with PyInstaller + working-directory: backend run: | - cd backend pyinstaller main.py --name PictoPy_Server --onedir --distpath dist - name: Copy app folder + working-directory: backend + shell: ${{ matrix.platform == 'windows-latest' && 'pwsh' || 'bash' }} run: | - cd backend - mkdir -p dist/PictoPy_Server/images - mkdir -p dist/PictoPy_Server/app - cp -r app/* dist/PictoPy_Server/app/ - - - name: Create ZIP package - run: | - cd backend/dist/PictoPy_Server - zip -r PictoPy-Ubuntu.zip . - - - name: Upload artifact - uses: actions/upload-artifact@v4 - with: - name: PictoPy-Ubuntu - path: backend/dist/PictoPy_Server/PictoPy-Ubuntu.zip - - build-server-macos: - runs-on: macos-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Setup Python - uses: actions/setup-python@v4 - with: - python-version: 3.12 - - - name: Install dependencies - run: | - cd backend - python -m pip install --upgrade pip - pip install -r requirements.txt - - - name: Build executable with PyInstaller - run: | - cd backend - pyinstaller main.py --name PictoPy_Server --onedir --distpath dist + ${{ matrix.mkdir-cmd }} + ${{ matrix.copy-cmd }} - - name: Copy app folder - run: | - cd backend - mkdir -p dist/PictoPy_Server/images - mkdir -p dist/PictoPy_Server/app - cp -r app/* dist/PictoPy_Server/app/ - - - name: Create ZIP package - run: | - cd backend/dist/PictoPy_Server - zip -r PictoPy-MacOS.zip . - - - name: Upload artifact - uses: actions/upload-artifact@v4 - with: - name: PictoPy-MacOS - path: backend/dist/PictoPy_Server/PictoPy-MacOS.zip - - build-sync-microservice-windows: - runs-on: windows-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Setup Python - uses: actions/setup-python@v4 - with: - python-version: 3.12 - - - name: Install dependencies - run: | - cd sync-microservice - python -m pip install --upgrade pip - pip install -r requirements.txt - pip install pyinstaller - - - name: Build executable with PyInstaller - run: | - cd sync-microservice - pyinstaller main.py --name PictoPy_Sync --onedir --distpath dist - - - name: Copy app folder - run: | - cd sync-microservice - robocopy app dist\PictoPy_Sync\app /e - if ($LASTEXITCODE -le 1) { exit 0 } - name: Create ZIP package + working-directory: backend/dist/PictoPy_Server + shell: bash run: | - cd sync-microservice/dist/PictoPy_Sync - tar -a -c -f PictoPy-Sync-Windows.zip . + ${{ matrix.zip-cmd }} - name: Upload artifact uses: actions/upload-artifact@v4 with: - name: PictoPy-Sync-Windows - path: sync-microservice/dist/PictoPy_Sync/PictoPy-Sync-Windows.zip + name: ${{ matrix.artifact-name }} + path: backend/dist/PictoPy_Server/${{ matrix.artifact-name }}.zip - build-sync-microservice-ubuntu: - runs-on: ubuntu-22.04 + build-sync-microservice: + strategy: + fail-fast: false + matrix: + include: + - platform: windows-latest + artifact-name: PictoPy-Sync-Windows + copy-cmd: | + robocopy app dist\PictoPy_Sync\app /e + if ($LASTEXITCODE -le 1) { exit 0 } + zip-cmd: tar -a -c -f PictoPy-Sync-Windows.zip . + - platform: ubuntu-22.04 + artifact-name: PictoPy-Sync-Ubuntu + copy-cmd: mkdir -p dist/PictoPy_Sync/app && cp -r app/* dist/PictoPy_Sync/app/ + zip-cmd: zip -r PictoPy-Sync-Ubuntu.zip . + - platform: macos-latest + artifact-name: PictoPy-Sync-MacOS + copy-cmd: mkdir -p dist/PictoPy_Sync/app && cp -r app/* dist/PictoPy_Sync/app/ + zip-cmd: zip -r PictoPy-Sync-MacOS.zip . + runs-on: ${{ matrix.platform }} steps: - name: Checkout code uses: actions/checkout@v4 @@ -184,88 +111,44 @@ jobs: uses: actions/setup-python@v4 with: python-version: 3.12 + cache: 'pip' + cache-dependency-path: sync-microservice/requirements.txt - name: Install dependencies + working-directory: sync-microservice run: | - cd sync-microservice python -m pip install --upgrade pip pip install -r requirements.txt pip install pyinstaller - name: Build executable with PyInstaller + working-directory: sync-microservice run: | - cd sync-microservice pyinstaller main.py --name PictoPy_Sync --onedir --distpath dist - name: Copy app folder + working-directory: sync-microservice + shell: ${{ matrix.platform == 'windows-latest' && 'pwsh' || 'bash' }} run: | - cd sync-microservice - mkdir -p dist/PictoPy_Sync/app - cp -r app/* dist/PictoPy_Sync/app/ + ${{ matrix.copy-cmd }} - - name: Create ZIP package - run: | - cd sync-microservice/dist/PictoPy_Sync - zip -r PictoPy-Sync-Ubuntu.zip . - - - name: Upload artifact - uses: actions/upload-artifact@v4 - with: - name: PictoPy-Sync-Ubuntu - path: sync-microservice/dist/PictoPy_Sync/PictoPy-Sync-Ubuntu.zip - - build-sync-microservice-macos: - runs-on: macos-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Setup Python - uses: actions/setup-python@v4 - with: - python-version: 3.12 - - - name: Install dependencies - run: | - cd sync-microservice - python -m pip install --upgrade pip - pip install -r requirements.txt - pip install pyinstaller - - - name: Build executable with PyInstaller - run: | - cd sync-microservice - pyinstaller main.py --name PictoPy_Sync --onedir --distpath dist - - - name: Copy app folder - run: | - cd sync-microservice - mkdir -p dist/PictoPy_Sync/app - cp -r app/* dist/PictoPy_Sync/app/ - name: Create ZIP package + working-directory: sync-microservice/dist/PictoPy_Sync + shell: bash run: | - cd sync-microservice/dist/PictoPy_Sync - zip -r PictoPy-Sync-MacOS.zip . + ${{ matrix.zip-cmd }} - name: Upload artifact uses: actions/upload-artifact@v4 with: - name: PictoPy-Sync-MacOS - path: sync-microservice/dist/PictoPy_Sync/PictoPy-Sync-MacOS.zip + name: ${{ matrix.artifact-name }} + path: sync-microservice/dist/PictoPy_Sync/${{ matrix.artifact-name }}.zip publish-tauri: permissions: contents: write - needs: - [ - build-server-windows, - build-server-ubuntu, - build-server-macos, - build-sync-microservice-windows, - build-sync-microservice-ubuntu, - build-sync-microservice-macos, - ] + needs: [build-server, build-sync-microservice] strategy: fail-fast: false matrix: @@ -307,16 +190,16 @@ jobs: - name: Extract server files shell: bash + working-directory: backend/dist run: | - cd backend/dist unzip -o *.zip rm *.zip ls -l - name: Extract sync microservice files shell: bash + working-directory: sync-microservice/dist run: | - cd sync-microservice/dist unzip -o *.zip rm *.zip ls -l @@ -329,12 +212,19 @@ jobs: uses: actions/setup-node@v4 with: node-version: lts/* + cache: 'npm' + cache-dependency-path: frontend/package-lock.json - name: Install Rust stable uses: dtolnay/rust-toolchain@stable with: targets: ${{ matrix.platform == 'macos-latest' && 'aarch64-apple-darwin' || '' }} + - name: Rust cache + uses: swatinem/rust-cache@v2 + with: + workspaces: frontend/src-tauri + - name: Install dependencies (ubuntu only) if: matrix.platform == 'ubuntu-22.04' run: | @@ -342,8 +232,8 @@ jobs: sudo apt-get install -y libwebkit2gtk-4.0-dev libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf - name: Install frontend dependencies + working-directory: frontend run: | - cd frontend npm install - uses: tauri-apps/tauri-action@v0 diff --git a/.github/workflows/pr-check-build.yml b/.github/workflows/pr-check-build.yml index a5d1a18f5..b01f45d6c 100644 --- a/.github/workflows/pr-check-build.yml +++ b/.github/workflows/pr-check-build.yml @@ -2,11 +2,20 @@ name: PR Check Build on: pull_request: paths: - - "frontend/**" + - "frontend/**" + +permissions: + contents: read + +concurrency: + group: pr-${{ github.event.pull_request.number }} + cancel-in-progress: true jobs: tauri-build-check: - name: Tauri Build Check + name: Tauri Build Check (${{matrix.platform}}) + timeout-minutes: 30 + strategy: fail-fast: false matrix: @@ -18,13 +27,17 @@ jobs: - platform: "windows-latest" args: "--features ci" runs-on: ${{ matrix.platform }} + steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 - name: setup node - uses: actions/setup-node@v4 + uses: actions/setup-node@v5 with: node-version: lts/* + cache: npm + cache-dependency-path: frontend/package-lock.json + - name: install Rust stable uses: dtolnay/rust-toolchain@stable @@ -35,12 +48,27 @@ jobs: if: matrix.platform == 'ubuntu-22.04' run: | sudo apt-get update - sudo apt-get install -y libwebkit2gtk-4.0-dev libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf + sudo apt-get install -y \ + libwebkit2gtk-4.0-dev \ + libwebkit2gtk-4.1-dev \ + libappindicator3-dev \ + librsvg2-dev \ + patchelf + + - name: Cache Cargo + uses: actions/cache@v4 + with: + path: | + frontend/src-tauri/target + ~/.cargo/registry + ~/.cargo/git + key: ${{ runner.os }}-cargo-${{ hashFiles('frontend/src-tauri/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo- - name: install frontend dependencies - run: | - cd frontend - npm install + working-directory: frontend + run: npm ci # - name: cache cargo registry and build # uses: actions/cache@v3 @@ -53,7 +81,7 @@ jobs: # restore-keys: | # ${{ runner.os }}-cargo- - - uses: tauri-apps/tauri-action@v0 + - uses: tauri-apps/tauri-action@v0.6.0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Don't worry, the below key is just a sample key for PR-Checks. Actual app build workflow uses a secret private key :) diff --git a/.github/workflows/pr-check-tests.yml b/.github/workflows/pr-check-tests.yml index 09be0ddee..84cfce30c 100644 --- a/.github/workflows/pr-check-tests.yml +++ b/.github/workflows/pr-check-tests.yml @@ -5,86 +5,147 @@ on: branches: - main +permissions: + contents: read + + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + + jobs: linting: + name: Linting runs-on: ubuntu-latest - name: Linting + timeout-minutes: 15 steps: - - name: Checkout Code - uses: actions/checkout@v3 + - name: Checkout Code + uses: actions/checkout@v5 - - name: Set up Node.js - uses: actions/setup-node@v3 + - name: Set up Node.js + uses: actions/setup-node@v5 + with: + node-version: "22" + cache: npm + cache-dependency-path: frontend/package-lock.json + + - name: Setup Python + uses: actions/setup-python@v6 + with: + python-version: "3.12" + cache: "pip" + cache-dependency-path: | + backend/requirements.txt + sync-microservice/requirements.txt + + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable with: - node-version: "18" + components: rustfmt - - name: Install Dependencies + - name: Cache Rust dependencies + uses: actions/cache@v4 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + frontend/src-tauri/target/ + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + + - name: Install Backend Dependencies + working-directory: backend run: | - cd frontend - npm install - cd .. - cd backend + python -m pip install --upgrade pip pip install pre-commit ruff black - cd .. - - name: Run Linters + + - name: Install Frontend Dependencies + working-directory: frontend + run: npm ci + + - name: Run Frontend Linters + working-directory: frontend run: | - cd frontend/ npm run lint:check npm run format:check - cd .. - cd backend/ - pre-commit run --config ../.pre-commit-config.yaml --all-files || exit 1 - cd .. - cd frontend/src-tauri/ - cargo fmt -- --check + - name: Run backend Linters + working-directory: backend + run: pre-commit run --config ../.pre-commit-config.yaml --all-files || exit 1 + + - name: Run Rust + working-directory: frontend/src-tauri + run: cargo fmt -- --check + + # Frontend Test Job frontend: - runs-on: ubuntu-latest + needs: [linting] + name: Frontend Tests + runs-on: ubuntu-latest + timeout-minutes: 15 steps: - name: Checkout Code - uses: actions/checkout@v3 + uses: actions/checkout@v5 - name: Set up Node.js - uses: actions/setup-node@v3 + uses: actions/setup-node@v5 with: - node-version: "18" + node-version: "22" + cache: npm + cache-dependency-path: frontend/package-lock.json - - name: Install Dependencies & Run Tests - run: | - cd frontend - npm install - npm test + - name: Install Dependencies + working-directory: frontend + run: npm ci + + - name: Run Tests + working-directory: frontend + run: npm test # Backend Test Job backend: - runs-on: ubuntu-latest + needs: [linting,frontend] name: Backend Tests + runs-on: ubuntu-latest steps: - name: Checkout Code - uses: actions/checkout@v3 + uses: actions/checkout@v5 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v6 with: - python-version: "3.11" + python-version: "3.12" + cache: "pip" + cache-dependency-path: | + backend/requirements.txt + sync-microservice/requirements.txt - - name: Build check(Main backend) + - name: Install Backend Dependencies + working-directory: backend run: | - cd backend python -m pip install --upgrade pip pip install -r requirements.txt - pyinstaller main.py --name PictoPy_Server --onedir --distpath dist - - name: Build check(Sync Microservice) + - name: Build Backend Executable + working-directory: backend + run: pyinstaller main.py --name PictoPy_Server --onedir --distpath dist + + - name: Install Micro Services Dependencies + working-directory: sync-microservice run: | - cd sync-microservice pip install -r requirements.txt - pyinstaller main.py --name PictoPy_Sync_Microservice --onedir --distpath dist + + - name: Build Sync Microservice Executable + working-directory: sync-microservice + run: pyinstaller main.py --name PictoPy_Sync_Microservice --onedir --distpath dist + - name: Run Tests - run: | - cd backend - pytest + working-directory: backend + run: pytest +