name: Deploy staging local

on:
  workflow_dispatch:

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
          alias_domain: subscan-widget-local

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

      - name: Slack Notification
        if: failure()
        uses: rtCamp/action-slack-notify@v2
        env:
          SLACK_CHANNEL: ${{ secrets.SLACK_CHANNEL_ID }}
          SLACK_COLOR: ${{ job.status }}
          SLACK_ICON: https://avatars.githubusercontent.com/u/14985020?s=48&v=4
          SLACK_MESSAGE: "${{ steps.smart-vercel.outputs.PREVIEW_LINK }}"
          SLACK_TITLE: Preview
          SLACK_USERNAME: Vercel
          SLACK_WEBHOOK: ${{ secrets.SLACK_INCOMING_WEBHOOK_URL }}
