|
5 | 5 | branches: [main] |
6 | 6 |
|
7 | 7 | jobs: |
8 | | - deploy: |
| 8 | + test: |
9 | 9 | runs-on: ubuntu-latest |
10 | 10 | steps: |
11 | 11 | - uses: actions/checkout@v4 |
12 | 12 |
|
13 | 13 | - uses: actions/setup-python@v5 |
14 | 14 | with: |
15 | 15 | python-version: "3.12" |
| 16 | + cache: 'pip' |
16 | 17 |
|
17 | 18 | - name: Run tests |
18 | 19 | run: | |
19 | 20 | pip install -r requirements.txt |
20 | 21 | pip install pytest |
21 | | - pytest --tb=short || echo "No tests found, skipping" |
| 22 | + if python -m pytest --collect-only -q 2>/dev/null | grep -q "test"; then |
| 23 | + pytest --tb=short |
| 24 | + else |
| 25 | + echo "No tests found, skipping" |
| 26 | + fi |
| 27 | +
|
| 28 | + deploy: |
| 29 | + needs: test |
| 30 | + runs-on: ubuntu-latest |
| 31 | + steps: |
| 32 | + - uses: actions/checkout@v4 |
| 33 | + |
| 34 | + - name: Create deployment |
| 35 | + id: deployment |
| 36 | + uses: actions/github-script@v7 |
| 37 | + with: |
| 38 | + script: | |
| 39 | + const deployment = await github.rest.repos.createDeployment({ |
| 40 | + owner: context.repo.owner, |
| 41 | + repo: context.repo.repo, |
| 42 | + ref: context.sha, |
| 43 | + environment: 'production', |
| 44 | + auto_merge: false, |
| 45 | + required_contexts: [], |
| 46 | + description: `Deploy ${context.sha.substring(0, 7)} to production` |
| 47 | + }); |
| 48 | + return deployment.data.id; |
22 | 49 |
|
23 | 50 | - name: Deploy to server |
24 | 51 | uses: appleboy/ssh-action@v1 |
@@ -79,3 +106,30 @@ jobs: |
79 | 106 | } |
80 | 107 | CADDYEOF |
81 | 108 | docker compose -f /opt/platform/docker-compose.yml exec -T caddy caddy reload --config /etc/caddy/Caddyfile |
| 109 | +
|
| 110 | + - name: Update deployment status (success) |
| 111 | + if: success() |
| 112 | + uses: actions/github-script@v7 |
| 113 | + with: |
| 114 | + script: | |
| 115 | + await github.rest.repos.createDeploymentStatus({ |
| 116 | + owner: context.repo.owner, |
| 117 | + repo: context.repo.repo, |
| 118 | + deployment_id: ${{ steps.deployment.outputs.result }}, |
| 119 | + state: 'success', |
| 120 | + environment_url: `https://${{ secrets.APP_DOMAIN }}`, |
| 121 | + description: 'Deployment succeeded' |
| 122 | + }); |
| 123 | +
|
| 124 | + - name: Update deployment status (failure) |
| 125 | + if: failure() |
| 126 | + uses: actions/github-script@v7 |
| 127 | + with: |
| 128 | + script: | |
| 129 | + await github.rest.repos.createDeploymentStatus({ |
| 130 | + owner: context.repo.owner, |
| 131 | + repo: context.repo.repo, |
| 132 | + deployment_id: ${{ steps.deployment.outputs.result }}, |
| 133 | + state: 'failure', |
| 134 | + description: 'Deployment failed' |
| 135 | + }); |
0 commit comments