Skip to content

Commit

Permalink
user.update (#255)
Browse files Browse the repository at this point in the history
* test

* test

* validate pr refs

* reset api app

* add .venv

* add code checkers

* set cwd

* new deps

* remove unused config

* fix pylint_django bug

* quick save

* finalize

* move logic to signal

* feedback

* split run into separate files

* update test cases

* house keeping

* house keeping
  • Loading branch information
SKairinos authored Jan 23, 2024
1 parent b8255b2 commit 85311da
Show file tree
Hide file tree
Showing 96 changed files with 1,207 additions and 9,417 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/contributing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@ on:
pull_request:

jobs:
validate-pr-refs:
uses: ocadotechnology/codeforlife-workspace/.github/workflows/validate-pull-request-refs.yaml@main

validate-existing-contributors:
uses: ocadotechnology/codeforlife-workspace/.github/workflows/validate-existing-contributors.yaml@main
299 changes: 152 additions & 147 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,150 +15,155 @@ env:
PYTHON_VERSION: 3.8

jobs:
# The below code was adapted from this documentation.
# https://docs.cypress.io/guides/continuous-integration/github-actions#Parallelization
# https://github.com/cypress-io/cypress-docker-images/tree/master/browsers
test-chrome:
runs-on: ubuntu-latest
steps:
- name: 🛫 Checkout
uses: actions/checkout@v3

- name: 🐍 Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
architecture: "x64"

- name: 🧪 Test on Chrome
uses: cypress-io/[email protected]
with:
working-directory: frontend
#TODO: Currently using the run script for local development
start: bash ../run
wait-on: ${{ env.CYPRESS_WAIT_ON }}
wait-on-timeout: ${{ env.CYPRESS_WAIT_ON_TIMEOUT }}
browser: chrome
record: true
spec: ${{ env.CYPRESS_SPEC }}
cache-key: os-${{ runner.os }}-dependencies-${{ hashFiles('yarn.lock') }}
env:
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_ENV: production
# TODO: load these from a file.
REACT_APP_API_BASE_URL: 'http://localhost:8000/api/'
REACT_APP_PORTAL_BASE_URL: 'http://localhost:8000'

- name: 🔍 Report test info
working-directory: frontend
run: npx cypress info

- name: 🔍 Report CPU info
working-directory: frontend
run: node -p 'os.cpus()'

- name: ✅ Upload coverage to Codecov
uses: codecov/[email protected]

build-and-deploy:
runs-on: ubuntu-latest
needs: [test-chrome]
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 Node
uses: actions/setup-node@v3
with:
node-version: 18

- 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 Frontend Dependencies
working-directory: ./frontend
run: yarn install
# TODO: fix dependencies and uncomment below lines
# env:
# NODE_ENV: production

- name: 🛠 Build Frontend
working-directory: ./frontend
run: yarn run build
env:
NODE_ENV: production

- name: 🛠 Bundle Frontend
working-directory: ./frontend
run: node djangoBundler.js
env:
NODE_ENV: production
REACT_APP_API_BASE_URL: ${{ vars.REACT_APP_API_BASE_URL }}
REACT_APP_PORTAL_BASE_URL: ${{ vars.REACT_APP_PORTAL_BASE_URL }}
REACT_APP_SSO_SERVICE_NAME: ${{ vars.REACT_APP_SSO_SERVICE_NAME }}
REACT_APP_SSO_SERVICE_PROTOCOL: 'https'
REACT_APP_SSO_SERVICE_DOMAIN: 'codeforlife.education'
REACT_APP_SSO_SERVICE_PORT: '443'

- name: 🛠 Install Backend Dependencies
working-directory: ./backend
run: |
python -m pip install --upgrade pip
python -m pip install pipenv
pipenv install
- name: 🔎 Check Migrations
working-directory: ./backend
run: pipenv run python ./manage.py makemigrations --check --dry-run

- name: 🛠 Generate requirements.txt
working-directory: ./backend
run: pipenv requirements > requirements.txt

- name: 🛠 Collect Static Files
working-directory: ./backend
run: pipenv run python ./manage.py collectstatic --noinput --clear

# https://mikefarah.gitbook.io/yq/
- name: 🖊️ Configure App Deployment
uses: mikefarah/yq@master
with:
cmd: |
SERVICE_NAME=$(
if [ ${{ github.ref_name }} == "production" ]
then echo ${{ env.SERVICE_NAME }}
else echo ${{ github.ref_name }}-${{ env.SERVICE_NAME }}
fi
)
SERVICE_IS_ROOT=$(
if [ ${{ github.ref_name }} == "production" ]
then echo "1"
else echo "0"
fi
)
yq -i '
.service = "${{ github.ref_name }}-${{ env.SERVICE }}" |
.env_variables.SECRET_KEY = "${{ vars.SECRET_KEY }}" |
.env_variables.SERVICE_NAME = "$SERVICE_NAME" |
.env_variables.SERVICE_IS_ROOT = "$SERVICE_IS_ROOT" |
.env_variables.MODULE_NAME = "${{ github.ref_name }}"
' backend/app.yaml
- name: 🚀 Deploy App on GCloud
working-directory: ./backend
run: gcloud app deploy
test-backend:
uses: ocadotechnology/codeforlife-workspace/.github/workflows/test-python-code.yaml@main
with:
working-directory: backend

# # The below code was adapted from this documentation.
# # https://docs.cypress.io/guides/continuous-integration/github-actions#Parallelization
# # https://github.com/cypress-io/cypress-docker-images/tree/master/browsers
# test-chrome:
# runs-on: ubuntu-latest
# steps:
# - name: 🛫 Checkout
# uses: actions/checkout@v3

# - name: 🐍 Setup Python
# uses: actions/setup-python@v4
# with:
# python-version: ${{ env.PYTHON_VERSION }}
# architecture: "x64"

# - name: 🧪 Test on Chrome
# uses: cypress-io/[email protected]
# with:
# working-directory: frontend
# #TODO: Currently using the run script for local development
# start: bash ../run
# wait-on: ${{ env.CYPRESS_WAIT_ON }}
# wait-on-timeout: ${{ env.CYPRESS_WAIT_ON_TIMEOUT }}
# browser: chrome
# record: true
# spec: ${{ env.CYPRESS_SPEC }}
# cache-key: os-${{ runner.os }}-dependencies-${{ hashFiles('yarn.lock') }}
# env:
# CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# NODE_ENV: production
# # TODO: load these from a file.
# REACT_APP_API_BASE_URL: 'http://localhost:8000/api/'
# REACT_APP_PORTAL_BASE_URL: 'http://localhost:8000'

# - name: 🔍 Report test info
# working-directory: frontend
# run: npx cypress info

# - name: 🔍 Report CPU info
# working-directory: frontend
# run: node -p 'os.cpus()'

# - name: ✅ Upload coverage to Codecov
# uses: codecov/[email protected]

# build-and-deploy:
# runs-on: ubuntu-latest
# needs: [test-chrome]
# 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 Node
# uses: actions/setup-node@v3
# with:
# node-version: 18

# - 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 Frontend Dependencies
# working-directory: ./frontend
# run: yarn install
# # TODO: fix dependencies and uncomment below lines
# # env:
# # NODE_ENV: production

# - name: 🛠 Build Frontend
# working-directory: ./frontend
# run: yarn run build
# env:
# NODE_ENV: production

# - name: 🛠 Bundle Frontend
# working-directory: ./frontend
# run: node djangoBundler.js
# env:
# NODE_ENV: production
# REACT_APP_API_BASE_URL: ${{ vars.REACT_APP_API_BASE_URL }}
# REACT_APP_PORTAL_BASE_URL: ${{ vars.REACT_APP_PORTAL_BASE_URL }}
# REACT_APP_SSO_SERVICE_NAME: ${{ vars.REACT_APP_SSO_SERVICE_NAME }}
# REACT_APP_SSO_SERVICE_PROTOCOL: 'https'
# REACT_APP_SSO_SERVICE_DOMAIN: 'codeforlife.education'
# REACT_APP_SSO_SERVICE_PORT: '443'

# - name: 🛠 Install Backend Dependencies
# working-directory: ./backend
# run: |
# python -m pip install --upgrade pip
# python -m pip install pipenv
# pipenv install

# - name: 🔎 Check Migrations
# working-directory: ./backend
# run: pipenv run python ./manage.py makemigrations --check --dry-run

# - name: 🛠 Generate requirements.txt
# working-directory: ./backend
# run: pipenv requirements > requirements.txt

# - name: 🛠 Collect Static Files
# working-directory: ./backend
# run: pipenv run python ./manage.py collectstatic --noinput --clear

# # https://mikefarah.gitbook.io/yq/
# - name: 🖊️ Configure App Deployment
# uses: mikefarah/yq@master
# with:
# cmd: |
# SERVICE_NAME=$(
# if [ ${{ github.ref_name }} == "production" ]
# then echo ${{ env.SERVICE_NAME }}
# else echo ${{ github.ref_name }}-${{ env.SERVICE_NAME }}
# fi
# )

# SERVICE_IS_ROOT=$(
# if [ ${{ github.ref_name }} == "production" ]
# then echo "1"
# else echo "0"
# fi
# )

# yq -i '
# .service = "${{ github.ref_name }}-${{ env.SERVICE }}" |
# .env_variables.SECRET_KEY = "${{ vars.SECRET_KEY }}" |
# .env_variables.SERVICE_NAME = "$SERVICE_NAME" |
# .env_variables.SERVICE_IS_ROOT = "$SERVICE_IS_ROOT" |
# .env_variables.MODULE_NAME = "${{ github.ref_name }}"
# ' backend/app.yaml

# - name: 🚀 Deploy App on GCloud
# working-directory: ./backend
# run: gcloud app deploy
41 changes: 35 additions & 6 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,45 @@
"editor.tabSize": 2,
"javascript.preferences.quoteStyle": "single",
"typescript.preferences.quoteStyle": "single",
"isort.path": [
"backend/.venv/bin/python",
"-m",
"isort"
],
"isort.args": [
"--settings-file=backend/pyproject.toml"
],
"black-formatter.path": [
"backend/.venv/bin/python",
"-m",
"black"
],
"black-formatter.args": [
"--config",
"backend/pyproject.toml"
"--config=backend/pyproject.toml"
],
"python.testing.pytestArgs": [
"-c=backend/pyproject.toml",
"backend"
"mypy-type-checker.cwd": "${workspaceFolder}/backend",
"mypy-type-checker.path": [
".venv/bin/python",
"-m",
"mypy"
],
"mypy-type-checker.args": [
"--config-file=pyproject.toml"
],
"pylint.cwd": "${workspaceFolder}/backend",
"pylint.path": [
".venv/bin/python",
"-m",
"pylint"
],
"pylint.args": [
"--rcfile=backend/pyproject.toml"
"--rcfile=pyproject.toml"
],
"python.testing.cwd": "${workspaceFolder}/backend",
"python.testing.pytestArgs": [
"-n=auto",
"-c=pyproject.toml",
"."
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
Expand Down
File renamed without changes.
6 changes: 4 additions & 2 deletions backend/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ google-cloud-logging = "==1.*"
google-auth = "==2.*"
google-cloud-container = "==2.3.0"
"django-anymail[amazon_ses]" = "==7.0.*"
codeforlife = {ref = "v0.9.2", git = "https://github.com/ocadotechnology/codeforlife-package-python.git"}
codeforlife = {ref = "code-checkers", git = "https://github.com/ocadotechnology/codeforlife-package-python.git"}
django = "==3.2.20"
djangorestframework = "==3.13.1"
django-cors-headers = "==4.1.0"
Expand All @@ -54,12 +54,14 @@ pytest-order = "*"
pyvirtualdisplay = "*"
pytest-mock = "*"
PyPDF2 = "==2.10.6"
black = "*"
black = "==23.12.1"
pytest-env = "==0.8.2"
mypy = "==1.6.1"
django-stubs = {version = "==4.2.6", extras = ["compatible-mypy"]}
djangorestframework-stubs = {version = "==3.14.4", extras = ["compatible-mypy"]}
pylint = "==3.0.2"
pylint-django = "==2.5.5"
isort = "==5.13.2"

[requires]
python_version = "3.8"
Loading

0 comments on commit 85311da

Please sign in to comment.