name: "[NOT CALLABLE] Deploy To CurseForge"
on:
  workflow_call:
    inputs:
      tag:
        description: The Release Tag.
        required: true
        type: string
      release_type:
        description: The Release Type. This is the formatted version.
        required: true
        type: string

jobs:
  deployCF:
    name: Deploy to CurseForge (${{ inputs.tag }})
    runs-on: ubuntu-latest
    env:
      GITHUB_TAG: ${{ github.event.inputs.tag }}

    steps:
      - name: Checkout Tag
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Restore NPM Cached Files
        uses: actions/cache@v4
        id: npm-cache
        with:
          path: |
            ~/.npm
            ./tools/node_modules
          key: ${{ runner.os }}-npm-${{ hashFiles('./tools/package-lock.json') }}
          restore-keys: ${{ runner.os }}-npm-

      - name: Setup NodeJS v20
        uses: actions/setup-node@v4
        with:
          node-version: 20
          check-latest: true

      - name: Setup NPM Packages
        if: steps.npm-cache.outputs.cache-hit != 'true'
        working-directory: ./tools
        run: npm ci

      - name: Check Environmental Variables
        working-directory: ./tools
        run: npm run gulp check
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          CURSEFORGE_PROJECT_ID: ${{ secrets.CURSEFORGE_PROJECT_ID }}
          CURSEFORGE_API_TOKEN: ${{ secrets.CURSEFORGE_API_TOKEN }}
          CFCORE_API_TOKEN: ${{ secrets.CFCORE_API_TOKEN }}

      - name: Download Built Artifacts
        uses: actions/download-artifact@v4
        with:
          name: Built Pack
          path: ./build/

      - name: Deploy to CurseForge
        env:
          CURSEFORGE_PROJECT_ID: ${{ secrets.CURSEFORGE_PROJECT_ID }}
          CURSEFORGE_API_TOKEN: ${{ secrets.CURSEFORGE_API_TOKEN }}
          RELEASE_TYPE: ${{ inputs.release_type }}
        working-directory: ./tools
        run: npm run gulp deployCurseForge
