name: Build and Push Docker Image

on:
  push:
    branches:
      - main
      - ci-test 

jobs:
  build-and-push:
    runs-on: ubuntu-latest

    steps:
        - name: Checkout code
          uses: actions/checkout@v2

        - name: Set up Go
          uses: actions/setup-go@v3
          with:
            go-version: '1.23'
        
        - name: Log in to GitHub Container Registry
          uses: docker/login-action@v2
          with:
            registry: ghcr.io
            username: ${{ github.actor }}
            password: ${{ secrets.GITHUB_TOKEN }}

        - name: Build Docker image
          run: |
            docker build -t ghcr.io/${{ github.repository | toLowerCase}}/go-web-server:latest .
  
        - name: Push Docker image to GitHub Container Registry
          run: |
            docker push ghcr.io/${{ github.repository | toLowerCase }}/go-web-server:latest
  
        - name: Verify image is pushed
          run: |
            echo "Docker image pushed to: ghcr.io/${{ github.repository | toLowerCase }}/go-web-server:latest"