-
Notifications
You must be signed in to change notification settings - Fork 7
160 lines (142 loc) · 5.73 KB
/
aps-cypress-e2e.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
name: Cypress and Execute Tests
on:
workflow_dispatch: {}
push:
branches: ['test', 'cypress/*']
pull_request:
branches: ['dev']
env:
DASHBOARD_PROJECT_ID: ${{ secrets.CY_DASHBOARD_PRJ_ID }}
DASHBOARD_RECORD_KEY: ${{ secrets.CY_DASHBOARD_RECORD_KEY }}
EXECUTION_ENV: prod
GIT_COMMIT_BRANCH: ${{ github.ref_name }}
GIT_COMMIT_SHA: ${{ github.sha }}
GIT_COMMIT_AUTHOR: ${{ github.actor }}
GIT_COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
GIT_REPO_URL: ${{ github.repository }}
jobs:
cypress-run:
runs-on: ubuntu-latest
steps:
- name: Build GWA API Image
run: |
git clone https://github.com/bcgov/gwa-api.git --branch v1.0.40
cd gwa-api/microservices/gatewayApi
docker build -t gwa-api:e2e .
- name: Checkout Portal
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build Docker Images
run: |
docker compose --profile testsuite build
- name: Spin up API Services Portal and Run E2E Tests
run: |
export CY_EXECUTION_ENV=${{ env.EXECUTION_ENV }}
export CY_RECORD_KEY=${{ env.DASHBOARD_RECORD_KEY }}
export CY_PROJECT_ID=${{ env.DASHBOARD_PROJECT_ID }}
export CY_COMMIT_BRANCH=${{ env.GIT_COMMIT_BRANCH }}
export CY_COMMIT_SHA=${{ env.GIT_COMMIT_SHA }}
export CY_COMMIT_AUTHOR=${{ env.GIT_COMMIT_AUTHOR }}
export CY_COMMIT_MESSAGE="${{ env.GIT_COMMIT_MESSAGE }}"
export CY_REPO_URL=${{ env.GIT_REPO_URL }}
export CY_COMMIT_AUTHOR_EMAIL=$(git --no-pager show -s --format='%ae' ${{ env.GIT_COMMIT_SHA }})
docker compose --profile testsuite up -d
- name: Execute Tests & Clean Up
run: |
# Start following logs in the background with continuous output
docker logs -f cypress-e2e 2>&1 &
LOG_PID=$!
while true; do
if [ "$(docker ps -aq -f status=exited -f name=cypress-e2e)" ]; then
echo "Cypress tests completed."
# cleanup
docker compose down
break
else
sleep 30s
fi
done
- name: Upload E2E Test Results HTML Report
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results-html
path: ${{ github.workspace }}/e2e/results/report
- name: Upload E2E Test Results JSON Report
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results-json
path: ${{ github.workspace }}/e2e/results/bcgov-aps-e2e-report.json
- name: Upload E2E Code Coverage Report
if: always()
uses: actions/upload-artifact@v4
with:
name: code-coverage
path: ${{ github.workspace }}/e2e/coverage
- name: Instrument the code for coverage analysis
if: always()
run: |
# Rewrite the paths as the coverage starts with '../app'!
sed -e 's/..\/app/./g' ${{ github.workspace }}/e2e/coverage/lcov.info > lcov.info
- name: SonarCloud Scan
if: always()
uses: sonarsource/[email protected]
with:
args: >
-Dsonar.organization=bcgov-oss
-Dsonar.projectKey=aps-portal-e2e
-Dsonar.host.url=https://sonarcloud.io
-Dsonar.projectBaseDir=src
-Dsonar.sources=.
-Dsonar.exclusions=nextapp/**,mocks/**,test/**,tools/**,*.json,*.js
-Dsonar.javascript.lcov.reportPaths=/github/workspace/lcov.info
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- name: Upload Astra scan results
uses: actions/upload-artifact@v4
with:
name: astra-scan-results
path: ${{ github.workspace }}/e2e/cypress/fixtures/state/scanResult.json
- name: Check for failed tests and create Issue
if: always()
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
FAILURE_COUNT=$(cat ${{ github.workspace }}/e2e/results/bcgov-aps-e2e-report.json | jq '.stats.failures')
if [[ "$FAILURE_COUNT" -gt 0 ]]; then
FAILED_TESTS=$(jq -r '
.results[] |
(.file | split("/") | .[2:] | join("/")) as $file |
.. |
.tests? // empty |
.[] |
select(.fail == true) |
"- " + $file + " - " + .title
' ${{ github.workspace }}/e2e/results/bcgov-aps-e2e-report.json)
STATS=$(cat ${{ github.workspace }}/e2e/results/bcgov-aps-e2e-report.json | jq -r '.stats | to_entries | map("\(.key)\t\(.value)") | .[]' | column -t)
echo -e "Stats: $STATS\n\nFailed Tests:\n$FAILED_TESTS\n\nRun Link: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" > msg
export MSG=$(cat msg)
gh issue create --title "FAILED: Automated Tests($FAILURE_COUNT)" --body "$MSG" --label "automation" --assignee "${{ env.GIT_COMMIT_AUTHOR }}"
exit 1
fi
- name: Set up Python 3.9
if: failure()
uses: actions/setup-python@v2
with:
python-version: '3.9'
architecture: 'x64'
- name: Install Python dependencies
if: failure()
run: |
python -m pip install --upgrade pip
pip install requests
- name: Check Astra results and create Jira issue if necessary
if: failure()
run: python .github/astra-jira.py
env:
JIRA_EMAIL: ${{ secrets.JIRA_EMAIL }}
JIRA_API_KEY: ${{ secrets.JIRA_API_KEY }}
ASTRA_SCAN_RESULTS: ${{ github.workspace }}/e2e/cypress/fixtures/state/scanResult.json