---
name: "Build Containers"

on:
  workflow_dispatch:
  push:
    tags:
      - '*'

jobs:
  build-containers:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

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

      - name: docker build
        run: ./var/docker/docker-build.sh

      - name: Get date
        run: |
          echo "DATE=$(date +'%s')" >> "$GITHUB_ENV"

      - name: Print post-build debug info
        run: |
          docker images

      - name: docker tag
        run: |
          docker tag localhost/postiz ghcr.io/gitroomhq/postiz-app:${{ env.DATE }}
          docker push ghcr.io/gitroomhq/postiz-app:${{ env.DATE }}

          docker tag ghcr.io/gitroomhq/postiz-app:${{ env.DATE }} ghcr.io/gitroomhq/postiz-app:latest
          docker push ghcr.io/gitroomhq/postiz-app:latest

          docker tag localhost/postiz-devcontainer ghcr.io/gitroomhq/postiz-devcontainer:${{ env.DATE }}
          docker push ghcr.io/gitroomhq/postiz-devcontainer:${{ env.DATE }}

          docker tag ghcr.io/gitroomhq/postiz-devcontainer:${{ env.DATE }} ghcr.io/gitroomhq/postiz-devcontainer:latest
          docker push ghcr.io/gitroomhq/postiz-devcontainer:latest
