-
Notifications
You must be signed in to change notification settings - Fork 1
97 lines (84 loc) · 3.48 KB
/
build-and-test.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# 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
# 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
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