added workflow tests #4
Workflow file for this run
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: Web App Test | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
jobs: | |
build_and_test: | |
runs-on: ubuntu-latest | |
services: | |
mongo: | |
image: mongo | |
env: | |
MONGO_INITDB_ROOT_USERNAME: ${{ secrets.MONGO_INITDB_ROOT_USERNAME }} | |
MONGO_INITDB_ROOT_PASSWORD: ${{ secrets.MONGO_INITDB_ROOT_PASSWORD }} | |
ports: | |
- 27017:27017 | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Environment File | |
run: | | |
echo "MONGO_INITDB_ROOT_USERNAME=${{ secrets.MONGO_INITDB_ROOT_USERNAME }}" > .env | |
echo "MONGO_INITDB_ROOT_PASSWORD=${{ secrets.MONGO_INITDB_ROOT_PASSWORD }}" >> .env | |
- name: Remove previous Docker containers | |
run: docker-compose down -v || true | |
- name: Check used ports | |
run: sudo netstat -tulnp | grep 27017 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Build Docker Image | |
run: docker-compose build | |
- name: Run Docker Containers | |
run: docker-compose up -d | |
- name: Run Tests | |
run: docker exec <container_name> pytest | |
- name: Clean up | |
if: always() | |
run: docker-compose down |