1- name : Deploy FNS API to Cloud Run (Separated Jobs)
1+ name : Branch-Specific Deploy FNS API to Cloud Run
22
33on :
44 push :
55 branches :
66 - master
7+ - develop
78 pull_request :
89 branches :
10+ - develop
911 - master
1012
1113jobs :
14+ test :
15+ name : Run Backend Tests
16+ runs-on : ubuntu-latest
17+ steps :
18+ - name : Checkout code
19+ uses : actions/checkout@v2
20+
21+ - name : Set up Python 3.9
22+ uses : actions/setup-python@v2
23+ with :
24+ python-version : 3.9
25+
26+ - name : Install dependencies
27+ run : pip install -r requirements.txt
28+
29+ - name : Run tests
30+ run : python -m unittest tests/test_backend.py
31+
1232 build-and-push-image :
1333 name : Build and Push Docker Image
1434 runs-on : ubuntu-latest
35+ needs : test
36+ if : github.ref == 'refs/heads/master' # Condition: Only run on master branch
1537 steps :
1638 - name : Checkout code
1739 uses : actions/checkout@v2
1840
19- - name : Google Cloud Auth # Authenticate gcloud CLI
41+ - name : Google Cloud Auth
2042 uses : google-github-actions/auth@v2
2143 with :
2244 credentials_json : ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
2345
24- - name : Set up Google Cloud CLI # Set up gcloud CLI and Docker
46+ - name : Set up Google Cloud CLI
2547 uses : google-github-actions/setup-gcloud@v2
2648 with :
2749 version : latest
2850 project_id : ${{ secrets.GOOGLE_PROJECT }}
2951
30- - name : Configure Docker to push to Artifact Registry # Configure docker auth
31- run : |
32- gcloud auth configure-docker us-central1-docker.pkg.dev
52+ - name : Configure Docker to push to Artifact Registry
53+ run : gcloud auth configure-docker us-central1-docker.pkg.dev
3354
34- - name : Build and Push Docker image to Artifact Registry # Build and push image
55+ - name : Build and Push Docker image to Artifact Registry
3556 env :
3657 GOOGLE_PROJECT : ${{ secrets.GOOGLE_PROJECT }}
3758 IMAGE_NAME : us-central1-docker.pkg.dev/${{ secrets.GOOGLE_PROJECT }}/flex-net-sim-repo/fns-api
@@ -43,20 +64,21 @@ jobs:
4364 deploy-to-cloud-run :
4465 name : Deploy to Cloud Run
4566 runs-on : ubuntu-latest
46- needs : build-and-push-image # Ensure this job runs after build-and-push-image
67+ needs : build-and-push-image
68+ if : github.ref == 'refs/heads/master' # Condition: Only run on master branch
4769 steps :
48- - name : Checkout code (again, if needed for deploy steps - optional )
70+ - name : Checkout code (again, if needed)
4971 uses : actions/checkout@v2
5072
51- - name : Google Cloud Auth # Authenticate gcloud CLI
73+ - name : Google Cloud Auth
5274 uses : google-github-actions/auth@v2
5375 with :
5476 credentials_json : ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
5577
5678 - name : Deploy to Cloud Run
5779 uses : google-github-actions/deploy-cloudrun@v1
5880 with :
59- image : us-central1-docker.pkg.dev/${{ secrets.GOOGLE_PROJECT }}/flex-net-sim-repo/fns-api:latest # Use the same image as built
81+ image : us-central1-docker.pkg.dev/${{ secrets.GOOGLE_PROJECT }}/flex-net-sim-repo/fns-api:latest
6082 service : fns-api-cloud-run
6183 region : us-central1
6284 project_id : ${{ secrets.GOOGLE_PROJECT }}
0 commit comments