Publish VS Code Extension #69
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish VS Code Extension | |
| on: | |
| # Triggered when TypeScript SDK workflow completes on a tag | |
| workflow_run: | |
| workflows: ["TypeScript SDK"] | |
| types: [completed] | |
| workflow_dispatch: | |
| inputs: | |
| dry-run: | |
| description: 'Dry run (do not publish)' | |
| required: false | |
| default: 'false' | |
| type: boolean | |
| version: | |
| description: 'SDK version to use (e.g., 0.1.17). If empty, extracts from triggering workflow tag.' | |
| required: false | |
| type: string | |
| permissions: | |
| contents: read | |
| jobs: | |
| # Build and test job | |
| build-and-test: | |
| runs-on: ubuntu-latest | |
| # Only run if: | |
| # - manually triggered (workflow_dispatch) | |
| # - TypeScript SDK workflow succeeded (workflow_run) | |
| if: | | |
| github.event_name == 'workflow_dispatch' || | |
| (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success') | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| submodules: recursive | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'npm' | |
| cache-dependency-path: vscode/package-lock.json | |
| - name: Get SDK version | |
| id: sdk_version | |
| run: | | |
| if [ -n "${{ github.event.inputs.version }}" ]; then | |
| VERSION="${{ github.event.inputs.version }}" | |
| elif [ "${{ github.event_name }}" == "workflow_run" ]; then | |
| # Extract version from the triggering workflow's tag | |
| # The head_branch contains the tag name for tag-triggered workflows | |
| TAG="${{ github.event.workflow_run.head_branch }}" | |
| # Only use the tag if it looks like a version tag (starts with 'v') | |
| if [[ "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+ ]]; then | |
| VERSION=${TAG#v} | |
| else | |
| # Non-tag push (e.g., master branch) - use latest from npm | |
| VERSION=$(npm view @json-structure/sdk version) | |
| fi | |
| else | |
| # For workflow_dispatch without version, use latest from npm | |
| VERSION=$(npm view @json-structure/sdk version) | |
| fi | |
| echo "VERSION=$VERSION" >> $GITHUB_OUTPUT | |
| echo "Using SDK version: $VERSION" | |
| - name: Update SDK dependency to npm package | |
| working-directory: vscode | |
| run: | | |
| VERSION="${{ steps.sdk_version.outputs.VERSION }}" | |
| echo "Updating @json-structure/sdk dependency to version $VERSION" | |
| # Update package.json to use npm package instead of local file | |
| npm pkg set "dependencies.@json-structure/sdk=$VERSION" | |
| cat package.json | grep -A2 '"dependencies"' | |
| - name: Install VS Code Extension dependencies | |
| working-directory: vscode | |
| run: npm install | |
| - name: Run VS Code Extension tests | |
| working-directory: vscode | |
| run: xvfb-run -a npm test | |
| - name: Update extension version to match SDK | |
| working-directory: vscode | |
| run: | | |
| VERSION="${{ steps.sdk_version.outputs.VERSION }}" | |
| # Use npm pkg set to avoid triggering version hooks that auto-generate dev versions | |
| npm pkg set "version=$VERSION" | |
| echo "Set extension version to: $VERSION" | |
| - name: Package extension | |
| working-directory: vscode | |
| run: npm run package | |
| env: | |
| SKIP_VERSION_UPDATE: '1' | |
| - name: Get version | |
| id: version | |
| working-directory: vscode | |
| run: | | |
| VERSION=$(node -p "require('./package.json').version") | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "Extension version: $VERSION" | |
| - name: Upload VSIX artifact | |
| uses: actions/upload-artifact@v6 | |
| with: | |
| name: json-structure-${{ steps.version.outputs.version }} | |
| path: vscode/json-structure-*.vsix | |
| retention-days: 30 | |
| outputs: | |
| version: ${{ steps.version.outputs.version }} | |
| sdk_version: ${{ steps.sdk_version.outputs.VERSION }} | |
| # Publish job - runs after successful build for workflow_run or manual dispatch | |
| publish: | |
| runs-on: ubuntu-latest | |
| needs: [build-and-test] | |
| # Publish on workflow_run (TypeScript SDK completed) or manual dispatch (unless dry-run) | |
| if: | | |
| needs.build-and-test.result == 'success' && | |
| (github.event_name == 'workflow_run' || | |
| (github.event_name == 'workflow_dispatch' && github.event.inputs.dry-run != 'true')) | |
| environment: vscode-marketplace | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| submodules: recursive | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'npm' | |
| cache-dependency-path: vscode/package-lock.json | |
| - name: Update SDK dependency to npm package | |
| working-directory: vscode | |
| run: | | |
| VERSION="${{ needs.build-and-test.outputs.sdk_version }}" | |
| echo "Updating @json-structure/sdk dependency to version $VERSION" | |
| npm pkg set "dependencies.@json-structure/sdk=$VERSION" | |
| - name: Install VS Code Extension dependencies | |
| working-directory: vscode | |
| run: npm install | |
| - name: Update extension version to match SDK | |
| working-directory: vscode | |
| run: | | |
| VERSION="${{ needs.build-and-test.outputs.sdk_version }}" | |
| # Use npm pkg set to avoid triggering version hooks that auto-generate dev versions | |
| npm pkg set "version=$VERSION" | |
| echo "Set extension version to: $VERSION" | |
| - name: Package extension | |
| working-directory: vscode | |
| run: npm run package | |
| env: | |
| SKIP_VERSION_UPDATE: '1' | |
| - name: Publish to VS Code Marketplace | |
| if: ${{ github.event.inputs.dry-run != 'true' }} | |
| working-directory: vscode | |
| run: | | |
| npx @vscode/vsce publish --packagePath json-structure-${{ needs.build-and-test.outputs.version }}.vsix | |
| env: | |
| VSCE_PAT: ${{ secrets.VSCE_PAT }} | |
| - name: Publish to Open VSX Registry | |
| if: ${{ github.event.inputs.dry-run != 'true' }} | |
| working-directory: vscode | |
| run: | | |
| if [ -n "$OVSX_PAT" ]; then | |
| npx ovsx publish json-structure-${{ needs.build-and-test.outputs.version }}.vsix -p "$OVSX_PAT" | |
| else | |
| echo "OVSX_PAT not set, skipping Open VSX publish" | |
| fi | |
| env: | |
| OVSX_PAT: ${{ secrets.OVSX_PAT }} | |
| continue-on-error: true |