From 9c7556bca0e3b003a46d573be6a2846dd8bedbe7 Mon Sep 17 00:00:00 2001 From: syui Date: Sat, 9 Aug 2025 18:30:10 +0900 Subject: [PATCH] fix --- .github/workflows/pre-release.yml | 61 ------------ .github/workflows/release.yml | 22 ----- .github/workflows/sync-versions.yml | 81 ---------------- scpt/run.zsh | 40 ++++++++ scripts/sync-versions.js | 72 -------------- scripts/sync-versions.sh | 144 ---------------------------- 6 files changed, 40 insertions(+), 380 deletions(-) delete mode 100644 .github/workflows/pre-release.yml delete mode 100644 .github/workflows/sync-versions.yml delete mode 100755 scripts/sync-versions.js delete mode 100755 scripts/sync-versions.sh diff --git a/.github/workflows/pre-release.yml b/.github/workflows/pre-release.yml deleted file mode 100644 index 7ec1caa..0000000 --- a/.github/workflows/pre-release.yml +++ /dev/null @@ -1,61 +0,0 @@ -name: Pre-release Test - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -jobs: - test-build: - name: Test Build and Version Sync - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - - 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: Test version sync - run: | - chmod +x scripts/sync-versions.sh - ./scripts/sync-versions.sh - - - name: Setup Rust - uses: dtolnay/rust-toolchain@stable - - - name: Cache cargo - uses: actions/cache@v4 - with: - path: | - ~/.cargo/registry - ~/.cargo/git - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - - name: Test build - run: cargo build --release - - - name: Test version consistency - run: | - CARGO_VERSION=$(grep '^version = ' Cargo.toml | cut -d'"' -f2) - OAUTH_VERSION=$(jq -r '.version' oauth/package.json) - PDS_VERSION=$(jq -r '.version' pds/package.json) - - echo "Cargo.toml: $CARGO_VERSION" - echo "oauth/package.json: $OAUTH_VERSION" - echo "pds/package.json: $PDS_VERSION" - - if [[ "$CARGO_VERSION" != "$OAUTH_VERSION" ]] || [[ "$CARGO_VERSION" != "$PDS_VERSION" ]]; then - echo "❌ Version mismatch detected!" - exit 1 - else - echo "✅ All versions are synchronized" - fi \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6f2610c..0ebe469 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -48,28 +48,6 @@ 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 - continue-on-error: true - run: | - echo "🔄 Trying Node.js version sync first..." - node scripts/sync-versions.js || { - echo "🔄 Node.js version failed, trying shell script..." - chmod +x scripts/sync-versions.sh - ./scripts/sync-versions.sh || echo "âš ī¸ Both version sync methods failed, but continuing with build..." - } - name: Setup Rust uses: dtolnay/rust-toolchain@stable diff --git a/.github/workflows/sync-versions.yml b/.github/workflows/sync-versions.yml deleted file mode 100644 index 9e06344..0000000 --- a/.github/workflows/sync-versions.yml +++ /dev/null @@ -1,81 +0,0 @@ -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/scpt/run.zsh b/scpt/run.zsh index 78f3193..99c76aa 100755 --- a/scpt/run.zsh +++ b/scpt/run.zsh @@ -20,9 +20,49 @@ function _env() { function _deploy_ailog() { } +function _sync_versions() { + # Get version from Cargo.toml + local version=$(grep '^version = ' "$d/Cargo.toml" | cut -d'"' -f2) + if [[ -z "$version" ]]; then + echo "âš ī¸ Could not find version in Cargo.toml" + return 1 + fi + + echo "â„šī¸ Syncing versions to $version" + + # Update oauth/package.json + if [[ -f "$d/oauth/package.json" ]]; then + if command -v jq >/dev/null 2>&1; then + local temp_file=$(mktemp) + jq --arg version "$version" '.version = $version' "$d/oauth/package.json" > "$temp_file" + mv "$temp_file" "$d/oauth/package.json" + echo "✅ Updated oauth/package.json to $version" + else + sed -i.bak "s/\"version\":[[:space:]]*\"[^\"]*\"/\"version\": \"$version\"/" "$d/oauth/package.json" + rm -f "$d/oauth/package.json.bak" + echo "✅ Updated oauth/package.json to $version (sed)" + fi + fi + + # Update pds/package.json + if [[ -f "$d/pds/package.json" ]]; then + if command -v jq >/dev/null 2>&1; then + local temp_file=$(mktemp) + jq --arg version "$version" '.version = $version' "$d/pds/package.json" > "$temp_file" + mv "$temp_file" "$d/pds/package.json" + echo "✅ Updated pds/package.json to $version" + else + sed -i.bak "s/\"version\":[[:space:]]*\"[^\"]*\"/\"version\": \"$version\"/" "$d/pds/package.json" + rm -f "$d/pds/package.json.bak" + echo "✅ Updated pds/package.json to $version (sed)" + fi + fi +} + function _server() { lsof -ti:$port | xargs kill -9 2>/dev/null || true cd $d/my-blog + _sync_versions cargo build --release cp -rf $ailog $CARGO_HOME/bin/ $ailog build diff --git a/scripts/sync-versions.js b/scripts/sync-versions.js deleted file mode 100755 index 1902121..0000000 --- a/scripts/sync-versions.js +++ /dev/null @@ -1,72 +0,0 @@ -#!/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 deleted file mode 100755 index 26cc064..0000000 --- a/scripts/sync-versions.sh +++ /dev/null @@ -1,144 +0,0 @@ -#!/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 -} - -# Fallback function for when jq is not available -update_package_version_fallback() { - local package_file="$1" - local version="$2" - - # Get current version using grep/sed - local old_version=$(grep '"version"' "$package_file" | sed 's/.*"version":\s*"\([^"]*\)".*/\1/') - - # Skip update if version is already correct - if [[ "$old_version" == "$version" ]]; then - echo "✅ $(basename "$package_file"): Already up to date ($version)" - return 0 - fi - - # Update version using sed - if sed -i.bak "s/\"version\":\s*\"[^\"]*\"/\"version\": \"$version\"/" "$package_file"; then - rm -f "$package_file.bak" - echo "✅ Updated $(basename "$package_file"): $old_version → $version (sed)" - return 0 - else - rm -f "$package_file.bak" - echo "❌ Failed to update $package_file with sed" - return 1 - fi -} - -# 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, fallback to sed if not - if ! command -v jq &> /dev/null; then - echo "âš ī¸ jq not found, using sed fallback for $package_file" - return update_package_version_fallback "$package_file" "$version" - fi - - # Get current version using jq - echo "🔍 Extracting version from $package_file using jq..." - local old_version=$(jq -r '.version' "$package_file" 2>&1) - local jq_exit_code=$? - - if [[ $jq_exit_code -ne 0 ]]; then - echo "❌ jq failed to read $package_file: $old_version" - echo "🔍 Trying fallback method..." - return update_package_version_fallback "$package_file" "$version" - fi - - echo "🔍 Current version: '$old_version'" - - # Skip update if version is already correct - if [[ "$old_version" == "$version" ]]; then - echo "✅ $(basename "$package_file"): Already up to date ($version)" - return 0 - fi - - # Update version using jq (with proper formatting) - local temp_file=$(mktemp) - if jq --arg version "$version" '.version = $version' "$package_file" > "$temp_file" 2>/dev/null; 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 with jq" - 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 "🔍 Project root: $PROJECT_ROOT" - 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 - local failed_count=0 - - for package in "${packages[@]}"; do - echo "🔍 Processing: $package" - echo "🔍 File exists: $(test -f "$package" && echo "YES" || echo "NO")" - if [[ -f "$package" ]]; then - echo "🔍 File size: $(wc -c < "$package") bytes" - echo "🔍 File content preview:" - head -5 "$package" | sed 's/^/ /' - fi - - if update_package_version "$package" "$version"; then - ((updated_count++)) - else - ((failed_count++)) - echo "âš ī¸ Failed to update: $package" - fi - echo "---" - done - - echo "📊 Summary: $updated_count updated, $failed_count failed" - - if [[ $failed_count -gt 0 ]]; then - echo "âš ī¸ $failed_count files failed to update, but continuing..." - echo "📋 This might be due to environment differences or file permissions" - # Don't exit with error code to allow CI to continue - # exit 1 - else - echo "✅ Successfully synced all package.json files" - fi -} - -# Run main function -main "$@" \ No newline at end of file