Skip to content

Test our workflow runs unit test #1

Test our workflow runs unit test

Test our workflow runs unit test #1

# This workflow builds and tests our Python application.
name: Build and Test
on:
push:
branches:
- 'master'
# - "*" If we want all branches
paths:
- 'app/**' # Only run if our push contains a file in the app folder
permissions:
contents: read
jobs:
build-and-test:
runs-on: ubuntu-latest
# Use the matrix strategy to run build and test steps for both backend_gcf and ui_cr
strategy:
matrix:
app-folder:
- app/backend_gcf
- app/ui_cr
env:
PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
SVC_ACCOUNT: ${{ secrets.GCP_SVC_ACCOUNT }}
SVC_ACCOUNT_CREDS_FILE: ${{ github.workspace }}/${{ secrets.GCP_SVC_ACCOUNT }}.json
SVC_ACCOUNT_EMAIL: ${{ secrets.GCP_SVC_ACCOUNT }}@$PROJECT_ID.iam.gserviceaccount.com
REGION: ${{ vars.GCP_REGION }}
FUNCTIONS_PORT: ${{ vars.GCP_DEV_FUNCTIONS_PORT}}
FLASK_RUN_PORT: ${{ vars.FLASK_RUN_PORT }}
BACKEND_GCF: https://${{ vars.GCP_REGION }}-${{ secrets.GCP_PROJECT_ID }}.${{ vars.GCP_FUNCTION_URI_SUFFIX }}
steps:
- uses: actions/checkout@v4
- name: Check env vars
run: |
echo "Environment variables configured:"
echo PROJECT_ID="$PROJECT_ID"
echo REGION="$REGION"
echo SVC_ACCOUNT="$SVC_ACCOUNT"
echo SVC_ACCOUNT_EMAIL="$SVC_ACCOUNT_EMAIL"
echo SVC_ACCOUNT_CREDS_FILE="$SVC_ACCOUNT_CREDS_FILE"
echo BACKEND_GCF="$BACKEND_GCF"
echo FUNCTIONS_PORT="$FUNCTIONS_PORT"
echo FLASK_RUN_PORT="$FLASK_RUN_PORT"
# Creates a credentials file that will be used for ADC later
- name: Create credentials file
run: |
echo "${{ secrets.GOOGLE_APPLICATION_CREDENTIALS_JSON }}" > $SVC_ACCOUNT_CREDS_FILE
echo "Checking the credentials:"
head -n 5 $SVC_ACCOUNT_CREDS_FILE
shell: bash
# Cache Python dependencies to speed up subsequent runs
- name: Cache pip
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
working-directory: ${{ matrix.app-folder }}
run: |
echo "Installing Python dependencies"
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
working-directory: ${{ matrix.app-folder }}
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
working-directory: ${{ matrix.app-folder }}
run: |
pytest