Brak opisu

quick-testing.yml 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. name: Docker Compose Up and Ping
  2. on:
  3. workflow_run:
  4. workflows: ["dockerbuild"]
  5. types:
  6. - completed
  7. workflow_dispatch:
  8. jobs:
  9. build:
  10. runs-on: ${{ matrix.os }}
  11. strategy:
  12. matrix:
  13. os: [ubuntu-latest]
  14. architecture: [x64, arm64]
  15. steps:
  16. - name: Checkout code
  17. uses: actions/checkout@v2
  18. - name: Shai-Hulud 2.0 Detector
  19. uses: gensecaihq/Shai-Hulud-2.0-Detector@v1.0.0
  20. - name: Install Docker Compose
  21. run: |
  22. sudo apt-get update
  23. sudo apt-get install -y docker-compose
  24. docker-compose --version
  25. - name: Set up opensearch directory
  26. run: chmod -R 777 shuffle-database
  27. - name: Build the stack
  28. run: docker compose up -d
  29. - name: Wait for 30 seconds
  30. run: sleep 30
  31. - name: Check for restarting containers in a loop and fixing perms again
  32. run: |
  33. # echo "Changing permissions on shuffle-database directory again"
  34. # chmod -R 777 shuffle-database
  35. ATTEMPTS=30 # Total time = ATTEMPTS * 5 seconds = 30 seconds
  36. for i in $(seq 1 $ATTEMPTS); do
  37. RESTARTING_CONTAINERS=$(docker ps --filter "status=restarting" --format "{{.Names}}")
  38. if [ -n "$RESTARTING_CONTAINERS" ]; then
  39. echo "The following containers are restarting:"
  40. echo "$RESTARTING_CONTAINERS"
  41. exit 1
  42. fi
  43. echo "No containers are restarting. Attempt $i/$ATTEMPTS."
  44. sleep 1
  45. done
  46. echo "No containers were found in a restarting state after $ATTEMPTS checks."
  47. - name: Check if the response from the frontend contains the word "Shuffle"
  48. run: |
  49. RESPONSE=$(curl -s http://localhost:3001)
  50. if echo "$RESPONSE" | grep -q "Shuffle"; then
  51. echo "The word 'Shuffle' was found in the response."
  52. else
  53. echo "The word 'Shuffle' was not found in the response."
  54. exit 1
  55. fi
  56. - name: Register a user and check the status code
  57. run: |
  58. MAX_RETRIES=30
  59. RETRY_INTERVAL=10
  60. CONTAINER_NAME="shuffle-backend"
  61. for (( i=1; i<=$MAX_RETRIES; i++ ))
  62. do
  63. STATUS_CODE=$(curl -s -o /dev/null -w "%{http_code}" 'http://localhost:3001/api/v1/register' \
  64. -H 'Accept: */*' \
  65. -H 'Accept-Language: en-US,en;q=0.9' \
  66. -H 'Connection: keep-alive' \
  67. -H 'Content-Type: application/json' \
  68. --data-raw '{"username":"demo@demo.io","password":"supercoolpassword"}')
  69. if [ "$STATUS_CODE" -eq 200 ]; then
  70. echo "User registration was successful with status code 200."
  71. exit 0
  72. elif [ "$STATUS_CODE" -ne 502 ]; then
  73. echo "User registration failed with status code $STATUS_CODE."
  74. exit 1
  75. fi
  76. echo "Received status code $STATUS_CODE. Retrying in $RETRY_INTERVAL seconds... ($i/$MAX_RETRIES)"
  77. echo "Fetching last 30 lines of logs from container $CONTAINER_NAME..."
  78. logs_output=$(docker logs --tail 30 "$CONTAINER_NAME")
  79. echo "$logs_output"
  80. echo "Fetching last 30 lines of logs from container shuffle-opensearch..."
  81. opensearch_logs=$(docker logs --tail 30 shuffle-opensearch)
  82. echo "$opensearch_logs"
  83. sleep $RETRY_INTERVAL
  84. done
  85. echo "User registration failed after $MAX_RETRIES attempts."
  86. exit 1
  87. - name: Run Selenium testing for frontend
  88. run: |
  89. cd $GITHUB_WORKSPACE/frontend
  90. # write some log to see the current directory
  91. chmod +x frontend-testing.sh
  92. ./frontend-testing.sh
  93. - name: Get the API key and run a health check
  94. id: health_check
  95. run: |
  96. RESPONSE=$(curl -s -k -u admin:StrongShufflePassword321! 'https://localhost:9200/users/_search')
  97. echo "Raw Response: $RESPONSE"
  98. API_KEY=$(echo "$RESPONSE" | jq -r '.hits.hits[0]._source.apikey')
  99. if [ -n "$API_KEY" ] && [ "$API_KEY" != "null" ]; then
  100. echo "Admin API key: $API_KEY"
  101. echo "API_KEY=$API_KEY" >> $GITHUB_ENV
  102. else
  103. echo "Failed to retrieve the API key for the admin user."
  104. exit 1
  105. fi
  106. echo "Waiting 1 minute before sending the health API request..."
  107. sleep 60
  108. echo "Checking health API..."
  109. HEALTH_RESPONSE=$(curl -s 'http://localhost:3001/api/v1/health?force=true' \
  110. -H "Authorization: Bearer $API_KEY")
  111. echo "Health API Response: $HEALTH_RESPONSE"
  112. WORKFLOWS_CREATE=$(echo "$HEALTH_RESPONSE" | jq -r '.workflows.create')
  113. WORKFLOWS_RUN=$(echo "$HEALTH_RESPONSE" | jq -r '.workflows.run')
  114. WORKFLOWS_RUN_FINISHED=$(echo "$HEALTH_RESPONSE" | jq -r '.workflows.run_finished')
  115. WORKFLOWS_RUN_STATUS=$(echo "$HEALTH_RESPONSE" | jq -r '.workflows.run_status')
  116. WORKFLOWS_DELETE=$(echo "$HEALTH_RESPONSE" | jq -r '.workflows.delete')
  117. echo "WORKFLOWS_CREATE: $WORKFLOWS_CREATE"
  118. echo "WORKFLOWS_RUN: $WORKFLOWS_RUN"
  119. echo "WORKFLOWS_RUN_FINISHED: $WORKFLOWS_RUN_FINISHED"
  120. echo "WORKFLOWS_RUN_STATUS: $WORKFLOWS_RUN_STATUS"
  121. echo "WORKFLOWS_DELETE: $WORKFLOWS_DELETE"
  122. if [ "$WORKFLOWS_CREATE" = "true" ] && [ "$WORKFLOWS_RUN" = "true" ] && [ "$WORKFLOWS_RUN_FINISHED" = "true" ] && [ "$WORKFLOWS_RUN_STATUS" = "FINISHED" ] && [ "$WORKFLOWS_DELETE" = "true" ]; then
  123. echo "Health endpoint check was successful."
  124. exit 0
  125. else
  126. echo "Health check failed."
  127. exit 1
  128. fi
  129. notify:
  130. needs: build
  131. if: failure()
  132. runs-on: ubuntu-latest
  133. steps:
  134. - name: Send Twilio Alert
  135. run: |
  136. WORKFLOW_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
  137. MESSAGE="🚨 Shuffle Workflow Failed!
  138. Repository: ${{ github.repository }}
  139. Branch: ${{ github.ref_name }}
  140. Workflow URL: $WORKFLOW_URL"
  141. curl -s -X POST https://api.twilio.com/2010-04-01/Accounts/${{ secrets.TWILIO_ACCOUNT_SID }}/Messages.json \
  142. --data-urlencode "To=${{ secrets.TWILIO_TO_NUMBER }}" \
  143. --data-urlencode "From=${{ secrets.TWILIO_FROM_NUMBER }}" \
  144. --data-urlencode "Body=$MESSAGE" \
  145. -u "${{ secrets.TWILIO_ACCOUNT_SID }}:${{ secrets.TWILIO_AUTH_TOKEN }}" > /dev/null