Update commands.md #97
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: OrderFlow CI | |
# on: | |
# push: | |
# branches: [ "main" ] | |
# pull_request: | |
# branches: [ "main" ] | |
on: push | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
max-parallel: 4 | |
# matrix: | |
# python-version: [3.9] | |
# Postgres (running in a Docker container) | |
services: | |
# label used to access the service container | |
postgres: | |
# Docker Hub image | |
image: postgres | |
# provide the password for Postgres | |
env: | |
POSTGRES_PASSWORD: postgres | |
# set health checks to wait until Postgres has started | |
options: >- | |
--health-cmd pg_isready | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
ports: | |
# maps TCP port 5432 on service container to the host | |
- 5432:5432 | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v3 | |
with: | |
python-version: 3.9 | |
- name: Install backend (Python) dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r back/requirements.txt | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 18 | |
- name: Install frontend dependencies | |
run: | | |
cd front | |
npm ci | |
- name: Start backend | |
run: | | |
# export some environment variables to help Django connect to Postgres (running in a Docker container) | |
export POSTGRES_HOST=localhost | |
export POSTGRES_NAME=orderflow_db | |
export POSTGRES_USER=postgres | |
export POSTGRES_PASSWORD=postgres | |
# create the project database | |
sudo apt update | |
sudo apt install postgresql-client | |
PGPASSWORD="$POSTGRES_PASSWORD" psql -h "$POSTGRES_HOST" -U "$POSTGRES_USER" -c "CREATE DATABASE $POSTGRES_NAME;" | |
# create Django and project tables in the project database (see back/orderapi/migrations/0001_initial.py) | |
cd back | |
python manage.py migrate | |
# add products to the project database | |
PGPASSWORD="$POSTGRES_PASSWORD" psql -h "$POSTGRES_HOST" -U "$POSTGRES_USER" -d "$POSTGRES_NAME" << EOF | |
INSERT INTO products (name, price, price_full, image_url, description) | |
VALUES | |
('Whiskerjig Table', 299.99, 349.99, 'http://localhost:3000/images/01.jpg', 'Product 1 description'), | |
('Fluffelorn Chaise', 124.99, 199.99, 'http://localhost:3000/images/02.jpg', 'Product 2 description'), | |
('Gobbledy Table', 259.99, 349.99, 'http://localhost:3000/images/03.jpg', 'Product 3 description'), | |
('Fluffernut Ottoman', 249.99, 499.99, 'http://localhost:3000/images/04.jpg', 'Product 4 description'), | |
('Pufflewump Sofa', 549.99, null, 'http://localhost:3000/images/05.jpg', 'Product 5 description'), | |
('Zippitydoo Table', 129.99, null, 'http://localhost:3000/images/06.jpg', 'Product 6 description'), | |
('Snuggleplank Table', 29.99, null, 'http://localhost:3000/images/07.jpg', 'Product 7 description'), | |
('Bumbleflop Chair', 519.99, 629.99, 'http://localhost:3000/images/08.jpg', 'Product 8 description'), | |
('Zonkplunk Ottoman', 229.99, null, 'http://localhost:3000/images/09.jpg', 'Product 9 description'), | |
('Flibberjibber Table', 329.99, null, 'http://localhost:3000/images/10.jpg', 'Product 10 description'); | |
EOF | |
# start the Django server | |
python manage.py runserver 0.0.0.0:8000 & | |
- name: Run API Tests (Cypress) | |
uses: cypress-io/github-action@v5 | |
with: | |
working-directory: ./front | |
# wait-on: 'http://localhost:8000' | |
- name: Start frontend | |
run: | | |
cd front | |
npm start & | |
- name: Run UI Tests (pytest/Selenium) | |
run: | | |
pytest . |