generated from ocadotechnology/codeforlife-template-backend
-
Notifications
You must be signed in to change notification settings - Fork 22
104 lines (87 loc) · 2.86 KB
/
main.yaml
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
98
99
100
101
102
103
104
name: Main
on:
push:
paths-ignore:
- "README.md"
- "CHANGELOG.md"
- "LICENSE"
- ".gitignore"
- ".vscode"
workflow_dispatch:
env:
SERVICE: sso
PYTHON_VERSION: 3.8
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: 🛫 Checkout
uses: actions/checkout@v3
- name: 🐍 Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install Python Packages
working-directory: ./backend
run: |
python -m pip install --upgrade pip
python -m pip install pipenv
pipenv install --dev
- name: Check Code Format
working-directory: ./backend
run: if ! pipenv run black --check .; then exit 1; fi
- name: Check Migrations
working-directory: ./backend
run: pipenv run python manage.py makemigrations --check --dry-run
# TODO: assert code coverage target.
- name: Test Code Units
working-directory: ./backend
run: pipenv run pytest
build-and-deploy:
runs-on: ubuntu-latest
needs: [test]
if: github.ref_name == 'production' || github.ref_name == 'development' || github.ref_name == 'staging'
environment: ${{ github.ref_name }}
steps:
- name: 🛫 Checkout
uses: actions/checkout@v3
- name: 🐍 Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: 🗝 Authenticate with GCloud
uses: google-github-actions/auth@v1
with:
credentials_json: ${{ secrets.GCP_CREDENTIALS }}
- name: 🤖 Set up GCloud SDK
uses: google-github-actions/setup-gcloud@v1
- name: 🛠 Install Backend Dependencies
working-directory: ./backend
run: |
python -m pip install --upgrade pip
python -m pip install pipenv
pipenv install
- name: 🛠 Generate requirements.txt
working-directory: ./backend
run: pipenv requirements > requirements.txt
- name: ⚙️ Set Service Name
run: |
echo "SERVICE_NAME=$(
if [ ${{ github.ref_name }} == 'production' ]
then echo ${{ env.SERVICE }}
else echo ${{ github.ref_name }}-${{ env.SERVICE }}
fi
)" >> $GITHUB_ENV
# https://mikefarah.gitbook.io/yq/
- name: 🖊️ Configure App Deployment
uses: mikefarah/yq@master
with:
cmd: |
yq -i '
.service = "${{ github.ref_name }}-${{ env.SERVICE }}" |
.env_variables.SECRET_KEY = "${{ secrets.SECRET_KEY }}" |
.env_variables.SERVICE_NAME = "${{ env.SERVICE_NAME }}"
' backend/app.yaml
- name: 🚀 Deploy App on GCloud
working-directory: ./backend
run: gcloud app deploy