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+ - feature/*
8+ - develop
79 pull_request :
810 branches :
911 - master
12+ - feature/*
13+ - develop
1014
1115jobs :
16+ test :
17+ name : Run Backend Tests
18+ runs-on : ubuntu-latest
19+ steps :
20+ - name : Checkout code
21+ uses : actions/checkout@v2
22+
23+ - name : Set up Python 3.9
24+ uses : actions/setup-python@v2
25+ with :
26+ python-version : 3.9
27+
28+ - name : Install dependencies
29+ run : pip install -r requirements.txt
30+
31+ - name : Run tests
32+ run : python -m unittest tests/test_backend.py
33+
1234 build-and-push-image :
1335 name : Build and Push Docker Image
1436 runs-on : ubuntu-latest
37+ needs : test
38+ if : github.ref == 'refs/heads/master' # Condition: Only run on master branch
1539 steps :
1640 - name : Checkout code
1741 uses : actions/checkout@v2
1842
19- - name : Google Cloud Auth # Authenticate gcloud CLI
43+ - name : Google Cloud Auth
2044 uses : google-github-actions/auth@v2
2145 with :
2246 credentials_json : ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
2347
24- - name : Set up Google Cloud CLI # Set up gcloud CLI and Docker
48+ - name : Set up Google Cloud CLI
2549 uses : google-github-actions/setup-gcloud@v2
2650 with :
2751 version : latest
2852 project_id : ${{ secrets.GOOGLE_PROJECT }}
2953
30- - name : Configure Docker to push to Artifact Registry # Configure docker auth
31- run : |
32- gcloud auth configure-docker us-central1-docker.pkg.dev
54+ - name : Configure Docker to push to Artifact Registry
55+ run : gcloud auth configure-docker us-central1-docker.pkg.dev
3356
34- - name : Build and Push Docker image to Artifact Registry # Build and push image
57+ - name : Build and Push Docker image to Artifact Registry
3558 env :
3659 GOOGLE_PROJECT : ${{ secrets.GOOGLE_PROJECT }}
3760 IMAGE_NAME : us-central1-docker.pkg.dev/${{ secrets.GOOGLE_PROJECT }}/flex-net-sim-repo/fns-api
@@ -43,20 +66,21 @@ jobs:
4366 deploy-to-cloud-run :
4467 name : Deploy to Cloud Run
4568 runs-on : ubuntu-latest
46- needs : build-and-push-image # Ensure this job runs after build-and-push-image
69+ needs : build-and-push-image
70+ if : github.ref == 'refs/heads/master' # Condition: Only run on master branch
4771 steps :
48- - name : Checkout code (again, if needed for deploy steps - optional )
72+ - name : Checkout code (again, if needed)
4973 uses : actions/checkout@v2
5074
51- - name : Google Cloud Auth # Authenticate gcloud CLI
75+ - name : Google Cloud Auth
5276 uses : google-github-actions/auth@v2
5377 with :
5478 credentials_json : ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
5579
5680 - name : Deploy to Cloud Run
5781 uses : google-github-actions/deploy-cloudrun@v1
5882 with :
59- image : us-central1-docker.pkg.dev/${{ secrets.GOOGLE_PROJECT }}/flex-net-sim-repo/fns-api:latest # Use the same image as built
83+ image : us-central1-docker.pkg.dev/${{ secrets.GOOGLE_PROJECT }}/flex-net-sim-repo/fns-api:latest
6084 service : fns-api-cloud-run
6185 region : us-central1
6286 project_id : ${{ secrets.GOOGLE_PROJECT }}
0 commit comments