name: 'Release: Standalone Package'

on:
  workflow_dispatch:
    inputs:
      package:
        description: 'Package to release'
        required: true
        type: choice
        options:
          - '@n8n/codemirror-lang'
          - '@n8n/codemirror-lang-html'
          - '@n8n/codemirror-lang-sql'
          - '@n8n/create-node'
          - '@n8n/eslint-plugin-community-nodes'
          - '@n8n/node-cli'
          - '@n8n/scan-community-package'
# All packages listed above require OIDC enabled in NPM. https://docs.npmjs.com/trusted-publishers

concurrency:
  group: release-package-${{ github.event.inputs.package }}
  cancel-in-progress: false

env:
  CACHE_KEY: ${{ github.sha }}-${{ github.event.inputs.package }}-build

jobs:
  publish-to-npm:
    name: Publish to NPM
    runs-on: ubuntu-latest
    timeout-minutes: 15
    environment: npm
    permissions:
      id-token: write
    env:
      NPM_CONFIG_PROVENANCE: true

    steps:
      - name: Check branch
        if: github.ref != 'refs/heads/master'
        run: |
          echo "::error::This workflow can only be run from the master branch"
          exit 1

      - name: Checkout
        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

      - name: Setup and Build
        uses: ./.github/actions/setup-nodejs
        with:
          build-command: 'pnpm turbo build --filter "...${{ github.event.inputs.package }}"'

      - name: Pre publishing changes
        run: |
          node .github/scripts/ensure-provenance-fields.mjs

      - name: Publish package
        env:
          PACKAGE: ${{ github.event.inputs.package }}
        run: pnpm --filter "$PACKAGE" publish --access public --no-git-checks --publish-branch master
