name: vscode

on:
  workflow_call:

jobs:
  publish-vscode:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: editors/vscode
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - uses: ./.github/actions/setup-pixi
        with:
          environments: node

      - name: Publish and Package to Marketplace
        env:
          VSCE_PAT: ${{ secrets.VSCE_PAT }}
        run: |
          FLAG="${{ contains(github.ref_name, '-') && '--pre-release' || '' }}"
          pixi run build-vscode $FLAG

          if [[ "${{ github.ref }}" == "refs/tags/"* ]]; then
            pixi run publish-vscode -p "$VSCE_PAT" $FLAG
          fi

      - name: Upload .vsix to Release
        uses: softprops/action-gh-release@v2
        if: startsWith(github.ref, 'refs/tags/v')
        with:
          files: "editors/vscode/*.vsix"
          tag_name: ${{ github.ref }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
