Skip to content

derailed-dash launched the Build-and-Test workflow 🚀 #18

derailed-dash launched the Build-and-Test workflow 🚀

derailed-dash launched the Build-and-Test workflow 🚀 #18

# This workflow builds and tests our Python application.
name: Build and Test
run-name: ${{ github.actor }} launched the Build-and-Test workflow 🚀
on:
push:
branches-ignore:
- 'master' # Run on all branches except master
paths:
- 'app/**' # Only run if our push contains a file in the app folder
workflow_dispatch: # Allows manual triggering of the workflow.
permissions:
contents: read
env:
PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
SVC_ACCOUNT: ${{ secrets.GCP_SVC_ACCOUNT }}
GOOGLE_APPLICATION_CREDENTIALS: ${{ github.workspace }}/${{ secrets.GCP_SVC_ACCOUNT }}.json
SVC_ACCOUNT_EMAIL: ${{ secrets.GCP_SVC_ACCOUNT }}@${{ secrets.GCP_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 }}
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
# This allows us to re-use this job and run it for each application folder
strategy:
matrix:
app-folder:
- app/backend_gcf
- app/ui_cr
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 GOOGLE_APPLICATION_CREDENTIALS="$GOOGLE_APPLICATION_CREDENTIALS"
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.GCP_SVC_ACCOUNT_CREDS }}" | base64 --decode > $GOOGLE_APPLICATION_CREDENTIALS
echo "Checking the credentials:"
head -n 3 $GOOGLE_APPLICATION_CREDENTIALS
shell: bash
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: 'pip' # caching pip dependencies
- name: Install dependencies
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
echo "Running first flake8:"
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
echo "Flake8 exit code: $?"
echo "Running second flake8:"
# 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
echo "Flake8 exit code: $?"
- name: Test with pytest
working-directory: ${{ matrix.app-folder }}
run: |
pytest || if [ $? -eq 5 ]; then echo "No tests were found, but continuing..."; else exit 1; fi