Create copilot-audit.yml #28
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: FastAPI CI/CD | |
| on: | |
| pull_request: | |
| branches: | |
| - main | |
| - develop | |
| - "release/**" | |
| push: | |
| branches: | |
| - main | |
| - develop | |
| permissions: | |
| contents: read | |
| jobs: | |
| test: | |
| name: Python Tests | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| python-version: ["3.11", "3.12", "3.13"] | |
| steps: | |
| - name: Checkout repo | |
| uses: actions/checkout@v4 | |
| - name: Setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| pip install -r requirements-dev.txt | |
| - name: Lint | |
| run: ruff check . | |
| - name: Run tests | |
| run: pytest --maxfail=1 --disable-warnings -q | |
| deploy: | |
| name: Deploy FastAPI | |
| runs-on: ubuntu-latest | |
| needs: test # รัน Deploy เฉพาะเมื่อ Test ผ่าน | |
| steps: | |
| - name: Checkout repo | |
| uses: actions/checkout@v4 | |
| - name: Build Docker image | |
| run: docker build -t my-fastapi-app:latest . | |
| - name: Push to DockerHub | |
| run: | | |
| echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin | |
| docker tag my-fastapi-app:latest mydockerhubuser/my-fastapi-app:latest | |
| docker push mydockerhubuser/my-fastapi-app:latest | |
| - name: Deploy with Uvicorn | |
| run: | | |
| docker run -d -p 8000:8000 mydockerhubuser/my-fastapi-app:latest |