name: Build <%= @app_name %> starter PROD

on:
  workflow_dispatch:
  push:
    tags:
      - "v[0-9]+.[0-9]+.[0-9]+"

jobs:
  build:
    name: Build and test
    runs-on: ubuntu-latest
    permissions:
      packages: write
      contents: write
    concurrency:
      group: ci-${{ github.ref }}
      cancel-in-progress: true

    steps:
      - uses: actions/checkout@v3

      - name: Create Release
        id: create_release
        uses: actions/create-release@latest
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
        with:
          tag_name: ${{ github.ref }}
          release_name: Release ${{ github.ref }}
          body: Create release ${{ github.ref }}
          draft: false
          prerelease: false

      - name: Extract metadata (tags, labels) for Docker
        id: meta
        uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
        with:
          images: ghcr.io/${{ github.repository }}

      - name: Build & push Docker image 🐳
        uses: mr-smithers-excellent/docker-build-push@v5
        with:
          image: <%= String.downcase(@app_name) %>
          tags: ${{ github.event.release.tag_name }}
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
          buildArgs: MIX_ENV=prod
        env:
          MIX_ENV: prod
