name: ghcr push

on:
  push:
    branches: ['next']
    paths-ignore: ['**/*.md', '**/*.yml']

env:
  REGISTRY: ghcr.io
  IMAGE_NAME: ${{ github.repository }}

jobs:
  build-and-push-image:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write

    steps:
      - name: Checkout repository
        uses: actions/checkout@v3

      - name: get-npm-version
        id: package-version
        uses: martinbeentjes/npm-get-version-action@main

      - name: Log in to the Container registry
        uses: docker/login-action@v2.0.0
        with:
          registry: ${{ env.REGISTRY }}
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Build and push
        uses: docker/build-push-action@v3.0.0
        with:
          context: .
          push: true
          tags: |
             ghcr.io/sipcapture/pastash:latest
             ghcr.io/sipcapture/pastash:${{ steps.package-version.outputs.current-version}}
