Add initial project structure with Docker, CI/CD workflows, and examp… #3
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: Python CI | |
| on: | |
| push: | |
| branches: ["main"] | |
| pull_request: | |
| branches: ["main"] | |
| jobs: | |
| # Run tests | |
| tests: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| python-version: [3.12, 3.13, 3.14] | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: actions/setup-python@v6 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Cache pip packages | |
| uses: actions/cache@v5 | |
| with: | |
| path: ~/.cache/pip | |
| key: ${{ runner.os }}-pip | |
| - name: Install dependencies | |
| run: | | |
| pip install pytest | |
| if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | |
| - name: Run Tests | |
| run: pytest --junitxml=test-results.xml | |
| - name: Upload Test Results | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: test-results-${{ matrix.python-version }} | |
| path: test-results.xml | |
| # Check if code follows code flake8 code style | |
| lint: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - run: pip install flake8 | |
| - run: flake8 . | |
| # Build Docker container and run a simple test to check if it is working | |
| container-build: | |
| runs-on: ubuntu-latest | |
| needs: [tests, lint] | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Build Docker Image | |
| run: docker build -t my-python-app:latest . | |
| - name: Run Container Test | |
| run: | | |
| docker run -d --name my-python-app-test -p 8000:8000 my-python-app:latest | |
| sleep 5 | |
| curl --fail http://localhost:8000/health | |
| docker stop my-python-app-test |