name: Release on Dockerhub

on:
  push:
    tags:
      - "v*"

jobs:
  release-image-on-dockerhub:
    name: Release on Dockerhub
    runs-on: ubuntu-latest
    env:
      TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
      TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
      DATABASE_URL: "postgresql://postgres:postgres@localhost:5432/formbricks?schema=public"
    steps:
      - name: Checkout Repo
        uses: actions/checkout@v2

      - name: Log in to Docker Hub
        uses: docker/login-action@v2
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v2

      - name: Get Release Tag
        id: extract_release_tag
        run: |
          TAG=${{ github.ref }}
          TAG=${TAG#refs/tags/v}
          echo "RELEASE_TAG=$TAG" >> $GITHUB_ENV

      - name: Build and push Docker image
        uses: docker/build-push-action@v4
        with:
          context: .
          file: ./apps/web/Dockerfile
          push: true
          tags: |
            ${{ secrets.DOCKER_USERNAME }}/formbricks:${{ env.RELEASE_TAG }}
            ${{ secrets.DOCKER_USERNAME }}/formbricks:latest
