Skip to content

Commit a648d3d

Browse files
committed
testing the e2e temp workflow
1 parent 4f641e0 commit a648d3d

1 file changed

Lines changed: 187 additions & 0 deletions

File tree

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

0 commit comments

Comments
 (0)