name: docker

on:
  push:
    branches:
      - 'main'

jobs:
  build-and-publish:
    name: Build & Publish
    runs-on: ubuntu-latest

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

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

      - name: Build and push Docker image to ghcr.io
        uses: docker/build-push-action@v2
        with:
          context: .
          push: ${{ github.event_name != 'pull_request' }}
          tags: ghcr.io/marconlp/snapify:latest
          labels: |
            org.opencontainers.image.url=https://github.com/marconlp/snapify
            org.opencontainers.image.source=https://github.com/marconlp/snapify
            org.opencontainers.image.title=snapify
            org.opencontainers.image.revision=${{ github.sha }}
            org.opencontainers.image.created=${{ github.event.repository.updated_at }}
            org.opencontainers.image.description=Screen recording sharing for absolutely everyone.
