Publish Extension #13
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 Extension | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - 'package.json' | |
| workflow_dispatch: | |
| inputs: | |
| force_publish: | |
| description: 'Force publish even if version unchanged' | |
| required: false | |
| default: false | |
| type: boolean | |
| jobs: | |
| detect-version: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version: ${{ steps.version.outputs.version }} | |
| changed: ${{ steps.changed.outputs.changed }} | |
| should_publish: ${{ steps.should_publish.outputs.should_publish }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 2 | |
| - name: Get current version | |
| id: version | |
| run: | | |
| VERSION=$(node -p "require('./package.json').version") | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "Current version: $VERSION" | |
| - name: Check if version changed | |
| id: changed | |
| run: | | |
| if [ "${{ github.event_name }}" == "workflow_dispatch" ] && [ "${{ github.event.inputs.force_publish }}" == "true" ]; then | |
| echo "changed=true" >> $GITHUB_OUTPUT | |
| echo "Force publish requested" | |
| elif [ "${{ github.event_name }}" == "push" ] && [ -f package.json ]; then | |
| # Check if package.json was modified in this commit | |
| if git diff HEAD~1 HEAD --name-only | grep -q "package.json"; then | |
| # Get old version from previous commit | |
| OLD_VERSION=$(git show HEAD~1:package.json 2>/dev/null | grep -o '"version": "[^"]*"' | cut -d'"' -f4 || echo "") | |
| # Get new version from current commit | |
| NEW_VERSION=$(node -p "require('./package.json').version") | |
| if [ -z "$OLD_VERSION" ]; then | |
| echo "changed=false" >> $GITHUB_OUTPUT | |
| echo "Could not determine old version (possibly first commit)" | |
| elif [ "$OLD_VERSION" != "$NEW_VERSION" ]; then | |
| echo "changed=true" >> $GITHUB_OUTPUT | |
| echo "Version changed from $OLD_VERSION to $NEW_VERSION" | |
| else | |
| echo "changed=false" >> $GITHUB_OUTPUT | |
| echo "Version unchanged: $NEW_VERSION" | |
| fi | |
| else | |
| echo "changed=false" >> $GITHUB_OUTPUT | |
| echo "package.json not modified in this commit" | |
| fi | |
| else | |
| echo "changed=false" >> $GITHUB_OUTPUT | |
| echo "Not a push event or package.json not found" | |
| fi | |
| - name: Determine if should publish | |
| id: should_publish | |
| run: | | |
| if [ "${{ steps.changed.outputs.changed }}" == "true" ]; then | |
| echo "should_publish=true" >> $GITHUB_OUTPUT | |
| echo "Will publish extension" | |
| else | |
| echo "should_publish=false" >> $GITHUB_OUTPUT | |
| echo "Skipping publish - version unchanged" | |
| fi | |
| build: | |
| needs: detect-version | |
| if: needs.detect-version.outputs.should_publish == 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Install Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20.x' | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: | | |
| npm ci | |
| # Ensure postinstall runs (installs campaign-webview dependencies) | |
| npm run postinstall || true | |
| # Verify rimraf is available | |
| ./node_modules/.bin/rimraf --version || npx rimraf --version || echo "rimraf available via npx" | |
| - name: Install vsce | |
| run: npm install -g @vscode/vsce | |
| - name: Install ovsx | |
| run: npm install -g ovsx | |
| - name: Build extension | |
| run: | | |
| # Ensure postinstall script has run | |
| npm run postinstall || true | |
| # Add node_modules/.bin to PATH for rimraf | |
| export PATH="$PWD/node_modules/.bin:$PATH" | |
| # Build the extension | |
| npm run esbuild | |
| echo "Build completed successfully" | |
| - name: Package extension | |
| run: | | |
| # Add node_modules/.bin to PATH for rimraf (used in prepublish script) | |
| export PATH="$PWD/node_modules/.bin:$PATH" | |
| vsce package --allow-package-secrets sendgrid --allow-package-env-file --out sp-isc-devtools-${{ needs.detect-version.outputs.version }}.vsix | |
| echo "VSIX package created" | |
| - name: Upload VSIX artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: extension-vsix | |
| path: sp-isc-devtools-${{ needs.detect-version.outputs.version }}.vsix | |
| retention-days: 30 | |
| - name: Display VSIX info | |
| run: | | |
| echo "VSIX file created: sp-isc-devtools-${{ needs.detect-version.outputs.version }}.vsix" | |
| ls -lh sp-isc-devtools-*.vsix | |
| publish-vscode: | |
| needs: [detect-version, build] | |
| if: needs.detect-version.outputs.should_publish == 'true' | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: vscode-marketplace | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Install Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20.x' | |
| - name: Install dependencies | |
| run: | | |
| npm ci | |
| npm run postinstall || true | |
| - name: Install vsce | |
| run: npm install -g @vscode/vsce | |
| - name: Publish to VS Code Marketplace | |
| run: | | |
| if [ -z "${{ secrets.VSCE_PAT }}" ]; then | |
| echo "VSCE_PAT secret is not set. Skipping VS Code Marketplace publish." | |
| exit 0 | |
| fi | |
| # Add node_modules/.bin to PATH for rimraf (used in prepublish script) | |
| export PATH="$GITHUB_WORKSPACE/node_modules/.bin:$PATH" | |
| # Publish from source (vsce will run prepublish which needs rimraf) | |
| vsce publish -p "${{ secrets.VSCE_PAT }}" --allow-package-secrets sendgrid | |
| continue-on-error: true | |
| - name: Download VSIX artifact for release | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: extension-vsix | |
| path: . | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: v${{ needs.detect-version.outputs.version }} | |
| name: Release v${{ needs.detect-version.outputs.version }} | |
| files: sp-isc-devtools-${{ needs.detect-version.outputs.version }}.vsix | |
| generate_release_notes: true | |
| draft: false | |
| prerelease: false | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| publish-openvsx: | |
| needs: [detect-version, build] | |
| if: needs.detect-version.outputs.should_publish == 'true' | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: openvsx-marketplace | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Install Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20.x' | |
| - name: Install ovsx | |
| run: npm install -g ovsx | |
| - name: Download VSIX artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: extension-vsix | |
| path: . | |
| - name: Publish to Open VSX Marketplace | |
| run: | | |
| if [ -z "${{ secrets.OVSX_SECRET }}" ]; then | |
| echo "OVSX_SECRET secret is not set. Skipping Open VSX Marketplace publish." | |
| exit 0 | |
| fi | |
| ovsx publish sp-isc-devtools-${{ needs.detect-version.outputs.version }}.vsix -p "${{ secrets.OVSX_SECRET }}" | |
| continue-on-error: true | |
| notify: | |
| needs: [detect-version, publish-vscode, publish-openvsx] | |
| if: always() | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Publish status | |
| run: | | |
| if [ "${{ needs.detect-version.outputs.should_publish }}" == "true" ]; then | |
| if [ "${{ needs.publish-vscode.result }}" == "success" ] && [ "${{ needs.publish-openvsx.result }}" == "success" ]; then | |
| echo "✅ Successfully published v${{ needs.detect-version.outputs.version }} to both marketplaces" | |
| elif [ "${{ needs.publish-vscode.result }}" == "success" ]; then | |
| echo "⚠️ Published to VS Code Marketplace but Open VSX failed" | |
| elif [ "${{ needs.publish-openvsx.result }}" == "success" ]; then | |
| echo "⚠️ Published to Open VSX but VS Code Marketplace failed" | |
| else | |
| echo "❌ Publishing failed for both marketplaces" | |
| fi | |
| else | |
| echo "ℹ️ Version unchanged, skipping publish" | |
| fi |