-
Notifications
You must be signed in to change notification settings - Fork 0
138 lines (117 loc) · 3.74 KB
/
fns-api-workflow.yml
File metadata and controls
138 lines (117 loc) · 3.74 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
name: pipeline
on:
# Run on pushes to any branch
push:
branches:
- '**'
# Run on pull requests to these branches
pull_request:
branches:
- master
- develop
# Allow manual trigger
workflow_dispatch:
# Permissions needed for GitHub Pages
permissions:
contents: read
pages: write
id-token: write
# Allow only one concurrent deployment
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
# Job 1: Run tests and generate coverage report
test-coverage:
name: Run Tests with Coverage
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python 3.9
uses: actions/setup-python@v4
with:
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run tests with coverage
run: |
pytest --cov=backend --cov=utils --cov-report=html tests/
- name: Prepare coverage report for GitHub Pages
run: |
mkdir -p public/coverage
mv htmlcov/* public/coverage/
- name: Upload static files as artifact
uses: actions/upload-pages-artifact@v3
with:
name: github-pages
path: './public'
# Job 2: Deploy GitHub Pages
deploy-pages:
name: Deploy Coverage Report
if: github.ref == 'refs/heads/master'
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: test-coverage
steps:
- name: Setup Pages
uses: actions/configure-pages@v3
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: github-pages
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
# Job 3: Build and push Docker image (master only)
build-and-push-image:
name: Build and Push Docker Image
needs: test-coverage
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Google Cloud Auth
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
- name: Set up Google Cloud CLI
uses: google-github-actions/setup-gcloud@v2
with:
version: latest
project_id: ${{ secrets.GOOGLE_PROJECT }}
- name: Configure Docker to push to Artifact Registry
run: gcloud auth configure-docker us-central1-docker.pkg.dev
- name: Build and Push Docker image to Artifact Registry
env:
GOOGLE_PROJECT: ${{ secrets.GOOGLE_PROJECT }}
IMAGE_NAME: us-central1-docker.pkg.dev/${{ secrets.GOOGLE_PROJECT }}/flex-net-sim-repo/fns-api
IMAGE_TAG: latest
run: |
docker build -t $IMAGE_NAME:$IMAGE_TAG .
docker push $IMAGE_NAME:$IMAGE_TAG
# Job 4: Deploy to Cloud Run (master only)
deploy-to-cloud-run:
name: Deploy to Cloud Run
needs: build-and-push-image
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Google Cloud Auth
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
- name: Deploy to Cloud Run
uses: google-github-actions/deploy-cloudrun@v1
with:
image: us-central1-docker.pkg.dev/${{ secrets.GOOGLE_PROJECT }}/flex-net-sim-repo/fns-api:latest
service: fns-api-cloud-run
region: us-central1
project_id: ${{ secrets.GOOGLE_PROJECT }}