From 04ef477f3b2fe8fc28c256d47f2ee1728c75ac14 Mon Sep 17 00:00:00 2001 From: Bijin A B Date: Sun, 22 Feb 2026 16:51:10 +0530 Subject: [PATCH] feat(CI): refactor github workflow for tests (#7252) --- .../actions/common/setup-node-deps/action.yml | 10 +- .../actions/tests/run-cli-tests/action.yml | 20 +++ .../actions/tests/run-e2e-tests/action.yml | 22 +++ .../actions/tests/run-unit-tests/action.yml | 48 ++++++ .github/workflows/lint-checks.yml | 26 ++++ .github/workflows/tests.yml | 146 +++++------------- 6 files changed, 162 insertions(+), 110 deletions(-) create mode 100644 .github/actions/tests/run-cli-tests/action.yml create mode 100644 .github/actions/tests/run-e2e-tests/action.yml create mode 100644 .github/actions/tests/run-unit-tests/action.yml create mode 100644 .github/workflows/lint-checks.yml diff --git a/.github/actions/common/setup-node-deps/action.yml b/.github/actions/common/setup-node-deps/action.yml index 66c32f298..b9860c35f 100644 --- a/.github/actions/common/setup-node-deps/action.yml +++ b/.github/actions/common/setup-node-deps/action.yml @@ -1,5 +1,10 @@ name: 'Setup Node Dependencies' description: 'Install Node.js and npm dependencies' +inputs: + skip-build: + description: 'Skip building libraries' + required: false + default: 'false' runs: using: 'composite' steps: @@ -9,12 +14,13 @@ runs: node-version: v22.17.0 cache: 'npm' cache-dependency-path: './package-lock.json' - + - name: Install node dependencies shell: bash run: npm ci --legacy-peer-deps - + - name: Build libraries + if: inputs.skip-build != 'true' shell: bash run: | npm run build:graphql-docs diff --git a/.github/actions/tests/run-cli-tests/action.yml b/.github/actions/tests/run-cli-tests/action.yml new file mode 100644 index 000000000..526d7dba2 --- /dev/null +++ b/.github/actions/tests/run-cli-tests/action.yml @@ -0,0 +1,20 @@ +name: 'Run CLI Tests' +description: 'Setup dependencies, start local testbench and run CLI tests' +runs: + using: 'composite' + steps: + - name: Run Local Testbench + shell: bash + run: | + npm start --workspace=packages/bruno-tests & + sleep 5 + + - name: Install Test Collection Dependencies + shell: bash + run: npm ci --prefix packages/bruno-tests/collection + + - name: Run CLI Tests + shell: bash + run: | + cd packages/bruno-tests/collection + node ../../bruno-cli/bin/bru.js run --env Prod --output junit.xml --format junit --sandbox developer diff --git a/.github/actions/tests/run-e2e-tests/action.yml b/.github/actions/tests/run-e2e-tests/action.yml new file mode 100644 index 000000000..e2b1ffd9e --- /dev/null +++ b/.github/actions/tests/run-e2e-tests/action.yml @@ -0,0 +1,22 @@ +name: 'Run E2E Tests' +description: 'Setup dependencies, configure environment, and run Playwright E2E tests' +inputs: + os: + description: 'Operating system (ubuntu, macos, windows)' + default: 'ubuntu' +runs: + using: 'composite' + steps: + - name: Install Test Collection Dependencies + shell: bash + run: npm ci --prefix packages/bruno-tests/collection + + - name: Run Playwright Tests (Ubuntu) + if: inputs.os == 'ubuntu' + shell: bash + run: xvfb-run npm run test:e2e + + - name: Run Playwright Tests + if: inputs.os != 'ubuntu' + shell: bash + run: npm run test:e2e diff --git a/.github/actions/tests/run-unit-tests/action.yml b/.github/actions/tests/run-unit-tests/action.yml new file mode 100644 index 000000000..58569d523 --- /dev/null +++ b/.github/actions/tests/run-unit-tests/action.yml @@ -0,0 +1,48 @@ +name: 'Run Unit Tests' +description: 'Setup dependencies and run unit tests for all packages' +runs: + using: 'composite' + steps: + - name: Test Package bruno-js + shell: bash + run: npm run test --workspace=packages/bruno-js + + - name: Test Package bruno-cli + shell: bash + run: npm run test --workspace=packages/bruno-cli + + - name: Test Package bruno-query + shell: bash + run: npm run test --workspace=packages/bruno-query + + - name: Test Package bruno-lang + shell: bash + run: npm run test --workspace=packages/bruno-lang + + - name: Test Package bruno-schema + shell: bash + run: npm run test --workspace=packages/bruno-schema + + - name: Test Package bruno-app + shell: bash + run: npm run test --workspace=packages/bruno-app + + - name: Test Package bruno-common + shell: bash + run: npm run test --workspace=packages/bruno-common + + - name: Test Package bruno-converters + shell: bash + run: npm run test --workspace=packages/bruno-converters + + - name: Test Package bruno-electron + shell: bash + run: npm run test --workspace=packages/bruno-electron + + - name: Test Package bruno-requests + shell: bash + run: npm run test --workspace=packages/bruno-requests + + - name: Test Package bruno-filestore + shell: bash + run: npm run test --workspace=packages/bruno-filestore diff --git a/.github/workflows/lint-checks.yml b/.github/workflows/lint-checks.yml new file mode 100644 index 000000000..7dfa5b5f2 --- /dev/null +++ b/.github/workflows/lint-checks.yml @@ -0,0 +1,26 @@ +name: Lint Checks +on: + workflow_dispatch: + push: + branches: [main, 'release/v*'] + pull_request: + branches: [main, 'release/v*'] + +jobs: + lint: + name: Lint Check + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - uses: actions/checkout@v6 + + - name: Setup Node Dependencies + uses: ./.github/actions/common/setup-node-deps + with: + skip-build: 'true' + + - name: Lint Check + run: npm run lint + env: + ESLINT_PLUGIN_DIFF_COMMIT: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.ref || 'main' }} \ No newline at end of file diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0fa88640a..d996ee8c1 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,9 +1,10 @@ name: Tests on: + workflow_dispatch: push: - branches: [main] + branches: [main, 'release/v*'] pull_request: - branches: [main] + branches: [main, 'release/v*'] jobs: unit-test: @@ -14,52 +15,12 @@ jobs: contents: read steps: - uses: actions/checkout@v6 - - uses: actions/setup-node@v5 - with: - node-version-file: '.nvmrc' - cache: 'npm' - cache-dependency-path: './package-lock.json' - - name: Install dependencies - run: npm ci --legacy-peer-deps - # build libraries - - name: Build libraries - run: | - npm run build --workspace=packages/bruno-common - npm run build --workspace=packages/bruno-query - npm run sandbox:bundle-libraries --workspace=packages/bruno-js - npm run build --workspace=packages/bruno-converters - npm run build --workspace=packages/bruno-requests - npm run build --workspace=packages/bruno-schema-types - npm run build --workspace=packages/bruno-filestore + - name: Setup Node Dependencies + uses: ./.github/actions/common/setup-node-deps - - name: Lint Check - run: npm run lint - env: - ESLINT_PLUGIN_DIFF_COMMIT: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.ref || 'main' }} - - # tests - - name: Test Package bruno-js - run: npm run test --workspace=packages/bruno-js - - name: Test Package bruno-cli - run: npm run test --workspace=packages/bruno-cli - - - name: Test Package bruno-query - run: npm run test --workspace=packages/bruno-query - - name: Test Package bruno-lang - run: npm run test --workspace=packages/bruno-lang - - name: Test Package bruno-schema - run: npm run test --workspace=packages/bruno-schema - - name: Test Package bruno-app - run: npm run test --workspace=packages/bruno-app - - name: Test Package bruno-common - run: npm run test --workspace=packages/bruno-common - - name: Test Package bruno-converters - run: npm run test --workspace=packages/bruno-converters - - name: Test Package bruno-electron - run: npm run test --workspace=packages/bruno-electron - - name: Test Package bruno-requests - run: npm run test --workspace=packages/bruno-requests + - name: Run Unit Tests + uses: ./.github/actions/tests/run-unit-tests cli-test: name: CLI Tests @@ -70,35 +31,12 @@ jobs: contents: read steps: - uses: actions/checkout@v6 - - uses: actions/setup-node@v5 - with: - node-version-file: '.nvmrc' - cache: 'npm' - cache-dependency-path: './package-lock.json' - - name: Install dependencies - run: npm ci --legacy-peer-deps + - name: Setup Node Dependencies + uses: ./.github/actions/common/setup-node-deps - - name: Build Libraries - run: | - npm run build --workspace=packages/bruno-query - npm run build --workspace=packages/bruno-common - npm run sandbox:bundle-libraries --workspace=packages/bruno-js - npm run build --workspace=packages/bruno-converters - npm run build --workspace=packages/bruno-requests - npm run build --workspace=packages/bruno-schema-types - npm run build --workspace=packages/bruno-filestore - - - name: Run Local Testbench - run: | - npm start --workspace=packages/bruno-tests & - sleep 5 - - - name: Run tests - run: | - cd packages/bruno-tests/collection - npm install - node ../../bruno-cli/bin/bru.js run --env Prod --output junit.xml --format junit --sandbox developer + - name: Run CLI Tests + uses: ./.github/actions/tests/run-cli-tests - name: Publish Test Report uses: EnricoMi/publish-unit-test-result-action@v2 @@ -107,46 +45,38 @@ jobs: check_name: CLI Test Results files: packages/bruno-tests/collection/junit.xml comment_mode: always + e2e-test: name: Playwright E2E Tests timeout-minutes: 60 runs-on: ubuntu-24.04 steps: - - uses: actions/checkout@v6 - - uses: actions/setup-node@v5 - with: - node-version: v22.11.x - - name: Install dependencies - run: | - sudo apt-get update - sudo apt-get --no-install-recommends install -y \ - libglib2.0-0 libnss3 libdbus-1-3 libatk1.0-0 libatk-bridge2.0-0 libcups2 libgtk-3-0 libasound2t64 \ - xvfb - npm ci --legacy-peer-deps - sudo chown root /home/runner/work/bruno/bruno/node_modules/electron/dist/chrome-sandbox - sudo chmod 4755 /home/runner/work/bruno/bruno/node_modules/electron/dist/chrome-sandbox + - uses: actions/checkout@v6 - - name: Install dependencies for test collection environment - run: | - npm ci --prefix packages/bruno-tests/collection + - name: Install System Dependencies (Ubuntu) + run: | + sudo apt-get update + sudo apt-get --no-install-recommends install -y \ + libglib2.0-0 libnss3 libdbus-1-3 libatk1.0-0 libatk-bridge2.0-0 libcups2 libgtk-3-0 libasound2t64 \ + xvfb - - name: Build libraries - run: | - npm run build:graphql-docs - npm run build:bruno-query - npm run build:bruno-common - npm run sandbox:bundle-libraries --workspace=packages/bruno-js - npm run build:bruno-converters - npm run build:bruno-requests - npm run build:schema-types - npm run build:bruno-filestore + - name: Setup Node Dependencies + uses: ./.github/actions/common/setup-node-deps - - name: Run Playwright tests - run: | - xvfb-run npm run test:e2e - - uses: actions/upload-artifact@v6 - if: ${{ !cancelled() }} - with: - name: playwright-report - path: playwright-report/ - retention-days: 30 + - name: Configure Chrome Sandbox + run: | + sudo chown root node_modules/electron/dist/chrome-sandbox + sudo chmod 4755 node_modules/electron/dist/chrome-sandbox + + - name: Run playwright Tests + uses: ./.github/actions/tests/run-e2e-tests + with: + os: ubuntu + + - name: Upload Playwright Report + uses: actions/upload-artifact@v6 + if: ${{ !cancelled() }} + with: + name: playwright-report + path: playwright-report/ + retention-days: 30