Skip to content

Run tests in develop #26

Run tests in develop

Run tests in develop #26

Workflow file for this run

name: Branch-Specific Deploy FNS API to Cloud Run
on:
push:
branches:
- master
- feature/*
- develop
pull_request:
branches:
- master
- feature/*
- develop
jobs:
test:
name: Run Backend Tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install dependencies
run: pip install -r requirements.txt
- name: Run tests
run: python -m unittest tests/test_backend.py
build-and-push-image:
name: Build and Push Docker Image
runs-on: ubuntu-latest
needs: test
if: github.ref == 'refs/heads/master' # Condition: Only run on master branch
steps:
- name: Checkout code
uses: actions/checkout@v2
- 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
deploy-to-cloud-run:
name: Deploy to Cloud Run
runs-on: ubuntu-latest
needs: build-and-push-image
if: github.ref == 'refs/heads/master' # Condition: Only run on master branch
steps:
- name: Checkout code (again, if needed)
uses: actions/checkout@v2
- 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 }}