name: "CI pipeline"

on:
  release:
    types:
      - published
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest

    permissions:
      packages: write

    steps:
      - uses: actions/checkout@v5

      - uses: zoexx/github-action-json-file-properties@release
        id: package_json
        with:
          file_path: "package.json"

      - uses: docker/metadata-action@v5
        id: meta
        with:
          images: |
            ${{ github.repository }}
            ghcr.io/${{ github.repository }}
          tags: |
            latest
            ${{ steps.package_json.outputs.version }}

      - name: "Login to Docker Hub"
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}

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

      - uses: docker/build-push-action@v6
        with:
          context: .
          build-args: |
            SIGNALR_URL=https://ezlog.app/api/comms
            ENDPOINT_URL=https://ezlog.app/api/send
            COMMIT=${{ github.sha }}
          push: true
          tags: ${{ steps.meta.outputs.tags }}
