Skip to content

refactor: simplify marketplace-publish workflow to use reusable compo… #2

refactor: simplify marketplace-publish workflow to use reusable compo…

refactor: simplify marketplace-publish workflow to use reusable compo… #2

name: Build and Publish (Reusable)
on:
workflow_call:
inputs:
version:
required: true
type: string
description: "Version to publish"
git_ref:
required: true
type: string
description: "Git reference to build from"
secrets:
POSTHOG_API_KEY:
required: true
VSCE_TOKEN:
required: true
OVSX_TOKEN:
required: true
JETBRAINS_MARKETPLACE_TOKEN:
required: true
GITHUB_TOKEN:

Check failure on line 23 in .github/workflows/_build-and-publish.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/_build-and-publish.yml

Invalid workflow file

secret name `GITHUB_TOKEN` within `workflow_call` can not be used since it would collide with system reserved name
required: true
TURBO_TOKEN:
required: false
TURBO_TEAM:
required: false
env:
NODE_VERSION: 20.19.2
PNPM_VERSION: 10.8.1
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
jobs:
build-and-release:
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
version: ${{ inputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ inputs.git_ref }}
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: ${{ env.PNPM_VERSION }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: "pnpm"
- name: Install dependencies
run: pnpm install
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Create .env file
run: echo "KILOCODE_POSTHOG_API_KEY=${{ secrets.POSTHOG_API_KEY }}" >> .env
- name: Package Extension
run: |
pnpm vsix:production
# Save VSIX contents to a temporary file to avoid broken pipe issues.
unzip -l bin/kilo-code-${{ inputs.version }}.vsix > /tmp/kilo-code-vsix-contents.txt
# Check for required files.
grep -q "extension/package.json" /tmp/kilo-code-vsix-contents.txt || exit 1
grep -q "extension/package.nls.json" /tmp/kilo-code-vsix-contents.txt || exit 1
grep -q "extension/dist/extension.js" /tmp/kilo-code-vsix-contents.txt || exit 1
grep -q "extension/webview-ui/audio/celebration.wav" /tmp/kilo-code-vsix-contents.txt || exit 1
grep -q "extension/webview-ui/build/assets/index.js" /tmp/kilo-code-vsix-contents.txt || exit 1
grep -q "extension/assets/codicons/codicon.ttf" /tmp/kilo-code-vsix-contents.txt || exit 1
grep -q "extension/assets/vscode-material-icons/icons/3d.svg" /tmp/kilo-code-vsix-contents.txt || exit 1
grep -q ".env" /tmp/kilo-code-vsix-contents.txt || exit 1
# Clean up temporary file.
rm /tmp/kilo-code-vsix-contents.txt
- name: Create and Push Git Tag
run: |
# Check if tag already exists remotely
if git ls-remote --tags origin | grep -q "refs/tags/v${{ inputs.version }}$"; then
echo "Tag v${{ inputs.version }} already exists remotely, skipping tag creation"
else
git tag -a "v${{ inputs.version }}" -m "Release v${{ inputs.version }}"
git push origin "v${{ inputs.version }}" --no-verify
echo "Successfully created and pushed git tag v${{ inputs.version }}"
fi
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Check if release already exists
if gh release view "v${{ inputs.version }}" >/dev/null 2>&1; then
echo "Release v${{ inputs.version }} already exists, skipping release creation"
else
# Extract changelog for current version
echo "Extracting changelog for version ${{ inputs.version }}"
# Try with 'v' prefix first (newer format), then without (older format)
changelog_content=$(sed -n "/## \\[v${{ inputs.version }}\\]/,/## \\[/p" CHANGELOG.md | sed '$d')
if [ -z "$changelog_content" ]; then
changelog_content=$(sed -n "/## \\[${{ inputs.version }}\\]/,/## \\[/p" CHANGELOG.md | sed '$d')
fi
# If changelog extraction failed, use a default message
if [ -z "$changelog_content" ]; then
echo "Warning: No changelog section found for version ${{ inputs.version }}"
changelog_content="Release v${{ inputs.version }}"
else
echo "Found changelog section for version ${{ inputs.version }}"
fi
# Create release with changelog content
gh release create "v${{ inputs.version }}" \
--title "Release v${{ inputs.version }}" \
--notes "$changelog_content" \
--target ${{ inputs.git_ref }} \
bin/kilo-code-${{ inputs.version }}.vsix
echo "Successfully created GitHub Release v${{ inputs.version }}"
fi
- name: Upload VSIX artifact
uses: actions/upload-artifact@v4
with:
name: kilo-code-vsix
path: bin/kilo-code-${{ inputs.version }}.vsix
publish-vscode:
needs: build-and-release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ inputs.git_ref }}
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: ${{ env.PNPM_VERSION }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: "pnpm"
- name: Install dependencies
run: pnpm install
- name: Download VSIX artifact
uses: actions/download-artifact@v4
with:
name: kilo-code-vsix
path: bin/
- name: Publish to VS Code Marketplace
continue-on-error: true
env:
VSCE_PAT: ${{ secrets.VSCE_TOKEN }}
OVSX_PAT: ${{ secrets.OVSX_TOKEN }}
run: |
pnpm --filter kilo-code publish:marketplace
echo "Successfully published version ${{ inputs.version }} to VS Code Marketplace"
publish-jetbrains:
needs: build-and-release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ inputs.git_ref }}
submodules: recursive
lfs: true
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: ${{ env.PNPM_VERSION }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: "pnpm"
- uses: actions/setup-java@v4
with:
distribution: "jetbrains"
java-version: "21"
check-latest: false
token: ${{ secrets.GITHUB_TOKEN }}
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
libx11-dev \
libxkbfile-dev \
pkg-config \
build-essential \
python3
- name: Turbo cache setup
uses: actions/cache@v4
with:
path: .turbo
key: ${{ runner.os }}-turbo-${{ github.sha }}
restore-keys: |
${{ runner.os }}-turbo-
- name: Install dependencies
run: pnpm install
- name: Create .env file
run: echo "KILOCODE_POSTHOG_API_KEY=${{ secrets.POSTHOG_API_KEY }}" >> .env
- name: Build JetBrains Plugin
run: pnpm run jetbrains:bundle
shell: bash
- name: Get bundle name
id: get_bundle_name
run: echo "BUNDLE_NAME=$(node jetbrains/plugin/scripts/get_bundle_name.js)" >> $GITHUB_ENV
- name: Attach to GitHub Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release upload "v${{ inputs.version }}" \
"jetbrains/plugin/build/distributions/${{ env.BUNDLE_NAME }}#JetBrains Plugin" \
--clobber
echo "Successfully attached JetBrains plugin to GitHub Release v${{ inputs.version }}"
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.BUNDLE_NAME }}
path: jetbrains/plugin/build/distributions/${{ env.BUNDLE_NAME }}
- name: Publish to JetBrains Marketplace
continue-on-error: true
run: |
curl \
-X POST \
-H "Authorization: Bearer ${{ secrets.JETBRAINS_MARKETPLACE_TOKEN }}" \
-F "file=@jetbrains/plugin/build/distributions/${{ env.BUNDLE_NAME }}" \
-F "pluginId=28350" \
-F "channel=stable" \
-F "isHidden=false" \
https://plugins.jetbrains.com/plugin/uploadPlugin
echo "Successfully published to JetBrains Marketplace"