name: Publish Image
on:
  push:
    branches:
      - main

jobs:
  build-and-publish:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - name: Login to GitHub Container Registry
        uses: docker/login-action@v1
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Build and push Docker image
        env:
          BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
        run: |
          docker build --build-arg BOT_TOKEN=$BOT_TOKEN . -t ghcr.io/bmonish/devtools-bot:latest -t ghcr.io/bmonish/devtools-bot:${{github.sha}}
          docker push ghcr.io/bmonish/devtools-bot:latest
          docker push ghcr.io/bmonish/devtools-bot:${{github.sha}}