name: CI - Test, Build, and Push on: push: branches: - main pull_request: branches: - main jobs: test: runs-on: ubuntu-latest container: hexpm/elixir:1.17.3-erlang-27.1.2-debian-bookworm-20240904-slim services: postgres: image: postgres:16 env: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres POSTGRES_DB: localspot_test options: >- --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 steps: - name: Install build dependencies run: | apt-get update -y apt-get install -y build-essential git - name: Checkout repository run: | git clone ${{ github.server_url }}/${{ github.repository }} . git checkout ${{ github.sha }} - name: Install hex and rebar run: | mix local.hex --force mix local.rebar --force - name: Install dependencies run: mix deps.get - name: Check formatting run: mix format --check-formatted - name: Compile (warnings as errors) run: mix compile --warnings-as-errors - name: Setup database env: MIX_ENV: test DATABASE_URL: postgres://postgres:postgres@postgres:5432/localspot_test run: mix ecto.create && mix ecto.migrate - name: Run tests env: MIX_ENV: test DATABASE_URL: postgres://postgres:postgres@postgres:5432/localspot_test run: mix test build-and-push: needs: test if: github.ref == 'refs/heads/main' && github.event_name == 'push' runs-on: ubuntu-latest container: docker:latest steps: - name: Checkout repository run: | git clone ${{ github.server_url }}/${{ github.repository }} . git checkout ${{ github.sha }} - name: Log in to Forgejo Container Registry run: | echo "Logging in as: ${{ github.actor }}" echo "${{ secrets.FORGEJO_TOKEN }}" | docker login forgejo.sivic.me -u ${{ github.actor }} --password-stdin echo "Login exit code: $?" - name: Build and push Docker images run: | docker build \ -t forgejo.sivic.me/${{ github.repository }}:latest \ -t forgejo.sivic.me/${{ github.repository }}:${{ github.sha }} \ . docker push forgejo.sivic.me/${{ github.repository }}:latest docker push forgejo.sivic.me/${{ github.repository }}:${{ github.sha }} - name: Summary run: | echo "✅ Successfully built and pushed:" echo " - forgejo.sivic.me/${{ github.repository }}:latest" echo " - forgejo.sivic.me/${{ github.repository }}:${{ github.sha }}"