diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 86411f3c71..d140b80a3a 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -99,39 +99,77 @@ jobs: - name: run unit tests working-directory: ./packages/nocodb run: pnpm run test:unit:pg + + pre-build-for-playwright: + uses: ./.github/workflows/pre-build-for-playwright.yml + playwright-mysql-1: + needs: pre-build-for-playwright if: ${{ github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'trigger-CI') || !github.event.pull_request.draft }} uses: ./.github/workflows/playwright-test-workflow.yml with: db: mysql shard: 1 playwright-mysql-2: + needs: pre-build-for-playwright if: ${{ github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'trigger-CI') || !github.event.pull_request.draft }} uses: ./.github/workflows/playwright-test-workflow.yml with: db: mysql shard: 2 + playwright-mysql-3: + needs: playwright-mysql-1 + if: ${{ always() && ( github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'trigger-CI') || !github.event.pull_request.draft )}} + uses: ./.github/workflows/playwright-test-workflow.yml + with: + db: mysql + shard: 3 + playwright-mysql-4: + needs: playwright-mysql-2 + if: ${{ always() && ( github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'trigger-CI') || !github.event.pull_request.draft )}} + uses: ./.github/workflows/playwright-test-workflow.yml + with: + db: mysql + shard: 4 playwright-sqlite-1: + needs: pre-build-for-playwright if: ${{ github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'trigger-CI') || !github.event.pull_request.draft }} uses: ./.github/workflows/playwright-test-workflow.yml with: db: sqlite shard: 1 playwright-sqlite-2: + needs: pre-build-for-playwright if: ${{ github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'trigger-CI') || !github.event.pull_request.draft }} uses: ./.github/workflows/playwright-test-workflow.yml with: db: sqlite shard: 2 playwright-pg-shard-1: + needs: pre-build-for-playwright if: ${{ github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'trigger-CI') || !github.event.pull_request.draft }} uses: ./.github/workflows/playwright-test-workflow.yml with: db: pg shard: 1 playwright-pg-shard-2: + needs: pre-build-for-playwright if: ${{ github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'trigger-CI') || !github.event.pull_request.draft }} uses: ./.github/workflows/playwright-test-workflow.yml with: db: pg shard: 2 + playwright-pg-shard-3: + needs: playwright-pg-shard-1 + if: ${{ always() && ( github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'trigger-CI') || !github.event.pull_request.draft )}} + uses: ./.github/workflows/playwright-test-workflow.yml + with: + db: pg + shard: 3 + playwright-pg-shard-4: + needs: playwright-pg-shard-2 + if: ${{ always() && ( github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'trigger-CI') || !github.event.pull_request.draft ) }} + uses: ./.github/workflows/playwright-test-workflow.yml + with: + db: pg + shard: 4 diff --git a/.github/workflows/playwright-test-workflow.yml b/.github/workflows/playwright-test-workflow.yml index 9cccaa26db..82830b94be 100644 --- a/.github/workflows/playwright-test-workflow.yml +++ b/.github/workflows/playwright-test-workflow.yml @@ -18,11 +18,32 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 + - name: pre-requisite checks + shell: bash + run: | + node_version=$(node --version || echo "error") + pnpm_version=$(pnpm -v || echo "error") + echo "node version: $node_version" + echo "pnpm version: $pnpm_version" + if [[ $node_version != v18* ]] || [[ $pnp_version != 8* ]]; then + echo "version mismatch: expected node v18 and pnpm v8" + RUN_PRERQUISITE_STEPS="true" + elif [[ ${FORCE_RUN_PRERQUISITE_STEPS} == "true" ]]; + # || [[ ! -f ${PRE_REQ_CHECK_FILE_PATH} ]]; + then + echo "FORCE_RUN_PRERQUISITE_STEPS is true" + RUN_PRERQUISITE_STEPS="true" + else + RUN_PRERQUISITE_STEPS="false" + fi + echo "RUN_PRERQUISITE_STEPS=${RUN_PRERQUISITE_STEPS}" >> $GITHUB_ENV - name: Setup Node + if: env.RUN_PRERQUISITE_STEPS == 'true' uses: actions/setup-node@v3 with: node-version: 18.14.0 - name: Setup pnpm + if: env.RUN_PRERQUISITE_STEPS == 'true' uses: pnpm/action-setup@v2 with: version: 8 @@ -31,6 +52,7 @@ jobs: run: | echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV - uses: actions/cache@v3 + if: env.RUN_PRERQUISITE_STEPS == 'true' name: Setup pnpm cache with: path: ${{ env.STORE_PATH }} @@ -46,8 +68,6 @@ jobs: sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD 'password';" sudo -u postgres psql -c "ALTER USER postgres WITH SUPERUSER;" service postgresql restart - - name: Set CI env - run: export CI=true - name: Kill stale servers run: | # export NODE_OPTIONS=\"--max_old_space_size=16384\"; @@ -78,10 +98,6 @@ jobs: working-directory: ./packages/nocodb/tests/pg-cy-quick/ run: | sudo -u postgres psql -U postgres -f 01-cy-quick.sql - - name: run frontend - working-directory: ./packages/nc-gui - run: pnpm run ci:run - timeout-minutes: 20 - name: Run backend if: ${{ inputs.db == 'sqlite' }} working-directory: ./packages/nocodb @@ -97,15 +113,38 @@ jobs: working-directory: ./packages/nocodb run: | pnpm run watch:run:playwright:pg &> ${{ inputs.db }}_${{ inputs.shard }}_test_backend.log & + - name: copy built output and start frontend + if: always() + working-directory: ./ + run: | + # expects the variables to be available in runner context. + path="gh-artifacts/runs/${GITHUB_RUN_ID}/ui-build/.output" + target_dir="/mnt/${path}" + mkdir -p ${target_dir} + if [[ -d ${target_dir} ]]; then + echo "Directory ${target_dir} exists." + cp -r ${target_dir} ./packages/nc-gui/ || echo "playwright reports directory does not exists" >> ${target_dir}/playwright-report/index.html + else + echo "Error: Directory ${target_dir} does not exists." + exit 1 + fi + cd ./packages/nc-gui/ + pnpm run ci:start - name: Install Playwright Browsers working-directory: ./tests/playwright run: pnpm exec playwright install --with-deps chromium - - name: Wait for backend + - name: Wait for frontend and backend run: | - while ! curl --output /dev/null --silent --head --fail http://localhost:8080; do + while ! curl --output /dev/null --silent --head --fail http://localhost:3000; do printf '.' sleep 2 done + echo "Frontend is up" + while ! curl --output /dev/null --silent --head --fail http://localhost:8080; do + printf '.' + sleep 2 + done + echo "Backend is up" timeout-minutes: 2 - name: Run Playwright Tests working-directory: ./tests/playwright diff --git a/.github/workflows/pre-build-for-playwright.yml b/.github/workflows/pre-build-for-playwright.yml new file mode 100644 index 0000000000..520f3b74d8 --- /dev/null +++ b/.github/workflows/pre-build-for-playwright.yml @@ -0,0 +1,80 @@ +name: pre-build-for-playwright + +on: + workflow_call: + inputs: + FORCE_RUN_PRERQUISITE_STEPS: + description: 'FORCE_RUN_PRERQUISITE_STEPS' + required: false + type: string + default: 'false' + +jobs: + playwright: + runs-on: [self-hosted, aws] + timeout-minutes: 100 + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: pre-requisite checks + shell: bash + run: | + node_version=$(node --version || echo "error") + pnpm_version=$(pnpm -v || echo "error") + echo "node version: $node_version" + echo "pnpm version: $pnpm_version" + if [[ $node_version != v18* ]] || [[ $pnp_version != 8* ]]; then + echo "version mismatch: expected node v18 and pnpm v8" + RUN_PRERQUISITE_STEPS="true" + elif [[ ${FORCE_RUN_PRERQUISITE_STEPS} == "true" ]]; + # || [[ ! -f ${PRE_REQ_CHECK_FILE_PATH} ]]; + then + echo "FORCE_RUN_PRERQUISITE_STEPS is true" + RUN_PRERQUISITE_STEPS="true" + else + RUN_PRERQUISITE_STEPS="false" + fi + echo "RUN_PRERQUISITE_STEPS=${RUN_PRERQUISITE_STEPS}" >> $GITHUB_ENV + - name: Setup Node + if: env.RUN_PRERQUISITE_STEPS == 'true' + uses: actions/setup-node@v3 + with: + node-version: 18.14.0 + - name: Setup pnpm + if: env.RUN_PRERQUISITE_STEPS == 'true' + uses: pnpm/action-setup@v2 + with: + version: 8 + - name: Get pnpm store directory + shell: bash + run: | + echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV + - uses: actions/cache@v3 + if: env.RUN_PRERQUISITE_STEPS == 'true' + name: Setup pnpm cache + with: + path: ${{ env.STORE_PATH }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- + - name: install dependencies + run: pnpm bootstrap + - name: run frontend + working-directory: ./packages/nc-gui + run: | + pnpm run build + timeout-minutes: 20 + - name: Copy Artifacts to Local Artifacts Dir + if: always() + working-directory: ./ + run: | + # expects the variables to be available in runner context. + path="gh-artifacts/runs/${GITHUB_RUN_ID}/ui-build/" + target_dir="/mnt/${path}" + mkdir -p ${target_dir} + + # start : add any artifacts to be copied here + cp -r ./packages/nc-gui/.output ${target_dir}/ || echo "playwright reports directory does not exists" >> ${target_dir}/playwright-report/index.html + + SUMMARY='[UI BUILD](http://65.21.27.147/'${path}')' + echo "$SUMMARY" >> $GITHUB_STEP_SUMMARY diff --git a/packages/nc-gui/package.json b/packages/nc-gui/package.json index c895f58dbe..637df820cb 100644 --- a/packages/nc-gui/package.json +++ b/packages/nc-gui/package.json @@ -31,6 +31,7 @@ "build:copy": "pnpm run generate; rm -rf ../nc-lib-gui/lib/dist/; rsync -rvzh ./dist/ ../nc-lib-gui/lib/dist/", "build:copy:publish": "pnpm run generate; rm -rf ../nc-lib-gui/lib/dist/; rsync -rvzh ./dist/ ../nc-lib-gui/lib/dist/; pnpm publish ../nc-lib-gui", "ci:run": "export NODE_OPTIONS=\"--max_old_space_size=16384\"; pnpm install; pnpm run build; NUXT_PAGE_TRANSITION_DISABLE=true NUXT_PUBLIC_NC_BACKEND_URL=http://localhost:8080 pnpm run start &", + "ci:start": "export NODE_OPTIONS=\"--max_old_space_size=16384\"; NUXT_PAGE_TRANSITION_DISABLE=true NUXT_PUBLIC_NC_BACKEND_URL=http://localhost:8080 pnpm run start &", "preinstall": "npx only-allow pnpm", "postinstall": "nuxt prepare" }, diff --git a/tests/playwright/package.json b/tests/playwright/package.json index 2fc168cf61..6afc99ec4f 100644 --- a/tests/playwright/package.json +++ b/tests/playwright/package.json @@ -23,8 +23,10 @@ "scripts": { "test": "TRACE=true pnpm exec playwright test --workers=4", "test:fast": "pnpm exec playwright test --workers=6", - "test:shard:1": "TRACE=true pnpm exec playwright test --workers=4 --shard=1/2", - "test:shard:2": "TRACE=true pnpm exec playwright test --workers=4 --shard=2/2", + "test:shard:1": "TRACE=true pnpm exec playwright test --workers=4 --shard=1/4", + "test:shard:2": "TRACE=true pnpm exec playwright test --workers=4 --shard=2/4", + "test:shard:3": "TRACE=true pnpm exec playwright test --workers=4 --shard=3/4", + "test:shard:4": "TRACE=true pnpm exec playwright test --workers=4 --shard=4/4", "test:repeat": "TRACE=true pnpm exec playwright test --workers=4 --repeat-each=12", "test:quick": "TRACE=true PW_QUICK_TEST=1 pnpm exec playwright test --workers=4", "test:debug": "./startPlayWrightServer.sh; PW_TEST_REUSE_CONTEXT=1 PW_TEST_CONNECT_WS_ENDPOINT=ws://127.0.0.1:31000/ PWDEBUG=console pnpm exec playwright test -c playwright.config.ts --headed --project=chromium --retries 0 --timeout 0 --workers 1 --max-failures=1", @@ -32,8 +34,10 @@ "test:debug:watch": "pnpm dlx nodemon -e ts -w ./ -x \"pnpm run test:debug\"", "test:debug:quick:sqlite": "./startPlayWrightServer.sh; PW_QUICK_TEST=1 PW_TEST_REUSE_CONTEXT=1 PW_TEST_CONNECT_WS_ENDPOINT=ws://127.0.0.1:31000/ PWDEBUG=console pnpm exec playwright test -c playwright.config.ts --headed --project=chromium --retries 0 --timeout 5 --workers 1 --max-failures=1", "ci:test": "pnpm exec playwright test --workers=2", - "ci:test:shard:1": "pnpm exec playwright test --workers=2 --shard=1/2", - "ci:test:shard:2": "pnpm exec playwright test --workers=2 --shard=2/2", + "ci:test:shard:1": "pnpm exec playwright test --workers=4 --shard=1/4", + "ci:test:shard:2": "pnpm exec playwright test --workers=4 --shard=2/4", + "ci:test:shard:3": "pnpm exec playwright test --workers=4 --shard=3/4", + "ci:test:shard:4": "pnpm exec playwright test --workers=4 --shard=4/4", "ci:test:mysql": "E2E_DB_TYPE=mysql pnpm exec playwright test --workers=2", "ci:test:pg": "E2E_DB_TYPE=pg pnpm exec playwright test --workers=2", "preinstall": "npx only-allow pnpm"