-
Notifications
You must be signed in to change notification settings - Fork 0
89 lines (77 loc) · 2.72 KB
/
api.yml
File metadata and controls
89 lines (77 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
name: API CI/CD
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
jobs:
test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: services/api
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
- name: Run tests with coverage
run: |
pytest --cov=. --cov-report=term --cov-report=xml
- name: Check coverage threshold
run: |
coverage report --fail-under=80
build-and-push:
needs: test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build API image (test only)
if: ${{ github.event_name == 'pull_request' }}
uses: docker/build-push-action@v5
with:
context: .
file: ./services/api/Dockerfile
push: false
tags: marketplace-api:test
- name: Login to Docker Hub
# Only runs on main/master pushes; secrets required but not referenced in the condition to avoid invalid workflow errors
if: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') }}
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push API image
if: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') }}
uses: docker/build-push-action@v5
with:
context: .
file: ./services/api/Dockerfile
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/marketplace-api:latest
${{ secrets.DOCKERHUB_USERNAME }}/marketplace-api:${{ github.sha }}
deploy:
needs: build-and-push
runs-on: ubuntu-latest
env:
DO_API_TOKEN: ${{ secrets.DO_API_TOKEN }}
DO_APP_ID: ${{ secrets.DO_APP_ID }}
if: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') }}
steps:
- name: Trigger DigitalOcean App Platform deployment
if: ${{ env.DO_API_TOKEN != '' && env.DO_APP_ID != '' }}
run: |
curl -X POST \
-H "Authorization: Bearer ${DO_API_TOKEN}" \
-H "Content-Type: application/json" \
"https://api.digitalocean.com/v2/apps/${DO_APP_ID}/deployments"