From 3886fc4451e7454f159d31590dc1ab4e892c381f Mon Sep 17 00:00:00 2001 From: nathan Date: Fri, 3 Oct 2025 00:08:40 +0800 Subject: [PATCH 1/5] chore: optimize ci --- .github/workflows/integration-test.yml | 102 +++++++++++++++++-------- cypress.config.ts | 5 +- 2 files changed, 74 insertions(+), 33 deletions(-) diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index 3273e695..b5c379a3 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -13,6 +13,11 @@ env: jobs: run_e2e_tests: runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + # Split tests across 4 parallel jobs for 4x speedup + shard: [1, 2, 3, 4] steps: - name: Checkout code uses: actions/checkout@v4 @@ -27,6 +32,30 @@ jobs: with: version: 10.9.0 + # Cache pnpm dependencies for faster installs + - name: Get pnpm store directory + id: pnpm-cache + shell: bash + run: | + echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT + + - name: Cache pnpm dependencies + uses: actions/cache@v4 + with: + path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- + + # Cache Cypress binary for faster setup + - name: Cache Cypress binary + uses: actions/cache@v4 + with: + path: ~/.cache/Cypress + key: ${{ runner.os }}-cypress-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-cypress- + - name: Install dependencies run: | pnpm install --frozen-lockfile @@ -63,61 +92,66 @@ jobs: username: ${{ secrets.DOCKER_HUB_USERNAME }} password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} - - name: Run Docker-Compose (without web service) + - name: Start Docker services working-directory: AppFlowy-Cloud-Premium env: APPFLOWY_CLOUD_VERSION: ${{ env.CLOUD_VERSION }} APPFLOWY_AI_VERSION: ${{ env.CLOUD_VERSION }} APPFLOWY_WORKER_VERSION: ${{ env.CLOUD_VERSION }} - RUST_LOG: appflowy_cloud=debug + RUST_LOG: appflowy_cloud=info run: | - # Pull and start all backend services (excluding web) + # Pull and start all backend services docker compose pull appflowy_cloud gotrue ai appflowy_worker docker compose -f docker-compose-web-ci.yml up -d - - # Wait for services to be ready - echo "Waiting for services to start..." - sleep 30 - - # Check health - for i in {1..30}; do - if curl -sf http://localhost/api/health > /dev/null 2>&1; then - echo "✓ Backend is ready" - break - fi - echo "Waiting for backend... (attempt $i/30)" - sleep 5 - done + + # Optimized health check with timeout + echo "Waiting for backend services..." + timeout 90 bash -c 'until curl -sf http://localhost/api/health > /dev/null 2>&1; do + echo "Waiting for backend... ($(date +%T))" + sleep 3 + done' && echo "✓ Backend is ready" || (echo "❌ Backend failed to start" && exit 1) + + # Cache build artifacts + - name: Cache build + id: cache-build + uses: actions/cache@v4 + with: + path: dist + key: ${{ runner.os }}-build-${{ hashFiles('src/**/*', 'package.json', 'vite.config.ts', 'tsconfig.json') }} + restore-keys: | + ${{ runner.os }}-build- - name: Build project + if: steps.cache-build.outputs.cache-hit != 'true' run: pnpm run build - name: Start preview server run: | pnpm run start & echo $! > preview-server.pid - - # Wait for preview server - for i in {1..30}; do - if curl -sf http://localhost:3000 > /dev/null 2>&1; then - echo "✓ Preview server is ready" - break - fi - echo "Waiting for preview server... (attempt $i/30)" - sleep 3 - done - - name: Run tests - run: pnpm cypress run --spec 'cypress/e2e/**/*.cy.ts' + # Optimized preview server health check + timeout 60 bash -c 'until curl -sf http://localhost:3000 > /dev/null 2>&1; do + echo "Waiting for preview server... ($(date +%T))" + sleep 2 + done' && echo "✓ Preview server is ready" || (echo "❌ Preview server failed to start" && exit 1) + + - name: Run tests (shard ${{ matrix.shard }}/4) + run: | + pnpm cypress run \ + --spec 'cypress/e2e/**/*.cy.ts' \ + --config video=false + env: + CYPRESS_SHARD: ${{ matrix.shard }} + CYPRESS_TOTAL_SHARDS: 4 - name: Upload artifacts if: always() uses: actions/upload-artifact@v4 with: - name: test-results + name: test-results-shard-${{ matrix.shard }} path: | cypress/screenshots/** - cypress/videos/** cypress/logs/** if-no-files-found: ignore retention-days: 3 @@ -125,7 +159,11 @@ jobs: - name: Cleanup if: always() run: | + # Kill preview server if [ -f preview-server.pid ]; then - kill $(cat preview-server.pid) || true + kill $(cat preview-server.pid) 2>/dev/null || true fi + pkill -f "vite preview" 2>/dev/null || true + + # Stop Docker services cd AppFlowy-Cloud-Premium && docker compose down || true \ No newline at end of file diff --git a/cypress.config.ts b/cypress.config.ts index aa72b4bf..a46d2702 100644 --- a/cypress.config.ts +++ b/cypress.config.ts @@ -22,6 +22,8 @@ export default defineConfig({ // Set viewport to MacBook Pro screen size viewportWidth: 1440, viewportHeight: 900, + // Disable video in CI for faster execution + video: process.env.CI ? false : true, setupNodeEvents(on, config) { // Configure browser launch options on('before:browser:launch', (browser, launchOptions) => { @@ -129,7 +131,8 @@ export default defineConfig({ }, chromeWebSecurity: false, retries: { - runMode: 3, + // Reduce retries in CI for faster feedback + runMode: process.env.CI ? 1 : 3, openMode: 0, }, }); From eb7ea7e11bf26d8f2da6348ecf835ffa616e4051 Mon Sep 17 00:00:00 2001 From: nathan Date: Fri, 3 Oct 2025 08:52:50 +0800 Subject: [PATCH 2/5] chore: optimize ci --- .github/workflows/integration-test.yml | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index b5c379a3..19608257 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -16,8 +16,8 @@ jobs: strategy: fail-fast: false matrix: - # Split tests across 4 parallel jobs for 4x speedup - shard: [1, 2, 3, 4] + # Split tests across 2 parallel jobs for better reliability + shard: [1, 2] steps: - name: Checkout code uses: actions/checkout@v4 @@ -104,12 +104,19 @@ jobs: docker compose pull appflowy_cloud gotrue ai appflowy_worker docker compose -f docker-compose-web-ci.yml up -d - # Optimized health check with timeout + # Extended health check with detailed logging echo "Waiting for backend services..." - timeout 90 bash -c 'until curl -sf http://localhost/api/health > /dev/null 2>&1; do + timeout 180 bash -c 'until curl -sf http://localhost/api/health > /dev/null 2>&1; do echo "Waiting for backend... ($(date +%T))" - sleep 3 - done' && echo "✓ Backend is ready" || (echo "❌ Backend failed to start" && exit 1) + sleep 5 + done' && echo "✓ Backend is ready" || ( + echo "❌ Backend failed to start after 3 minutes" + echo "Docker container status:" + docker compose -f docker-compose-web-ci.yml ps + echo "Docker logs:" + docker compose -f docker-compose-web-ci.yml logs --tail=50 + exit 1 + ) # Cache build artifacts - name: Cache build @@ -136,14 +143,14 @@ jobs: sleep 2 done' && echo "✓ Preview server is ready" || (echo "❌ Preview server failed to start" && exit 1) - - name: Run tests (shard ${{ matrix.shard }}/4) + - name: Run tests (shard ${{ matrix.shard }}/2) run: | pnpm cypress run \ --spec 'cypress/e2e/**/*.cy.ts' \ --config video=false env: CYPRESS_SHARD: ${{ matrix.shard }} - CYPRESS_TOTAL_SHARDS: 4 + CYPRESS_TOTAL_SHARDS: 2 - name: Upload artifacts if: always() From 8227ae0a31fbf4302ec64bfae5992c71064fe4e3 Mon Sep 17 00:00:00 2001 From: nathan Date: Sat, 4 Oct 2025 11:21:05 +0800 Subject: [PATCH 3/5] chore: optimize ci --- .github/workflows/integration-test.yml | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index 19608257..f3e7aca5 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -13,11 +13,6 @@ env: jobs: run_e2e_tests: runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - # Split tests across 2 parallel jobs for better reliability - shard: [1, 2] steps: - name: Checkout code uses: actions/checkout@v4 @@ -143,20 +138,17 @@ jobs: sleep 2 done' && echo "✓ Preview server is ready" || (echo "❌ Preview server failed to start" && exit 1) - - name: Run tests (shard ${{ matrix.shard }}/2) + - name: Run tests run: | pnpm cypress run \ --spec 'cypress/e2e/**/*.cy.ts' \ --config video=false - env: - CYPRESS_SHARD: ${{ matrix.shard }} - CYPRESS_TOTAL_SHARDS: 2 - name: Upload artifacts if: always() uses: actions/upload-artifact@v4 with: - name: test-results-shard-${{ matrix.shard }} + name: test-results path: | cypress/screenshots/** cypress/logs/** From bd80656815d87dc87874f06e7ba9478eb648cbc6 Mon Sep 17 00:00:00 2001 From: nathan Date: Thu, 9 Oct 2025 10:32:09 +0800 Subject: [PATCH 4/5] chore: test --- .github/workflows/integration-test.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index f3e7aca5..47e360ec 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -100,18 +100,18 @@ jobs: docker compose -f docker-compose-web-ci.yml up -d # Extended health check with detailed logging - echo "Waiting for backend services..." - timeout 180 bash -c 'until curl -sf http://localhost/api/health > /dev/null 2>&1; do - echo "Waiting for backend... ($(date +%T))" - sleep 5 - done' && echo "✓ Backend is ready" || ( - echo "❌ Backend failed to start after 3 minutes" - echo "Docker container status:" - docker compose -f docker-compose-web-ci.yml ps - echo "Docker logs:" - docker compose -f docker-compose-web-ci.yml logs --tail=50 - exit 1 - ) + # echo "Waiting for backend services..." + # timeout 180 bash -c 'until curl -sf http://localhost/api/health > /dev/null 2>&1; do + # echo "Waiting for backend... ($(date +%T))" + # sleep 5 + # done' && echo "✓ Backend is ready" || ( + # echo "❌ Backend failed to start after 3 minutes" + # echo "Docker container status:" + # docker compose -f docker-compose-web-ci.yml ps + # echo "Docker logs:" + # docker compose -f docker-compose-web-ci.yml logs --tail=50 + # exit 1 + # ) # Cache build artifacts - name: Cache build From 3bee21b79a36837d1f74c51931126be73c3b256e Mon Sep 17 00:00:00 2001 From: nathan Date: Thu, 9 Oct 2025 11:32:32 +0800 Subject: [PATCH 5/5] chore: use health endpoint --- .github/workflows/integration-test.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index 47e360ec..f3e7aca5 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -100,18 +100,18 @@ jobs: docker compose -f docker-compose-web-ci.yml up -d # Extended health check with detailed logging - # echo "Waiting for backend services..." - # timeout 180 bash -c 'until curl -sf http://localhost/api/health > /dev/null 2>&1; do - # echo "Waiting for backend... ($(date +%T))" - # sleep 5 - # done' && echo "✓ Backend is ready" || ( - # echo "❌ Backend failed to start after 3 minutes" - # echo "Docker container status:" - # docker compose -f docker-compose-web-ci.yml ps - # echo "Docker logs:" - # docker compose -f docker-compose-web-ci.yml logs --tail=50 - # exit 1 - # ) + echo "Waiting for backend services..." + timeout 180 bash -c 'until curl -sf http://localhost/api/health > /dev/null 2>&1; do + echo "Waiting for backend... ($(date +%T))" + sleep 5 + done' && echo "✓ Backend is ready" || ( + echo "❌ Backend failed to start after 3 minutes" + echo "Docker container status:" + docker compose -f docker-compose-web-ci.yml ps + echo "Docker logs:" + docker compose -f docker-compose-web-ci.yml logs --tail=50 + exit 1 + ) # Cache build artifacts - name: Cache build