Skip to content

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

Add API tests and update CI wf to start containers

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

Workflow file for this run

name: Build App
on:
pull_request:
branches: [ "main" ]
env:
SHA: ${{ github.sha }}
jobs:
run-api-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Start containers
uses: hoverkraft-tech/[email protected]
env:
SHA: ${{ env.SHA }}
up-flags: "--force-recreate"
- 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 }}