|
| 1 | +name: e2e tests |
| 2 | + |
| 3 | +on: |
| 4 | + # Nightly workflow - Run E2E tests on a schedule |
| 5 | + schedule: |
| 6 | + - cron: '0 2 * * *' # Run at 2 AM UTC daily |
| 7 | + # Post-merge - Run after changes are merged to main |
| 8 | + push: |
| 9 | + branches: [main] |
| 10 | + # Manual trigger - Support workflow_dispatch for on-demand runs |
| 11 | + workflow_dispatch: |
| 12 | + inputs: |
| 13 | + test_realm: |
| 14 | + description: 'Test realm to use (optional, defaults to var)' |
| 15 | + required: false |
| 16 | + type: string |
| 17 | + sfcc_client_id: |
| 18 | + description: 'SFCC Client ID (optional, defaults to var)' |
| 19 | + required: false |
| 20 | + type: string |
| 21 | + sfcc_client_secret: |
| 22 | + description: 'SFCC Client Secret (optional, defaults to secret)' |
| 23 | + required: false |
| 24 | + type: string |
| 25 | + sfcc_account_manager_host: |
| 26 | + description: 'SFCC Account Manager Host (optional, defaults to var)' |
| 27 | + required: false |
| 28 | + type: string |
| 29 | + sfcc_sandbox_api_host: |
| 30 | + description: 'SFCC Sandbox API Host (optional, defaults to var)' |
| 31 | + required: false |
| 32 | + type: string |
| 33 | + node_version: |
| 34 | + description: 'Node.js version to test with' |
| 35 | + required: false |
| 36 | + default: 'lts/*' |
| 37 | + type: choice |
| 38 | + options: |
| 39 | + - 'lts/-1' |
| 40 | + - 'lts/*' |
| 41 | + - 'latest' |
| 42 | + os: |
| 43 | + description: 'Operating system to test on' |
| 44 | + required: false |
| 45 | + default: 'ubuntu-latest' |
| 46 | + type: choice |
| 47 | + options: |
| 48 | + - 'ubuntu-latest' |
| 49 | + - 'windows-latest' |
| 50 | +jobs: |
| 51 | + e2e-tests: |
| 52 | + strategy: |
| 53 | + matrix: |
| 54 | + node_version: [22.x, 24.x] |
| 55 | + runs-on: ubuntu-latest |
| 56 | + environment: e2e-dev |
| 57 | + timeout-minutes: 10 # E2E tests can take longer |
| 58 | + steps: |
| 59 | + - uses: actions/checkout@v4 |
| 60 | + - uses: actions/setup-node@v4 |
| 61 | + with: |
| 62 | + node-version: ${{ matrix.node-version }} |
| 63 | + cache: pnpm |
| 64 | + - name: Check for required secrets and vars |
| 65 | + id: check-secrets |
| 66 | + env: |
| 67 | + SFCC_CLIENT_ID: ${{ vars.SFCC_CLIENT_ID }} |
| 68 | + SFCC_CLIENT_SECRET: ${{ secrets.SFCC_CLIENT_SECRET }} |
| 69 | + TEST_REALM: ${{ vars.TEST_REALM }} |
| 70 | + SFCC_ACCOUNT_MANAGER_HOST: ${{ vars.SFCC_ACCOUNT_MANAGER_HOST }} |
| 71 | + SFCC_SANDBOX_API_HOST: ${{ vars.SFCC_SANDBOX_API_HOST }} |
| 72 | + run: | |
| 73 | + if [ -n "$SFCC_CLIENT_ID" ] && [ -n "$SFCC_CLIENT_SECRET" ] && [ -n "$TEST_REALM" ] && [ -n "SFCC_ACCOUNT_MANAGER_HOST" ] && [ -n "SFCC_SANDBOX_API_HOST" ]; then |
| 74 | + echo "has-secrets=true" >> $GITHUB_OUTPUT |
| 75 | + else |
| 76 | + echo "has-secrets=false" >> $GITHUB_OUTPUT |
| 77 | + echo "E2E tests skipped - missing required variables:" >> $GITHUB_STEP_SUMMARY |
| 78 | + echo " - SFCC_CLIENT_ID (var): ${SFCC_CLIENT_ID:+✓}" >> $GITHUB_STEP_SUMMARY |
| 79 | + echo " - TEST_REALM (var): ${TEST_REALM:+✓}" >> $GITHUB_STEP_SUMMARY |
| 80 | + echo " - SFCC_ACCOUNT_MANAGER_HOST (var): ${SFCC_ACCOUNT_MANAGER_HOST:+✓}" >> $GITHUB_STEP_SUMMARY |
| 81 | + echo " - SFCC_SANDBOX_API_HOST (var): ${SFCC_SANDBOX_API_HOST:+✓}" >> $GITHUB_STEP_SUMMARY |
| 82 | + fi |
| 83 | + - name: Install dependencies |
| 84 | + if: steps.check-secrets.outputs.has-secrets == 'true' |
| 85 | + run: pnpm install |
| 86 | + - name: Build package |
| 87 | + if: steps.check-secrets.outputs.has-secrets == 'true' |
| 88 | + run: pnpm run build |
| 89 | + - name: Run E2E Tests |
| 90 | + if: steps.check-secrets.outputs.has-secrets == 'true' |
| 91 | + id: e2e-test |
| 92 | + env: |
| 93 | + # Required environment variables for Commerce Cloud integration |
| 94 | + SFCC_CLIENT_ID: ${{ inputs.sfcc_client_id || vars.SFCC_CLIENT_ID }} |
| 95 | + SFCC_CLIENT_SECRET: ${{ inputs.sfcc_client_secret || secrets.SFCC_CLIENT_SECRET }} |
| 96 | + SFCC_ACCOUNT_MANAGER_HOST: ${{ inputs.sfcc_account_manager_host || vars.SFCC_ACCOUNT_MANAGER_HOST }} |
| 97 | + SFCC_SANDBOX_API_HOST: ${{ inputs.sfcc_sandbox_api_host || vars.SFCC_SANDBOX_API_HOST }} |
| 98 | + TEST_REALM: ${{ inputs.test_realm || vars.TEST_REALM }} |
| 99 | + # Test configuration |
| 100 | + NODE_ENV: test |
| 101 | + SFCC_LOG_LEVEL: silent |
| 102 | + run: | |
| 103 | + echo "Running E2E tests with realm: ${TEST_REALM}" |
| 104 | + |
| 105 | + # Run E2E tests with JSON output for parsing |
| 106 | + pnpm mocha "test/functional/e2e/**/*.test.ts" --reporter json > e2e-results.json || true |
| 107 | + |
| 108 | + # Also run with spec reporter for readable output |
| 109 | + echo "## E2E Test Results" >> $GITHUB_STEP_SUMMARY |
| 110 | + pnpm mocha "test/functional/e2e/**/*.test.ts" --reporter spec |
| 111 | + - name: Parse E2E Results |
| 112 | + if: always() && steps.e2e-test.conclusion != 'cancelled' && steps.check-secrets.outputs.has-secrets == 'true' |
| 113 | + run: | |
| 114 | + if [ -f "e2e-results.json" ]; then |
| 115 | + # Extract test summary from JSON results |
| 116 | + TESTS=$(cat e2e-results.json | jq -r '.stats.tests // 0') |
| 117 | + PASSES=$(cat e2e-results.json | jq -r '.stats.passes // 0') |
| 118 | + FAILURES=$(cat e2e-results.json | jq -r '.stats.failures // 0') |
| 119 | + DURATION=$(cat e2e-results.json | jq -r '.stats.duration // 0') |
| 120 | + |
| 121 | + echo "## E2E Test Summary" >> $GITHUB_STEP_SUMMARY |
| 122 | + echo "- **Total Tests:** $TESTS" >> $GITHUB_STEP_SUMMARY |
| 123 | + echo "- **Passed:** $PASSES" >> $GITHUB_STEP_SUMMARY |
| 124 | + echo "- **Failed:** $FAILURES" >> $GITHUB_STEP_SUMMARY |
| 125 | + echo "- **Duration:** ${DURATION}ms" >> $GITHUB_STEP_SUMMARY |
| 126 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 127 | + |
| 128 | + # Add failure details if any |
| 129 | + if [ "$FAILURES" -gt "0" ]; then |
| 130 | + echo "### Failed Tests" >> $GITHUB_STEP_SUMMARY |
| 131 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 132 | + cat e2e-results.json | jq -r '.failures[]? | "[X] " + .fullTitle + "\n " + .err.message' >> $GITHUB_STEP_SUMMARY |
| 133 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 134 | + fi |
| 135 | + fi |
| 136 | + - name: Upload E2E Test Results |
| 137 | + if: always() && steps.e2e-test.conclusion != 'cancelled' && steps.check-secrets.outputs.has-secrets == 'true' |
| 138 | + uses: actions/upload-artifact@v4 |
| 139 | + with: |
| 140 | + name: e2e-test-results-${{ matrix.os }}-node${{ matrix.node_version }}-${{ github.run_number }} |
| 141 | + path: e2e-results.json |
| 142 | + retention-days: 30 |
| 143 | + - name: Notify on Failure |
| 144 | + if: failure() && (github.event_name == 'schedule' || github.event_name == 'push') && steps.check-secrets.outputs.has-secrets == 'true' |
| 145 | + uses: actions/github-script@v7 |
| 146 | + with: |
| 147 | + script: | |
| 148 | + const issue = { |
| 149 | + owner: context.repo.owner, |
| 150 | + repo: context.repo.repo, |
| 151 | + title: `CLI E2E Tests Failed - ${new Date().toISOString().split('T')[0]}`, |
| 152 | + body: `## CLI E2E Test Failure |
| 153 | + |
| 154 | + The CLI E2E tests have failed. Please investigate. |
| 155 | + |
| 156 | + **Workflow:** ${context.workflow} |
| 157 | + **Run:** ${context.runNumber} |
| 158 | + **Commit:** ${context.sha} |
| 159 | + **Event:** ${context.eventName} |
| 160 | + |
| 161 | + [View workflow run](${context.payload.repository.html_url}/actions/runs/${context.runId}) |
| 162 | + `, |
| 163 | + labels: ['bug', 'e2e-failure', 'cli', 'needs-investigation'] |
| 164 | + }; |
| 165 | + |
| 166 | + // Only create issue for scheduled runs to avoid spam |
| 167 | + if (context.eventName === 'schedule') { |
| 168 | + github.rest.issues.create(issue); |
| 169 | + } |
0 commit comments