name: Publish VS Code Extension

on:
  push:
    tags:
      - 'vscode-v*'

jobs:
  publish:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: plugin/vscode
    steps:
      - uses: actions/checkout@v6

      - uses: actions/setup-node@v4
        with:
          node-version: 22

      - run: npm install

      - run: npm run compile

      - name: Package extension
        run: npx vsce package --no-dependencies

      - name: Publish to Marketplace
        run: npx vsce publish --no-dependencies
        env:
          VSCE_PAT: ${{ secrets.VSCE_PAT }}

      - name: Upload .vsix artifact
        uses: actions/upload-artifact@v4
        with:
          name: rgx-vscode
          path: plugin/vscode/*.vsix
