Skip to content

Add API tests and update CI wf to start containers #24

Add API tests and update CI wf to start containers

Add API tests and update CI wf to start containers #24

Workflow file for this run

name: Build App
on:
pull_request:
branches: [ "main" ]
env:
SHA: ${{ github.sha }}
POSTGRES_USER: ${{ secrets.POSTGRES_USER }}
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
POSTGRES_DB: ${{ secrets.POSTGRES_DB }}
POSTGRES_HOST: ${{ secrets.POSTGRES_HOST }}
jobs:
run-api-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Start containers
run: |
docker compose build
docker image ls
docker compose up -d --force-recreate
docker logs api
docker logs database
# - name: Wait for containers
# run: |
# docker ps
# docker logs database
# # max_attempts=3
# # attempt=1
# # while [ $attempt -le $max_attempts ]; do
# # if curl -s http://0.0.0.0:8080/health | grep -q '"status":"OK"'; then
# # echo "Container is up and healthy!"
# # break
# # else
# # echo "Attempt $attempt/$max_attempts: Waiting for container..."
# # attempt=$((attempt + 1))
# # if [ $attempt -le $max_attempts ]; then
# # sleep 60 # Wait for 60 seconds before the next attempt
# # fi
# # fi
# # done
# # if [ $attempt -gt $max_attempts ]; then
# # echo "Container failed to become healthy after $max_attempts attempts."
# # exit 1
# # fi
# - name: Test
# run: go test -v ./...
# build-push-docker-image:
# runs-on: ubuntu-latest
# needs: run-api-tests
# steps:
# - uses: actions/checkout@v4
# - name: Login to Docker Hub
# uses: docker/login-action@v3
# with:
# username: ${{ secrets.DOCKERHUB_USERNAME }}
# password: ${{ secrets.DOCKERHUB_TOKEN }}
# - name: Build and push todo-api
# uses: docker/build-push-action@v6
# with:
# push: true
# tags: ${{ secrets.DOCKERHUB_USERNAME }}/todo-api:${{ env.SHA }}
# - name: Build and push todo-db
# uses: docker/build-push-action@v6
# with:
# file: Dockerfile.db
# push: true
# tags: ${{ secrets.DOCKERHUB_USERNAME }}/todo-db:${{ env.SHA }}