version: 2.1

# Required for dynamic configuration
setup: true

# Orbs
orbs:
  path-filtering: circleci/path-filtering@0.1.0
  continuation: circleci/continuation@0.2.0

# All input parameters to pass to build config
parameters:
  run-docs-only:
    type: boolean
    default: false

  upload-to-storage:
    type: string
    default: '1'

  run-build-linux:
    type: boolean
    default: false

  run-build-mac:
    type: boolean
    default: false

  run-linux-publish:
    type: boolean
    default: false

  linux-publish-arch-limit:
    type: enum
    default: all
    enum: ["all", "arm", "arm64", "x64", "ia32"]

  run-macos-publish:
    type: boolean
    default: false

  macos-publish-arch-limit:
    type: enum
    default: all
    enum: ["all", "osx-x64", "osx-arm64", "mas-x64", "mas-arm64"]

jobs:
  generate-config:
    docker:
      - image: cimg/node:16.14
    steps:
      - checkout
      - path-filtering/set-parameters:
          base-revision: main
          mapping: |
            ^((?!docs/).)*$ run-build-mac true
            ^((?!docs/).)*$ run-build-linux true
            docs/.* run-docs-only true
            ^((?!docs/).)*$ run-docs-only false
      - run:
          command: |
            cd .circleci/config
            yarn
            export CIRCLECI_BINARY="$HOME/circleci"
            curl -fLSs https://raw.githubusercontent.com/CircleCI-Public/circleci-cli/main/install.sh | DESTDIR=$CIRCLECI_BINARY bash
            node build.js
          name: Pack config.yml
      - run:
          name: Set params
          command: node .circleci/config/params.js
      - continuation/continue:
          configuration_path: .circleci/config-staging/built.yml
          parameters: /tmp/pipeline-parameters.json

# Initial setup workflow
workflows:
  setup:
    jobs:
      - generate-config