Skip to content

cypress_tests

cypress_tests #563

Workflow file for this run

---
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/**