Add pre-comit (#17) #68
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: Build and test web application and database | |
on: | |
push: | |
branches: | |
- main | |
- 'feature/*' | |
- '[0-9]*-*[a-zA-Z]*' # regex should match typical issue branches names | |
pull_request: | |
branches: | |
- main | |
jobs: | |
build-and-test: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Python 3.9 | |
uses: actions/setup-python@v2 | |
with: | |
python-version: 3.9 | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install poetry==1.8.1 | |
poetry install --no-root | |
- name: Run docker compose and wait until web server is up | |
env: | |
DB_HOST: ${{ secrets.DB_HOST }} | |
DB_NAME: ${{ secrets.DB_NAME }} | |
DB_USER: ${{ secrets.DB_USER }} | |
DB_PASS: ${{ secrets.DB_PASS }} | |
run: | | |
echo "DB_HOST=$DB_HOST" > .env | |
echo "DB_NAME=$DB_NAME" >> .env | |
echo "DB_USER=$DB_USER" >> .env | |
echo "DB_PASS=$DB_PASS" >> .env | |
docker compose up --build -d | |
echo "Checking .env" | |
cat .env | |
docker compose ps | |
docker ps | |
echo "Checking logs for the database container" | |
docker logs hackathon-starter-db-1 | |
# Wait for PostgreSQL to be ready | |
timeout 60 bash -c 'until docker exec hackathon-starter-db-1 pg_isready; do sleep 1; done' | |
# Additional wait for application to be ready (replace port 8000 with your application's port) | |
timeout 60 bash -c 'until echo > /dev/tcp/localhost/8000; do sleep 1; done' | |
- name: Run API tests | |
run: poetry run pytest tests/test_api.py | |
- name: Run database tests | |
run: docker exec hackathon-starter-web-1 poetry run pytest tests/test_database.py | |
- name: Stop and remove container | |
run: docker compose down |