|
| 1 | +name: Deploy |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + pull_request: |
| 8 | + |
| 9 | +jobs: |
| 10 | + test: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + strategy: |
| 13 | + matrix: |
| 14 | + python-version: ["3.10"] |
| 15 | + |
| 16 | + steps: |
| 17 | + - name: Checkout repository |
| 18 | + uses: actions/checkout@v4 |
| 19 | + |
| 20 | + - name: Set up Python |
| 21 | + uses: actions/setup-python@v4 |
| 22 | + with: |
| 23 | + python-version: ${{ matrix.python-version }} |
| 24 | + |
| 25 | + - name: Cache dependencies |
| 26 | + uses: actions/cache@v3 |
| 27 | + with: |
| 28 | + path: ~/.cache/pip |
| 29 | + key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('**/requirements.txt') }} |
| 30 | + restore-keys: | |
| 31 | + ${{ runner.os }}-pip-${{ matrix.python-version }}- |
| 32 | + ${{ runner.os }}-pip- |
| 33 | +
|
| 34 | + - name: Install dependencies |
| 35 | + run: | |
| 36 | + python -m pip install --upgrade pip |
| 37 | + pip install -r requirements.txt |
| 38 | +
|
| 39 | + - name: Run linting |
| 40 | + run: | |
| 41 | + pip install flake8 |
| 42 | + flake8 . |
| 43 | +
|
| 44 | + - name: Run tests |
| 45 | + run: pytest |
| 46 | + |
| 47 | + deploy: |
| 48 | + runs-on: ubuntu-latest |
| 49 | + needs: test # Ensures tests pass before deploying |
| 50 | + if: github.ref == 'refs/heads/main' # Only deploys from main branch |
| 51 | + |
| 52 | + steps: |
| 53 | + - name: Checkout repository |
| 54 | + uses: actions/checkout@v4 |
| 55 | + |
| 56 | + - name: Set up Python |
| 57 | + uses: actions/setup-python@v4 |
| 58 | + with: |
| 59 | + python-version: "3.10" |
| 60 | + |
| 61 | + - name: Install dependencies |
| 62 | + run: | |
| 63 | + python -m pip install --upgrade pip |
| 64 | + pip install -r requirements.txt |
| 65 | +
|
| 66 | + - name: Deploy Application |
| 67 | + run: | |
| 68 | + echo "Deploying application..." |
| 69 | + # Add actual deployment commands here, e.g.: |
| 70 | + # scp -r . user@server:/path/to/app |
| 71 | + # ssh user@server "systemctl restart my-app" |
| 72 | +
|
| 73 | + - name: Notify Deployment Success |
| 74 | + run: echo "Deployment successful!" |
0 commit comments