name: Publish libs to npm

on:
  workflow_dispatch:
    inputs:
      project:
        description: 'Monorepo project to publish'
        required: true
        type: choice
        options:
          - announcements
          - ui-toolkit
          - react-helpers
          - tailwindcss-config
          - types
          - utils
          - i18n
          - wallet

jobs:
  publish:
    name: Build & Publish - Tag
    runs-on: ubuntu-22.04
    permissions:
      contents: 'read'
      actions: 'read'
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Setup node
        uses: actions/setup-node@v3
        with:
          node-version-file: '.nvmrc'
          # https://stackoverflow.com/questions/61010294/how-to-cache-yarn-packages-in-github-actions
          cache: yarn

      - name: Install root dependencies
        run: yarn install --frozen-lockfile

      - name: Build project
        run: yarn nx build ${{inputs.project}}

      - name: Publish project to @vegaprotocol
        uses: JS-DevTools/npm-publish@v1
        with:
          token: ${{ secrets.NPM_TOKEN }}
          package: dist/libs/${{inputs.project}}/package.json
          access: public
