wekan/.github/workflows/e2e-testing.yml
omri zaher 2556cd6e8c test
2025-09-19 17:10:13 +03:00

169 lines
5.9 KiB
YAML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

name: Deploy testing environment to EC2
on:
pull_request:
branches:
- main
workflow_dispatch:
jobs:
deploy:
runs-on: ubuntu-latest
outputs:
wekan_image_tag: ${{ steps.docker_image_build.outputs.tag }}
steps:
- name: Checkout repository(omriza5/wekan)
uses: actions/checkout@v4
- name: Build and push docker image
id: docker_image_build
run: |
# Login to DockerHub
echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
# Use short commit SHA (first 7 characters)
SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
TAG="${SHORT_SHA}-$(date +%Y%m%d-%H%M%S)"
echo "tag=$TAG" >> $GITHUB_OUTPUT
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/wekan:$TAG .
docker push ${{ secrets.DOCKERHUB_USERNAME }}/wekan:$TAG
# Save the tag for later steps
echo "WEKAN_IMAGE_TAG=$TAG" >> $GITHUB_ENV
- name: Create .env file
run: |
echo "WEKAN_IMAGE=omriza5/wekan:${WEKAN_IMAGE_TAG}" >> .env
- name: Copy .env file to EC2
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.WEKAN_EC2_HOST_IP }}
username: ubuntu
key: ${{ secrets.EC2_SSH_KEY }}
source: ".env"
target: "/home/ubuntu/"
- name: Copy docker-compose file to EC2
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.WEKAN_EC2_HOST_IP }}
username: ubuntu
key: ${{ secrets.EC2_SSH_KEY }}
source: "docker-compose.yml"
target: "/home/ubuntu/"
- name: Deploy to EC2
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.WEKAN_EC2_HOST_IP }}
username: ubuntu
key: ${{ secrets.EC2_SSH_KEY }}
script: |
# Stop and remove containers with volumes
sudo docker compose down -v || true
# Clean up everything including named volumes
sudo docker volume rm $(sudo docker volume ls -q) 2>/dev/null || true
sudo docker stop $(sudo docker ps -aq) 2>/dev/null || true
sudo docker rm $(sudo docker ps -aq) 2>/dev/null || true
# Remove all images to free space
sudo docker rmi $(sudo docker images -q) 2>/dev/null || true
# Clean up networks (volumes already removed above)
sudo docker network prune -f || true
echo "${{ secrets.DOCKERHUB_PASSWORD }}" | docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin
sudo docker compose pull
sudo docker compose up -d
- name: Create test user via Wekan API
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.WEKAN_EC2_HOST_IP }}
username: ubuntu
key: ${{ secrets.EC2_SSH_KEY }}
script: |
# Wait for Wekan to be ready with proper health check
echo "Waiting for Wekan to be ready..."
for i in {1..24}; do
if curl -s http://localhost > /dev/null 2>&1; then
echo "✅ Wekan is responding!"
break
fi
echo "⏳ Waiting for Wekan... (attempt $i/24)"
sleep 5
done
# Enable registration in database (Wekan disables it by default)
echo "🔧 Enabling user registration..."
sudo docker exec wekan-db mongosh wekan --eval 'db.settings.update({},{$set: {"disableRegistration":false}}, {upsert: true})' || echo "Failed to enable registration"
# Wait for setting to take effect
sleep 3
# Create test user using correct form-encoded format (as per API docs)
echo "👤 Creating test user..."
RESPONSE=$(curl -s -w "HTTPSTATUS:%{http_code}" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: */*" \
-X POST \
http://localhost/users/register \
-d "username=omriza5&password=123456&email=omriza5@gmail.com")
# Parse response
HTTP_CODE=$(echo $RESPONSE | tr -d '\n' | sed -e 's/.*HTTPSTATUS://')
BODY=$(echo $RESPONSE | sed -e 's/HTTPSTATUS:.*//g')
# Check result
if [[ "$HTTP_CODE" == "200" || "$HTTP_CODE" == "201" ]]; then
echo "✅ Test user created successfully"
elif [[ "$HTTP_CODE" == "403" ]]; then
echo "❌ Registration forbidden (403) - checking if user exists..."
# Check if user already exists in database
USER_EXISTS=$(sudo docker exec wekan-db mongosh wekan --eval 'db.users.findOne({username: "omriza5"})' --quiet)
if [[ "$USER_EXISTS" != "null" ]]; then
echo " User already exists in database"
else
echo "❌ Registration is disabled and user doesn't exist"
exit 1
fi
else
echo "❌ User creation failed. HTTP Code: $HTTP_CODE"
echo "Response: $BODY"
exit 1
fi
# Verify user exists
echo "🔍 Verifying user creation..."
sudo docker exec wekan-db mongosh wekan --eval 'db.users.findOne({username: "omriza5"}, {username: 1, emails: 1, isAdmin: 1})'
API-tests:
needs: deploy
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v4
with:
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run API tests
env:
BASE_URL: ${{ secrets.WEKAN_URL }}
run: |
pytest --maxfail=5 --disable-warnings -v