Skip to content

feat: added mock script #12

feat: added mock script

feat: added mock script #12

name: Test and Deploy to EC2
on:
pull_request:
branches: [ "main" ]
types: [opened, synchronize, reopened, closed]
jobs:
test-api:
if: github.event.action != 'closed'
runs-on: ubuntu-latest
name: Test Cloud Services API
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install API dependencies
run: |
cd cloud-services
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pytest pytest-asyncio httpx
- name: Run API tests
run: |
cd cloud-services
pytest tests/ -v --tb=short
test-web:
if: github.event.action != 'closed'
runs-on: ubuntu-latest
name: Test Web Client
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install web dependencies
run: |
cd web-client
npm ci
- name: Run TypeScript type check
run: |
cd web-client
npm run type-check
- name: Run linter
run: |
cd web-client
npm run lint
- name: Build web client
run: |
cd web-client
npm run build
deploy:
if: github.event.pull_request.merged == true && github.event.action == 'closed'
needs: [test-api, test-web]
runs-on: ubuntu-latest
name: Deploy to EC2
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Configure SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.EC2_PEM_KEY }}" > ~/.ssh/CULoop.pem
chmod 600 ~/.ssh/CULoop.pem
printf "Host ec2\n HostName ${{ secrets.EC2_HOST }}\n User ${{ secrets.EC2_USER }}\n IdentityFile ~/.ssh/CULoop.pem\n StrictHostKeyChecking no\n" >> ~/.ssh/config
- name: Deploy to EC2
run: |
ssh ec2 << 'EOF'
cd ~
# Update web client
cd web-client
git pull origin main
npm ci
npm run build
sudo systemctl restart frontend
# Update API
cd ../cloud-services
git pull origin main
python -m pip install --upgrade pip
pip install -r requirements.txt
sudo systemctl restart backend
EOF