-
Notifications
You must be signed in to change notification settings - Fork 3
170 lines (149 loc) · 5.97 KB
/
cypress.yml
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
161
162
163
164
165
166
167
168
169
170
---
name: cypress_tests
on:
push: # This will trigger the workflow for any commit to any branch
pull_request:
types: [ opened, closed ]
branches:
- main
schedule:
- cron: "0 8 * * *" # Run every day at 8am UTC
workflow_dispatch:
env:
DOCKER_REGISTRY: ghcr.io
jobs:
build-docker:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: recursive
- name: Set Branch Name to Lowercase
run: |
echo GITHUB_REF_LC=$(echo ${{ github.ref_name }} | tr '[:upper:]' '[:lower:]') >> $GITHUB_ENV
- name: Docker login
# e92390c5fb421da1463c202d546fed0ec5c39f20 == v3.1.0
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20
with:
registry: ${{ env.DOCKER_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build docker image
# 2b51285047da1547ffb1b2203d8be4c0af6b1f20 == v3.2.0
uses: docker/setup-buildx-action@2b51285047da1547ffb1b2203d8be4c0af6b1f20
- name: Build and push Docker image
# 2cdde995de11925a030ce8070c3d77a52ffcf1c0 == v5.3.0
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0
env:
DOCKER_IMAGE_NAME: "${{ github.event.repository.name }}-${{ env.GITHUB_REF_LC }}"
DOCKER_IMAGE_VERSION: latest
with:
context: .
file: "Dockerfile.tests"
tags: "${{ env.DOCKER_REGISTRY }}/m0-foundation/${{ env.DOCKER_IMAGE_NAME }}:${{ env.DOCKER_IMAGE_VERSION }}"
load: true
cache-from: type=gha
cache-to: type=gha,mode=max
push: true
cypress:
timeout-minutes: 30
runs-on: ubuntu-latest
needs: build-docker
strategy:
fail-fast: false
matrix:
test_runs: [
"basic",
"basic-standard",
"basic-emergency",
"basic-zero",
# "standardProposals",
# "emergencyProposals",
# "zeroProposals"
]
steps:
- name: Set Branch Name to Lowercase
run: |
echo GITHUB_REF_LC=$(echo ${{ github.ref_name }} | tr '[:upper:]' '[:lower:]') >> $GITHUB_ENV
- name: Docker login
# e92390c5fb421da1463c202d546fed0ec5c39f20 == v3.1.0
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20
with:
registry: ${{ env.DOCKER_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Pull docker image to local runner
env:
DOCKER_IMAGE_NAME: "${{ github.event.repository.name }}-${{ env.GITHUB_REF_LC }}"
DOCKER_IMAGE_VERSION: latest
run: "docker pull ${{ env.DOCKER_REGISTRY }}/m0-foundation/${{ env.DOCKER_IMAGE_NAME }}:${{ env.DOCKER_IMAGE_VERSION }}"
- name: Run Cypress tests
# 4f65fabd2431ebc8d299f8e5a018d79a769ae185 == v3.0.0
uses: addnab/docker-run-action@4f65fabd2431ebc8d299f8e5a018d79a769ae185
env:
DOCKER_IMAGE_NAME: "${{ github.event.repository.name }}-${{ env.GITHUB_REF_LC }}"
DOCKER_IMAGE_VERSION: latest
with:
image: "${{ env.DOCKER_REGISTRY }}/m0-foundation/${{ env.DOCKER_IMAGE_NAME }}:${{ env.DOCKER_IMAGE_VERSION }}"
options: --env TEST_RUN=${{ matrix.test_runs }}
shell: bash
# run: "/app/entrypoint.sh"
run: |
# Define the log file
LOG_FILE=job_output.txt
# Start the main job in the background and redirect its output to the log file
/app/entrypoint.sh > $LOG_FILE 2>&1 &
MAIN_JOB_PID=$!
# Monitor the log file in real-time and display logs
(tail -f $LOG_FILE &)
# Function to monitor the log file for specific text and terminate the main job if found
monitor_log() {
while IFS= read -r LINE; do
echo "$LINE"
if [[ "$LINE" == *"Error: read ECONNRESET"* ]]; then
echo "Found 'Error: read ECONNRESET' in log, terminating the job."
if ps -p $MAIN_JOB_PID > /dev/null; then
kill $MAIN_JOB_PID
else
echo "Main job process $MAIN_JOB_PID already terminated."
fi
exit 255
fi
done < $LOG_FILE
}
# Run the log monitor function in the background
monitor_log &
MONITOR_PID=$!
# Wait for the main job to finish and capture its exit code
wait $MAIN_JOB_PID
MAIN_JOB_EXIT_CODE=$?
# Terminate the log monitor process
if ps -p $MONITOR_PID > /dev/null; then
kill $MONITOR_PID
else
echo "Main job process $MONITOR_PID already terminated."
fi
echo "************************************************************"
echo "***** Repeat the full log file *****"
echo "************************************************************"
echo ""
cat $LOG_FILE
# Display the main job's exit code
echo "Main job finished with exit code $MAIN_JOB_EXIT_CODE."
if [ $MAIN_JOB_EXIT_CODE -eq 255 ]; then
echo "Found ECONNRESET and exited error code $MAIN_JOB_EXIT_CODE."
fi
# Exit with the main job's exit code
exit $MAIN_JOB_EXIT_CODE
- name: Upload Cypress Test Reports
# 0b2256b8c012f0828dc542b3febcab082c67f72b == v4.3.4
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b
if: always() # This ensures artifacts are uploaded even if the job fails
with:
name: cypress-reports
path: |
cypress/screenshots/**