version: 2.1
orbs:
  win: circleci/windows@5.1.0
jobs:
  partner-win-build:
    executor:
      name: win/default
    parameters:
      tenantID:
        type: string
        default: $AZURE_TENANT_ID
      clientID:
        type: string
        default: $AZURE_CLIENT_ID
      clientSecret:
        type: string
        default: $AZURE_CLIENT_SECRET
    steps:
      - checkout
      - run:
          name: Set up Node.js
          command: |
            nvm install 22
            nvm use 22
      - run:
          name: Install Build Dependencies
          command: |
            choco install python visualstudio2022-workload-vctools -y
            python -m pip install --upgrade pip setuptools wheel

      # look for existing cache and restore if found
      - restore_cache:
          key: bsp-win-deps-{{ checksum "package-lock.json" }}
      # install dependencies
      - run:
          name: install dependencies
          command: npm install
      - run:
          name: Install NPM Packages
          command: npm install
      - save_cache:
          key: bsp-win-deps-{{ checksum "package-lock.json" }}
          paths:
            - node_modules
      - run:
          name: Build Electron App for Windows
          environment:
            AZURE_TENANT_ID: << parameters.tenantID >>
            AZURE_CLIENT_ID: << parameters.clientID >>
            AZURE_CLIENT_SECRET: << parameters.clientSecret >>
          command: |
            $env:AZURE_TENANT_ID = << parameters.tenantID >>
            $env:AZURE_CLIENT_ID = << parameters.clientID >>
            $env:AZURE_CLIENT_SECRET = << parameters.clientSecret >>
            npm run build:win
      # - store_artifacts:
      #     path: .\dist

workflows:
  deploy_and_build:
    jobs:
      - partner-win-build:
          filters:
            branches:
              only: main
