name: 'NocoDB Release'

on:
  # Triggered manually
  workflow_dispatch:
    inputs:
      tag:
        description: "Target Tag"
        required: true
      prev_tag:
        description: "Previous Tag"
        required: true
jobs:
  # Close all issues with target tags 'Fixed' & 'Resolved'
  close-fixed-issues:
    uses: ./.github/workflows/release-close-issue.yml
    with:
      issue_label: 'Status: Fixed'
      version: ${{ github.event.inputs.tag }}
  close-resolved-issues:
    needs: close-fixed-issues
    uses: ./.github/workflows/release-close-issue.yml
    with:
      issue_label: 'Status: Resolved'
      version: ${{ github.event.inputs.tag }}

  # Build, install, publish frontend and backend to npm
  release-npm:
    needs: close-resolved-issues
    uses: ./.github/workflows/release-npm.yml
    with:
      tag: ${{ github.event.inputs.tag }}
      targetEnv: ${{ github.event.inputs.targetEnv || 'PROD' }}
    secrets:
      NPM_TOKEN: "${{ secrets.NPM_TOKEN }}"

  # Draft Release Note
  release-draft-note:
    needs: release-npm
    uses: ./.github/workflows/release-draft.yml
    with:
      tag: ${{ github.event.inputs.tag }}
      prev_tag: ${{ github.event.inputs.prev_tag }}

  # Build docker image and push to docker hub
  release-docker:
    needs: release-draft-note
    uses: ./.github/workflows/release-docker.yml
    with:
      tag: ${{ github.event.inputs.tag }}
      targetEnv: ${{ github.event.inputs.targetEnv || 'PROD' }}
    secrets:
      DOCKERHUB_USERNAME: "${{ secrets.DOCKERHUB_USERNAME }}"
      DOCKERHUB_TOKEN: "${{ secrets.DOCKERHUB_TOKEN }}"

  # Sync changes to develop
  sync-to-develop:
    needs: release-docker
    uses: ./.github/workflows/sync-to-develop.yml
