name: Build and Push to GitHub Registry

on:
  push:
    branches:
      - master

jobs:
  build:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2

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

      - name: Get current package version
        uses: martinbeentjes/npm-get-version-action@v1.1.0
        id: package

      - name: Build and Push Docker Image
        uses: docker/build-push-action@v2
        with:
          push: true
          context: .
          tags: |
            ghcr.io/jagandeepbrar/lunasea-notification-service:latest
            ghcr.io/jagandeepbrar/lunasea-notification-service:${{ steps.package.outputs.current-version}}
