added depends on workflow #24
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: End-to-End Testing | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
jobs: | |
cypress-tests: | |
if: ${{ github.event.workflow_run.conclusion == 'success' }} # Check that the previous workflow was successful | |
runs-on: ubuntu-latest | |
steps: | |
# Step 1: Checkout the code | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
# Step 2: Set up Node.js | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 18 | |
# Step 1: Log in to Docker Hub | |
- name: Log in to Docker Hub | |
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin | |
# Step : Connect containers | |
- name: Create container network | |
run: | | |
docker network create docker_network_crowdfund | |
# Step 3: Pull and Run Database Docker Image | |
- name: Run MySQL database service | |
run: | | |
docker pull ${{ secrets.DOCKER_USERNAME }}/raisehub_database:latest | |
docker run -d --name raisehub_database \ | |
-p 3306:3306 \ | |
--env MYSQL_ROOT_PASSWORD=${{ secrets.MYSQL_ROOT_PASSWORD }} \ | |
--env MYSQL_DATABASE=crowdfund_db \ | |
${{ secrets.DOCKER_USERNAME }}/raisehub_database:latest | |
docker network connect docker_network_crowdfund raisehub_database | |
# Step 3.1: Wait for MySQL to Start and Verify Service | |
- name: Wait for MySQL Service to Start | |
run: | | |
for i in {1..10}; do | |
docker exec raisehub_database mysqladmin ping -h 127.0.0.1 -u root -p${{ secrets.MYSQL_ROOT_PASSWORD }} && break | |
echo "Waiting for MySQL to be ready..." | |
sleep 5 | |
done || (echo "MySQL failed to start" && exit 1) | |
- name: Debug MySQL Logs | |
if: failure() | |
run: | | |
docker logs raisehub_database | |
# Step 4: Pull and Run Backend Docker Image | |
- name: Run backend service | |
run: | | |
docker pull ${{ secrets.DOCKER_USERNAME }}/raisehub_backend:latest | |
docker run -d --name backend \ | |
-p 8080:8080 \ | |
--env MYSQL_USERNAME=${{ secrets.MYSQL_USERNAME }} \ | |
--env MYSQL_PASSWORD=${{ secrets.MYSQL_PASSWORD }} \ | |
--env JWT_SECRET=${{ secrets.JWT_SECRET }} \ | |
${{ secrets.DOCKER_USERNAME }}/raisehub_backend:latest | |
docker network connect docker_network_crowdfund backend | |
# Step 4.1: Wait for Backend to Start and Verify Service | |
- name: Wait for Backend Service to Start | |
run: | | |
for i in {1..10}; do | |
curl -sSf http://localhost:8080/health && break | |
echo "Waiting for Backend to be ready..." | |
sleep 5 | |
done || (echo "Backend failed to start" && exit 1) | |
docker logs -f backend | |
# Step 5: Build and Serve the Frontend (If using Docker container for frontend) | |
- name: Build and Serve Frontend | |
run: | | |
npm install | |
npm run build | |
npm run start & # This will start the frontend in the background | |
env: | |
REACT_APP_API_URL: http://localhost:8080 # Set backend API URL | |
# Step 6: Wait for Frontend Service to Start | |
- name: Wait for Frontend Service | |
run: | | |
npx wait-on http://localhost:3000 | |
# Step 7: Run Cypress Tests | |
- name: Run Cypress tests | |
uses: cypress-io/github-action@v5 | |
with: | |
browser: chrome | |
config-file: cypress.config.js | |
env: | |
CYPRESS_baseUrl: http://localhost:3000 # Point to the frontend |