name: catalog-api

on:
  workflow_dispatch:
  push:
    branches:
    - dev

    paths:
    - src/BuildingBlocks/**
    - src/Services/Catalog/**
    - .github/workflows/catalog-api.yml
  
  pull_request:
    branches:
    - dev
    
    paths:
    - src/BuildingBlocks/**
    - src/Services/Catalog/**
    - .github/workflows/catalog-api.yml
env:
  SERVICE: catalog-api
  IMAGE: catalog.api
  DOTNET_VERSION: 7.0.x
  PROJECT_PATH: Services/Catalog/Catalog.API
  TESTS_PATH: Services/Catalog/Catalog.UnitTests

jobs:

  BuildContainersForPR_Linux:
    runs-on: ubuntu-latest
    if: ${{ github.event_name == 'pull_request' }}
    steps:
    - name: Checkout code
      uses: actions/checkout@v2
    - uses: ./.github/workflows/composite/build-test
      with:
        service: ${{ env.SERVICE }}
        registry_endpoint: ${{ secrets.REGISTRY_ENDPOINT }}
        dotnet_version: ${{ env.DOTNET_VERSION }}
        project_path: ${{ env.PROJECT_PATH }}
        tests_path: ${{ env.TESTS_PATH }}

  BuildLinux:
    runs-on: ubuntu-latest
    if: ${{ github.event_name != 'pull_request' }}
    steps:
    - name: Checkout code
      uses: actions/checkout@v2
    - uses: ./.github/workflows/composite/build-push
      with:
        service: ${{ env.SERVICE }}
        registry_host: ${{ secrets.REGISTRY_HOST }}
        registry_endpoint: ${{ secrets.REGISTRY_ENDPOINT }}
        image_name: ${{ env.IMAGE }}
        registry_username: ${{ secrets.USERNAME }}
        registry_password: ${{ secrets.PASSWORD }}