name: Deploy develop

on:
  pull_request:

jobs:
  deploy:
    name: Deploy
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - uses: actions/checkout@v2
        with:
          repository: itering/actions
          path: .github/actions
          persist-credentials: false
          ssh-key: "${{ secrets.ITERING_ACTIONS_DEPLOY_KEY }}"

      - run: rm -rf vercel.json && mv vercel-local.json vercel.json

      - name: Cache multiple paths
        uses: actions/cache@v3
        with:
          path: '**/node_modules'
          key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}

      - uses: ./.github/actions/smart-vercel
        name: Deploy to Vercel
        id: smart-vercel
        with:
          vercel_token: ${{ secrets.VERCEL_TOKEN }}
          vercel_group: itering
          preview_output: true
          project_name: subscan-pro-lowcode
          dist_path: build
          script_build: yarn build:local
          enable_cache: true
          cache_type: yarn

      - uses: marocchino/sticky-pull-request-comment@v2
        with:
          append: true
          message: ${{ steps.smart-vercel.outputs.PREVIEW_OUTPUT }}
