new editing #15
This file contains hidden or 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: CI/CD for Flask App | |
| on: | |
| push: | |
| branches: [ main ] | |
| pull_request: | |
| branches: [ main ] | |
| jobs: | |
| lint: | |
| name: Lint Code | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.12' | |
| - name: Install flake8 | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install flake8 -r requirements.txt | |
| - name: Run flake8 | |
| run: | | |
| flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | |
| test: | |
| name: Run Tests | |
| runs-on: ubuntu-latest | |
| needs: lint | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.12' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| pip install pytest | |
| - name: Run pytest | |
| run: | | |
| if [ -d tests ]; then pytest; else echo 'No tests directory'; fi | |
| docker-build: | |
| name: Build Docker Image | |
| runs-on: ubuntu-latest | |
| needs: test | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Build Docker image | |
| run: | | |
| docker build -t flask-app-test . | |
| docker-run: | |
| name: Run Docker Container (Test Startup) | |
| runs-on: ubuntu-latest | |
| needs: docker-build | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Build Docker image (again for this job) | |
| run: | | |
| docker build -t flask-app-test . | |
| - name: Run container and check logs | |
| run: | | |
| docker run --rm -d -p 5003:5003 --name flask-app-test-container flask-app-test | |
| sleep 10 | |
| docker ps -a | |
| docker logs flask-app-test-container || true | |
| docker stop flask-app-test-container |