e2e tests #165
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: e2e tests | |
| on: | |
| # Scheduled workflow | |
| # 13:00 UTC ~= 8:00 AM ET (EST) | |
| # 01:00 UTC ~= 8:00 PM ET (EST) | |
| schedule: | |
| - cron: '0 13 * * *' | |
| - cron: '0 1 * * *' | |
| # Manual trigger - Support workflow_dispatch for on-demand runs | |
| workflow_dispatch: | |
| inputs: | |
| test_realm: | |
| description: 'Test realm to use (optional, defaults to var)' | |
| required: false | |
| type: string | |
| sfcc_client_id: | |
| description: 'SFCC Client ID (optional, defaults to var)' | |
| required: false | |
| type: string | |
| sfcc_client_secret: | |
| description: 'SFCC Client Secret (optional, defaults to secret)' | |
| required: false | |
| type: string | |
| sfcc_account_manager_host: | |
| description: 'SFCC Account Manager Host (optional, defaults to var)' | |
| required: false | |
| type: string | |
| sfcc_sandbox_api_host: | |
| description: 'SFCC Sandbox API Host (optional, defaults to var)' | |
| required: false | |
| type: string | |
| env: | |
| SFCC_DISABLE_TELEMETRY: ${{ vars.SFCC_DISABLE_TELEMETRY }} | |
| jobs: | |
| e2e-tests: | |
| # E2E tests run only on the current LTS Node version for stability and speed. | |
| strategy: | |
| matrix: | |
| node-version: [22.x] | |
| runs-on: ubuntu-latest | |
| environment: e2e-dev | |
| timeout-minutes: 40 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ matrix.node-version }} | |
| - name: Check for required secrets and vars | |
| id: check-secrets | |
| env: | |
| SFCC_CLIENT_ID: ${{ vars.SFCC_CLIENT_ID }} | |
| SFCC_CLIENT_SECRET: ${{ secrets.SFCC_CLIENT_SECRET }} | |
| TEST_REALM: ${{ vars.TEST_REALM }} | |
| SFCC_ACCOUNT_MANAGER_HOST: ${{ vars.SFCC_ACCOUNT_MANAGER_HOST }} | |
| SFCC_SANDBOX_API_HOST: ${{ vars.SFCC_SANDBOX_API_HOST }} | |
| SFCC_SHORTCODE: ${{ vars.SFCC_SHORTCODE }} | |
| SFCC_EXTRA_HEADERS: ${{ secrets.SFCC_EXTRA_HEADERS }} | |
| run: | | |
| if [ -n "$SFCC_CLIENT_ID" ] && [ -n "$SFCC_CLIENT_SECRET" ] && [ -n "$TEST_REALM" ] && [ -n "$SFCC_ACCOUNT_MANAGER_HOST" ] && [ -n "$SFCC_SANDBOX_API_HOST" ] && [ -n "$SFCC_SHORTCODE" ]; then | |
| echo "has-secrets=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "has-secrets=false" >> $GITHUB_OUTPUT | |
| echo " E2E tests skipped - missing required variables:" >> $GITHUB_STEP_SUMMARY | |
| echo " - SFCC_CLIENT_ID (var): ${SFCC_CLIENT_ID:+✓}" >> $GITHUB_STEP_SUMMARY | |
| echo " - TEST_REALM (var): ${TEST_REALM:+✓}" >> $GITHUB_STEP_SUMMARY | |
| echo " - SFCC_ACCOUNT_MANAGER_HOST (var): ${SFCC_ACCOUNT_MANAGER_HOST:+✓}" >> $GITHUB_STEP_SUMMARY | |
| echo " - SFCC_SANDBOX_API_HOST (var): ${SFCC_SANDBOX_API_HOST:+✓}" >> $GITHUB_STEP_SUMMARY | |
| echo " - SFCC_SHORTCODE (var): ${SFCC_SHORTCODE:+✓}" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v4 | |
| with: | |
| version: 10.17.1 | |
| - name: Get pnpm store directory | |
| shell: bash | |
| run: | | |
| echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV | |
| - name: Setup pnpm cache | |
| uses: actions/cache@v4 | |
| with: | |
| path: ${{ env.STORE_PATH }} | |
| key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-pnpm-store- | |
| - name: Install dependencies | |
| if: steps.check-secrets.outputs.has-secrets == 'true' | |
| run: pnpm install --frozen-lockfile | |
| - name: Build package | |
| if: steps.check-secrets.outputs.has-secrets == 'true' | |
| run: pnpm -r run build | |
| - name: Run E2E Tests | |
| if: steps.check-secrets.outputs.has-secrets == 'true' | |
| id: e2e-test | |
| working-directory: packages/b2c-cli | |
| env: | |
| # Required environment variables | |
| SFCC_CLIENT_ID: ${{ inputs.sfcc_client_id || vars.SFCC_CLIENT_ID }} | |
| SFCC_CLIENT_SECRET: ${{ inputs.sfcc_client_secret || secrets.SFCC_CLIENT_SECRET }} | |
| SFCC_ACCOUNT_MANAGER_HOST: ${{ inputs.sfcc_account_manager_host || vars.SFCC_ACCOUNT_MANAGER_HOST }} | |
| SFCC_SANDBOX_API_HOST: ${{ inputs.sfcc_sandbox_api_host || vars.SFCC_SANDBOX_API_HOST }} | |
| TEST_REALM: ${{ inputs.test_realm || vars.TEST_REALM }} | |
| SFCC_SHORTCODE: ${{ vars.SFCC_SHORTCODE }} | |
| SFCC_EXTRA_HEADERS: ${{ secrets.SFCC_EXTRA_HEADERS }} | |
| # Test configuration | |
| NODE_ENV: test | |
| SFCC_LOG_LEVEL: silent | |
| run: | | |
| echo "Running E2E tests with realm: ${TEST_REALM}" | |
| echo "Node version: $(node --version)" | |
| # Run E2E tests with CI reporter (outputs test-results.json) | |
| pnpm run test:e2e:ci && pnpm run lint | |
| - name: E2E Test Report | |
| uses: dorny/test-reporter@fe45e9537387dac839af0d33ba56eed8e24189e8 # v2.3.0 | |
| if: always() && steps.e2e-test.conclusion != 'cancelled' && steps.check-secrets.outputs.has-secrets == 'true' | |
| with: | |
| name: E2E Test Results (Node ${{ matrix.node-version }}) | |
| path: 'packages/b2c-cli/test-results.json' | |
| reporter: mocha-json | |
| - name: Upload E2E Test Results | |
| if: always() && steps.e2e-test.conclusion != 'cancelled' && steps.check-secrets.outputs.has-secrets == 'true' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: e2e-test-results-node-${{ matrix.node-version }}-${{ github.run_number }} | |
| path: packages/b2c-cli/test-results.json | |
| retention-days: 30 | |
| - name: Notify on Failure | |
| if: failure() && github.event_name == 'schedule' && steps.check-secrets.outputs.has-secrets == 'true' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const issue = { | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| title: `CLI E2E Tests Failed - ${new Date().toISOString().split('T')[0]}`, | |
| body: `## CLI E2E Test Failure | |
| The CLI E2E tests have failed. Please investigate. | |
| **Workflow:** ${context.workflow} | |
| **Run:** ${context.runNumber} | |
| **Commit:** ${context.sha} | |
| **Event:** ${context.eventName} | |
| **Node Version:** ${{ matrix.node-version }} | |
| [View workflow run](${context.payload.repository.html_url}/actions/runs/${context.runId}) | |
| `, | |
| labels: ['bug', 'e2e-failure', 'cli', 'needs-investigation'] | |
| }; | |
| // Only create issue for scheduled runs to avoid spam | |
| if (context.eventName === 'schedule') { | |
| github.rest.issues.create(issue); | |
| } |