name: Manual Deploy
on:
  workflow_dispatch:
    inputs:
      package:
        description: 'Package to deploy'
        required: true
        type: choice
        default: 'docs'
        options:
          - upload-client
          - access-client
          - docs
      environment:
        description: 'Environment to deploy'
        required: true
        type: choice
        default: 'staging'
        options:
          - production
          - staging
          - dev
jobs:
  deploy-access-client:
    runs-on: ubuntu-latest
    if: github.event.inputs.package == 'access-client'
    steps:
      - uses: actions/checkout@v3
      - uses: pnpm/action-setup@v2.2.3
        with:
          version: 8
      - uses: actions/setup-node@v3
        with:
          node-version: 18
          registry-url: 'https://registry.npmjs.org'
          cache: 'pnpm'
      - run: pnpm install
      - run: pnpm -r --filter @web3-storage/access build
      - run: pnpm -r --filter @web3-storage/access run rc || true # this fails because npm does not support workspace protocol so we force it to exit 0
      - uses: stefanzweifel/git-auto-commit-action@v4
        with:
          commit_message: 'chore(access): Bump access sdk pre release version'
      - run: pnpm -r --filter @web3-storage/access publish --tag next --access public
        env:
          NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
  deploy-upload-client:
    runs-on: ubuntu-latest
    if: github.event.inputs.package == 'upload-client'
    steps:
      - uses: actions/checkout@v3
      - uses: pnpm/action-setup@v2.2.3
        with:
          version: 8
      - uses: actions/setup-node@v3
        with:
          node-version: 18
          registry-url: 'https://registry.npmjs.org'
          cache: 'pnpm'
      - run: pnpm install
      - run: pnpm -r --filter @web3-storage/upload-client build
      - run: pnpm -r --filter @web3-storage/upload-client run rc || true # this fails because npm does not support workspace protocol so we force it to exit 0
      - uses: stefanzweifel/git-auto-commit-action@v4
        with:
          commit_message: 'chore(client): Bump client pre release version'
      - run: pnpm -r --filter @web3-storage/upload-client publish --tag next --access public
        env:
          NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
  deploy-docs:
    if: github.event.inputs.package == 'docs'
    uses: './.github/workflows/reusable-deploy-docs.yml'
