From 0dc2b854c9c65d42fa26d17238177dba9b83f3b9 Mon Sep 17 00:00:00 2001 From: syui Date: Sat, 9 Aug 2025 18:13:27 +0900 Subject: [PATCH] fix cargo version gh-actions --- .github/workflows/release.yml | 18 +++++++ .github/workflows/sync-versions.yml | 81 +++++++++++++++++++++++++++++ Cargo.toml | 2 +- oauth/package.json | 2 +- pds/package.json | 2 +- scripts/sync-versions.js | 72 +++++++++++++++++++++++++ scripts/sync-versions.sh | 81 +++++++++++++++++++++++++++++ src/mcp/claude_proxy.rs | 8 +-- 8 files changed, 259 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/sync-versions.yml create mode 100755 scripts/sync-versions.js create mode 100755 scripts/sync-versions.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cf1e832..5c46963 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -48,6 +48,24 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Setup Node.js for version sync + uses: actions/setup-node@v4 + with: + node-version: '18' + + - name: Install jq + run: | + if [[ "${{ matrix.os }}" == "ubuntu-latest" ]]; then + sudo apt-get update && sudo apt-get install -y jq + elif [[ "${{ matrix.os }}" == "macos-latest" ]]; then + brew install jq + fi + + - name: Sync package.json versions + run: | + chmod +x scripts/sync-versions.sh + ./scripts/sync-versions.sh + - name: Setup Rust uses: dtolnay/rust-toolchain@stable with: diff --git a/.github/workflows/sync-versions.yml b/.github/workflows/sync-versions.yml new file mode 100644 index 0000000..9e06344 --- /dev/null +++ b/.github/workflows/sync-versions.yml @@ -0,0 +1,81 @@ +name: Sync Versions + +on: + push: + branches: [ main ] + paths: + - 'Cargo.toml' + pull_request: + branches: [ main ] + paths: + - 'Cargo.toml' + workflow_dispatch: + +permissions: + contents: write + pull-requests: write + +jobs: + sync-versions: + name: Sync package.json versions with Cargo.toml + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' + + - name: Install jq + run: | + sudo apt-get update + sudo apt-get install -y jq + + - name: Make scripts executable + run: chmod +x scripts/sync-versions.sh + + - name: Sync versions + run: ./scripts/sync-versions.sh + + - name: Check for changes + id: changes + run: | + if git diff --quiet; then + echo "changed=false" >> $GITHUB_OUTPUT + echo "No version changes detected" + else + echo "changed=true" >> $GITHUB_OUTPUT + echo "Version changes detected" + git diff --name-only + fi + + - name: Commit and push changes + if: steps.changes.outputs.changed == 'true' && github.event_name == 'push' + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git add oauth/package.json pds/package.json + git commit -m "๐Ÿ”„ Sync package.json versions with Cargo.toml" + git push + + - name: Create Pull Request + if: steps.changes.outputs.changed == 'true' && github.event_name == 'pull_request' + uses: peter-evans/create-pull-request@v5 + with: + token: ${{ secrets.GITHUB_TOKEN }} + commit-message: "๐Ÿ”„ Sync package.json versions with Cargo.toml" + title: "Auto-sync package.json versions" + body: | + This PR automatically syncs package.json versions with the version in Cargo.toml. + + Changes: + - Updated oauth/package.json version + - Updated pds/package.json version + + Generated by GitHub Actions. + branch: sync-versions-${{ github.run_number }} + delete-branch: true \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 01296d2..87b1239 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ailog" -version = "0.3.2" +version = "0.3.3" edition = "2021" authors = ["syui"] description = "A static blog generator with AI features" diff --git a/oauth/package.json b/oauth/package.json index a6507b9..f646aac 100644 --- a/oauth/package.json +++ b/oauth/package.json @@ -1,6 +1,6 @@ { "name": "ailog-oauth", - "version": "0.3.2", + "version": "0.3.4", "type": "module", "scripts": { "dev": "vite", diff --git a/pds/package.json b/pds/package.json index 199adbc..750a10d 100644 --- a/pds/package.json +++ b/pds/package.json @@ -1,6 +1,6 @@ { "name": "pds-browser", - "version": "0.3.2", + "version": "0.3.4", "description": "AT Protocol browser for ai.log", "main": "index.js", "type": "module", diff --git a/scripts/sync-versions.js b/scripts/sync-versions.js new file mode 100755 index 0000000..1902121 --- /dev/null +++ b/scripts/sync-versions.js @@ -0,0 +1,72 @@ +#!/usr/bin/env node + +/** + * Version synchronization script for ailog + * Syncs version from Cargo.toml to all package.json files + */ + +const fs = require('fs'); +const path = require('path'); + +// Read version from Cargo.toml +function getCargoVersion() { + const cargoPath = path.join(__dirname, '../Cargo.toml'); + const cargoContent = fs.readFileSync(cargoPath, 'utf8'); + const versionMatch = cargoContent.match(/^version\s*=\s*"([^"]+)"/m); + + if (!versionMatch) { + throw new Error('Could not find version in Cargo.toml'); + } + + return versionMatch[1]; +} + +// Update package.json version +function updatePackageVersion(packagePath, version) { + if (!fs.existsSync(packagePath)) { + console.warn(`Package.json not found: ${packagePath}`); + return false; + } + + const packageData = JSON.parse(fs.readFileSync(packagePath, 'utf8')); + const oldVersion = packageData.version; + packageData.version = version; + + fs.writeFileSync(packagePath, JSON.stringify(packageData, null, 2) + '\n'); + console.log(`Updated ${path.relative(process.cwd(), packagePath)}: ${oldVersion} โ†’ ${version}`); + return true; +} + +// Main function +function main() { + try { + const version = getCargoVersion(); + console.log(`Cargo.toml version: ${version}`); + + // List of package.json files to update + const packageFiles = [ + path.join(__dirname, '../oauth/package.json'), + path.join(__dirname, '../pds/package.json') + ]; + + let updatedCount = 0; + for (const packageFile of packageFiles) { + if (updatePackageVersion(packageFile, version)) { + updatedCount++; + } + } + + console.log(`โœ… Successfully updated ${updatedCount} package.json files`); + + } catch (error) { + console.error('โŒ Error syncing versions:', error.message); + process.exit(1); + } +} + +// Run if called directly +if (require.main === module) { + main(); +} + +module.exports = { getCargoVersion, updatePackageVersion }; \ No newline at end of file diff --git a/scripts/sync-versions.sh b/scripts/sync-versions.sh new file mode 100755 index 0000000..b98536e --- /dev/null +++ b/scripts/sync-versions.sh @@ -0,0 +1,81 @@ +#!/bin/bash +# Version synchronization script for ailog +# Syncs version from Cargo.toml to all package.json files + +set -e + +# Get the directory of this script +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" + +# Function to extract version from Cargo.toml +get_cargo_version() { + grep '^version = ' "$PROJECT_ROOT/Cargo.toml" | cut -d'"' -f2 +} + +# Function to update package.json version using jq +update_package_version() { + local package_file="$1" + local version="$2" + + if [[ ! -f "$package_file" ]]; then + echo "โš ๏ธ Package.json not found: $package_file" + return 1 + fi + + # Check if jq is available + if ! command -v jq &> /dev/null; then + echo "โŒ jq is required but not installed. Please install jq first." + return 1 + fi + + # Get current version using jq + local old_version=$(jq -r '.version' "$package_file") + + # Update version using jq (with proper formatting) + local temp_file=$(mktemp) + jq --arg version "$version" '.version = $version' "$package_file" > "$temp_file" + + # Replace original file if jq succeeded + if [[ $? -eq 0 ]]; then + mv "$temp_file" "$package_file" + echo "โœ… Updated $(basename "$package_file"): $old_version โ†’ $version" + return 0 + else + rm -f "$temp_file" + echo "โŒ Failed to update $package_file" + return 1 + fi +} + +# Main execution +main() { + local version + version=$(get_cargo_version) + + if [[ -z "$version" ]]; then + echo "โŒ Could not find version in Cargo.toml" + exit 1 + fi + + echo "๐Ÿ“ฆ Cargo.toml version: $version" + echo "๐Ÿ”„ Syncing versions..." + + # List of package.json files to update + local packages=( + "$PROJECT_ROOT/oauth/package.json" + "$PROJECT_ROOT/pds/package.json" + ) + + local updated_count=0 + for package in "${packages[@]}"; do + if update_package_version "$package" "$version"; then + ((updated_count++)) + fi + done + + echo "โœ… Successfully synced $updated_count package.json files" +} + +# Run main function +main "$@" \ No newline at end of file diff --git a/src/mcp/claude_proxy.rs b/src/mcp/claude_proxy.rs index 30d6081..30d7a44 100644 --- a/src/mcp/claude_proxy.rs +++ b/src/mcp/claude_proxy.rs @@ -70,10 +70,10 @@ async fn communicate_with_claude_mcp( // Claude Code MCPใƒ—ใƒญใ‚ปใ‚นใ‚’่ตทๅ‹• // Use the full path to avoid shell function and don't use --continue let claude_executable = if claude_code_path == "claude" { - // Use $HOME environment variable instead of hardcoded path - match std::env::var("HOME") { - Ok(home) => format!("{}/.claude/local/claude", home), - Err(_) => "/Users/syui/.claude/local/claude".to_string(), // fallback + // Use dirs crate for cross-platform home directory detection + match dirs::home_dir() { + Some(home) => home.join(".claude/local/claude").to_string_lossy().to_string(), + None => "/Users/syui/.claude/local/claude".to_string(), // fallback } } else { claude_code_path.to_string()