Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 38 additions & 6 deletions .github/workflows/publish-cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ name: Publish ctxce CLI to npm

on:
workflow_dispatch:
inputs:
version:
description: "Version to publish (ensure package.json is updated)"
required: false
push:
tags:
- "ctxce-cli-v*"
branches:
- test
paths:
- "ctx-mcp-bridge/package.json"

jobs:
publish:
Expand All @@ -18,17 +16,51 @@ jobs:
id-token: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Use Node.js 20
uses: actions/setup-node@v4
with:
node-version: "20"
registry-url: "https://registry.npmjs.org"

- name: Check bridge version change
id: version_check
shell: bash
run: |
set -euo pipefail

PKG_PATH="ctx-mcp-bridge/package.json"
CURRENT_VERSION="$(node -p "require('./' + process.env.PKG_PATH).version")"

PREVIOUS_VERSION=""
if git cat-file -e "${{ github.event.before }}:${PKG_PATH}" 2>/dev/null; then
PREVIOUS_VERSION="$(git show "${{ github.event.before }}:${PKG_PATH}" | node -e 'let d="";process.stdin.on("data",c=>d+=c);process.stdin.on("end",()=>{try{console.log(JSON.parse(d).version||"")}catch(e){console.log("")}})')"
fi

ALREADY_PUBLISHED=false
if npm view "@context-engine-bridge/context-engine-mcp-bridge@${CURRENT_VERSION}" version >/dev/null 2>&1; then
ALREADY_PUBLISHED=true
fi

echo "current_version=${CURRENT_VERSION}" >> "$GITHUB_OUTPUT"
echo "previous_version=${PREVIOUS_VERSION}" >> "$GITHUB_OUTPUT"
echo "already_published=${ALREADY_PUBLISHED}" >> "$GITHUB_OUTPUT"

if [[ -n "$CURRENT_VERSION" && "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ]]; then
echo "changed=true" >> "$GITHUB_OUTPUT"
else
echo "changed=false" >> "$GITHUB_OUTPUT"
fi
env:
PKG_PATH: "ctx-mcp-bridge/package.json"

- name: Install dependencies
working-directory: ctx-mcp-bridge
run: npm install

- name: Publish to npm
if: steps.version_check.outputs.changed == 'true' && steps.version_check.outputs.already_published != 'true'
working-directory: ctx-mcp-bridge
run: npm publish --access public --provenance
68 changes: 68 additions & 0 deletions .github/workflows/publish-vscode-extension.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Publish VS Code Extension

on:
workflow_dispatch:
push:
branches:
- test
paths:
- "vscode-extension/context-engine-uploader/package.json"

concurrency:
group: vscode-marketplace-publish
cancel-in-progress: false

jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Use Node.js 20
uses: actions/setup-node@v4
with:
node-version: "20"

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Check extension version change
id: version_check
shell: bash
run: |
set -euo pipefail

FILE="vscode-extension/context-engine-uploader/package.json"
CURRENT_VERSION="$(node -p "require('./' + process.env.FILE).version" )"

PREVIOUS_VERSION=""
if git cat-file -e "${{ github.event.before }}:${FILE}" 2>/dev/null; then
PREVIOUS_VERSION="$(git show "${{ github.event.before }}:${FILE}" | node -e 'let d="";process.stdin.on("data",c=>d+=c);process.stdin.on("end",()=>{try{console.log(JSON.parse(d).version||"")}catch(e){console.log("")}})')"
fi

echo "current_version=${CURRENT_VERSION}" >> "$GITHUB_OUTPUT"
echo "previous_version=${PREVIOUS_VERSION}" >> "$GITHUB_OUTPUT"

if [[ -n "$CURRENT_VERSION" && "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ]]; then
echo "changed=true" >> "$GITHUB_OUTPUT"
else
echo "changed=false" >> "$GITHUB_OUTPUT"
fi
env:
FILE: "vscode-extension/context-engine-uploader/package.json"

- name: Publish to VS Code Marketplace
if: steps.version_check.outputs.changed == 'true'
shell: bash
env:
VSCE_PAT: ${{ secrets.VSCE_PAT }}
run: |
chmod +x vscode-extension/build/publish-vscode-extension.sh
vscode-extension/build/publish-vscode-extension.sh --bundle-deps
45 changes: 45 additions & 0 deletions vscode-extension/build/publish-vscode-extension.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env bash
set -euo pipefail

SCRIPT_DIR="$(cd -- "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BUILD_SCRIPT="$SCRIPT_DIR/build.sh"
OUT_DIR="$SCRIPT_DIR/../out"
BUNDLE_DEPS="${1:-}"

if [[ ! -f "$BUILD_SCRIPT" ]]; then
echo "Build script not found: $BUILD_SCRIPT" >&2
exit 1
fi

if [[ -z "${VSCE_PAT:-}" ]]; then
echo "VSCE_PAT is required" >&2
exit 1
fi

export VSCE_STORE="${VSCE_STORE:-file}"

"$BUILD_SCRIPT" "$BUNDLE_DEPS"

VSIX_PATH=""
if compgen -G "$OUT_DIR/*.vsix" >/dev/null; then
VSIX_PATH="$(ls -t "$OUT_DIR"/*.vsix | head -n 1)"
fi

if [[ -z "$VSIX_PATH" || ! -f "$VSIX_PATH" ]]; then
echo "No .vsix found in $OUT_DIR" >&2
exit 1
fi

set +e
PUBLISH_OUTPUT="$(npx --yes @vscode/vsce publish --packagePath "$VSIX_PATH" 2>&1)"
PUBLISH_EXIT_CODE="$?"
set -e

if [[ "$PUBLISH_EXIT_CODE" -ne 0 ]]; then
if echo "$PUBLISH_OUTPUT" | grep -qi "already exists"; then
exit 0
fi

echo "$PUBLISH_OUTPUT" >&2
exit "$PUBLISH_EXIT_CODE"
fi
Loading