diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d9dda3b..64a4714 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -6,8 +6,18 @@ on: - 'v*' workflow_dispatch: inputs: - skip_release: - description: 'Build artifacts only (no GitHub release)' + bump: + description: 'Version bump type' + required: false + default: 'none' + type: choice + options: + - none + - patch + - minor + - major + dry_run: + description: 'Dry run (build only, no release)' required: false default: true type: boolean @@ -15,230 +25,220 @@ on: permissions: contents: write -env: - # Grammar repos and their source directories - GRAMMARS: | - go:tree-sitter/tree-sitter-go:master:src - python:tree-sitter/tree-sitter-python:master:src - javascript:tree-sitter/tree-sitter-javascript:master:src - typescript:tree-sitter/tree-sitter-typescript:master:typescript/src - rust:tree-sitter/tree-sitter-rust:master:src - ruby:tree-sitter/tree-sitter-ruby:master:src - c:tree-sitter/tree-sitter-c:master:src - cpp:tree-sitter/tree-sitter-cpp:master:src - java:tree-sitter/tree-sitter-java:master:src - swift:tree-sitter/tree-sitter-swift:master:src - bash:tree-sitter/tree-sitter-bash:master:src - kotlin:fwcd/tree-sitter-kotlin:main:src - c_sharp:tree-sitter/tree-sitter-c-sharp:master:src - php:tree-sitter/tree-sitter-php:master:php/src - dart:UserNobody14/tree-sitter-dart:master:src - r:r-lib/tree-sitter-r:main:src - jobs: - build-macos: - strategy: - matrix: - include: - - runner: macos-13 - goarch: amd64 - name: codemap-darwin-amd64 - - runner: macos-14 - goarch: arm64 - name: codemap-darwin-arm64 - runs-on: ${{ matrix.runner }} + # ============================================================ + # Version Bump: Create tag based on bump type (manual trigger) + # ============================================================ + bump-version: + if: github.event_name == 'workflow_dispatch' && inputs.bump != 'none' + runs-on: ubuntu-latest + outputs: + new_tag: ${{ steps.bump.outputs.new_tag }} steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 - - name: Set up Go - uses: actions/setup-go@v5 + - name: Get latest tag and bump version + id: bump + env: + BUMP_TYPE: ${{ inputs.bump }} + run: | + # Get latest tag (or default to v0.0.0) + LATEST=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") + echo "Latest tag: $LATEST" + + # Parse version: v2.1.3 -> major=2, minor=1, patch=3 + VERSION="${LATEST#v}" + MAJOR="${VERSION%%.*}" + REST="${VERSION#*.}" + MINOR="${REST%%.*}" + PATCH="${REST#*.}" + + # Handle 2-part versions like v2.0 -> v2.0.0 + if [ "$PATCH" = "$MINOR" ]; then + PATCH="0" + fi + + case "$BUMP_TYPE" in + major) + # 2.1.3 -> 3.0.0 + NEW_TAG="v$((MAJOR + 1)).0.0" + ;; + minor) + # 2.1.3 -> 2.2.0 + NEW_TAG="v${MAJOR}.$((MINOR + 1)).0" + ;; + patch) + # 2.1.3 -> 2.1.4 + NEW_TAG="v${MAJOR}.${MINOR}.$((PATCH + 1))" + ;; + esac + + echo "Bumping $LATEST -> $NEW_TAG ($BUMP_TYPE)" + echo "new_tag=$NEW_TAG" >> "$GITHUB_OUTPUT" + + - name: Create and push tag + env: + NEW_TAG: ${{ steps.bump.outputs.new_tag }} + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git tag "$NEW_TAG" + git push origin "$NEW_TAG" + echo "✓ Created and pushed $NEW_TAG" + + # ============================================================ + # Build: One job per platform (grammars + Go + archive) + # Skipped when bump != none (tag push triggers fresh run) + # ============================================================ + build-darwin-amd64: + if: ${{ !(github.event_name == 'workflow_dispatch' && inputs.bump != 'none') }} + runs-on: macos-13 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 with: go-version: '1.21' + - name: Build grammars + run: | + chmod +x scripts/build-grammars.sh + ./scripts/build-grammars.sh darwin + - name: Build Go binary env: - CGO_ENABLED: 1 - run: go build -o codemap . + CGO_ENABLED: "1" + run: go build -trimpath -ldflags="-s -w" -o codemap . - - name: Build grammars + - name: Create archive run: | - set -e - mkdir -p grammars - - echo "$GRAMMARS" | while IFS=: read -r lang repo branch src_dir; do - [ -z "$lang" ] && continue - echo "Building $lang from $repo..." - - # Extract to temp dir to avoid conflicts - rm -rf _grammar_build && mkdir _grammar_build && cd _grammar_build - curl -sL "https://github.com/$repo/archive/refs/heads/$branch.tar.gz" | tar xz - extracted_dir=$(ls -d */ | head -1) - src_path="${extracted_dir}${src_dir}" - - if [ ! -d "$src_path" ]; then - echo " ✗ Source not found: $src_path" - exit 1 - fi - - sources="$src_path/parser.c" - use_cxx=false - if [ -f "$src_path/scanner.c" ]; then - sources="$sources $src_path/scanner.c" - elif [ -f "$src_path/scanner.cc" ]; then - use_cxx=true - clang++ -c -fPIC -I"$src_path" "$src_path/scanner.cc" -o scanner.o - sources="$sources scanner.o" - fi - - # Use clang++ for linking when C++ scanner is present - if $use_cxx; then - clang++ -shared -fPIC -I"$src_path" $sources -o ../grammars/libtree-sitter-$lang.dylib - else - clang -shared -fPIC -I"$src_path" $sources -o ../grammars/libtree-sitter-$lang.dylib - fi - cd .. && rm -rf _grammar_build - - echo " ✓ Built $lang" - done - - echo "" - echo "Built grammars:" - ls -la grammars/ - - - name: Create release archive + mkdir -p dist/codemap-darwin-amd64 + cp codemap dist/codemap-darwin-amd64/ + cp -r grammars dist/codemap-darwin-amd64/ + cp -r scanner/queries dist/codemap-darwin-amd64/ + cp README.md dist/codemap-darwin-amd64/ 2>/dev/null || true + cd dist && tar -czvf codemap-darwin-amd64.tar.gz codemap-darwin-amd64 + + - uses: actions/upload-artifact@v4 + with: + name: codemap-darwin-amd64 + path: dist/codemap-darwin-amd64.tar.gz + + build-darwin-arm64: + if: ${{ !(github.event_name == 'workflow_dispatch' && inputs.bump != 'none') }} + runs-on: macos-14 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: '1.21' + + - name: Build grammars run: | - mkdir -p release/${{ matrix.name }} - cp codemap release/${{ matrix.name }}/ - cp -r grammars release/${{ matrix.name }}/ - cp -r scanner/queries release/${{ matrix.name }}/ - cat > release/${{ matrix.name }}/README.txt << 'EOF' - codemap - Generate a brain map of your codebase for LLM context - - Usage: - codemap . # Project structure - codemap --deps # Dependency flow - codemap --diff # Changed files vs main - - Keep grammars/ next to codemap, or set CODEMAP_GRAMMAR_DIR. - More info: https://github.com/JordanCoin/codemap - EOF - cd release && tar -czvf ../${{ matrix.name }}.tar.gz ${{ matrix.name }} + chmod +x scripts/build-grammars.sh + ./scripts/build-grammars.sh darwin + + - name: Build Go binary + env: + CGO_ENABLED: "1" + run: go build -trimpath -ldflags="-s -w" -o codemap . - - name: Upload artifact - uses: actions/upload-artifact@v4 + - name: Create archive + run: | + mkdir -p dist/codemap-darwin-arm64 + cp codemap dist/codemap-darwin-arm64/ + cp -r grammars dist/codemap-darwin-arm64/ + cp -r scanner/queries dist/codemap-darwin-arm64/ + cp README.md dist/codemap-darwin-arm64/ 2>/dev/null || true + cd dist && tar -czvf codemap-darwin-arm64.tar.gz codemap-darwin-arm64 + + - uses: actions/upload-artifact@v4 with: - name: ${{ matrix.name }} - path: ${{ matrix.name }}.tar.gz + name: codemap-darwin-arm64 + path: dist/codemap-darwin-arm64.tar.gz - build-linux: + build-linux-amd64: + if: ${{ !(github.event_name == 'workflow_dispatch' && inputs.bump != 'none') }} runs-on: ubuntu-latest - strategy: - matrix: - include: - - goarch: amd64 - name: codemap-linux-amd64 - - goarch: arm64 - cc: aarch64-linux-gnu-gcc - name: codemap-linux-arm64 steps: - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: '1.21' + + - name: Build grammars + run: | + chmod +x scripts/build-grammars.sh + ./scripts/build-grammars.sh linux - - name: Set up Go - uses: actions/setup-go@v5 + - name: Build Go binary + env: + CGO_ENABLED: "1" + run: go build -trimpath -ldflags="-s -w" -o codemap . + + - name: Create archive + run: | + mkdir -p dist/codemap-linux-amd64 + cp codemap dist/codemap-linux-amd64/ + cp -r grammars dist/codemap-linux-amd64/ + cp -r scanner/queries dist/codemap-linux-amd64/ + cp README.md dist/codemap-linux-amd64/ 2>/dev/null || true + cd dist && tar -czvf codemap-linux-amd64.tar.gz codemap-linux-amd64 + + - uses: actions/upload-artifact@v4 + with: + name: codemap-linux-amd64 + path: dist/codemap-linux-amd64.tar.gz + + build-linux-arm64: + if: ${{ !(github.event_name == 'workflow_dispatch' && inputs.bump != 'none') }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 with: go-version: '1.21' - name: Install cross-compiler - if: matrix.goarch == 'arm64' - run: sudo apt-get update && sudo apt-get install -y gcc-aarch64-linux-gnu + run: sudo apt-get update && sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu + + - name: Build grammars + env: + CC: aarch64-linux-gnu-gcc + CXX: aarch64-linux-gnu-g++ + run: | + chmod +x scripts/build-grammars.sh + ./scripts/build-grammars.sh linux - name: Build Go binary env: - CGO_ENABLED: 1 + CGO_ENABLED: "1" GOOS: linux - GOARCH: ${{ matrix.goarch }} - CC: ${{ matrix.cc || 'gcc' }} - run: go build -o codemap . + GOARCH: arm64 + CC: aarch64-linux-gnu-gcc + run: go build -trimpath -ldflags="-s -w" -o codemap . - - name: Build grammars - run: | - set -e - mkdir -p grammars - CC="${{ matrix.cc || 'gcc' }}" - CXX="${CC/gcc/g++}" - - echo "$GRAMMARS" | while IFS=: read -r lang repo branch src_dir; do - [ -z "$lang" ] && continue - echo "Building $lang from $repo..." - - # Extract to temp dir to avoid conflicts - rm -rf _grammar_build && mkdir _grammar_build && cd _grammar_build - curl -sL "https://github.com/$repo/archive/refs/heads/$branch.tar.gz" | tar xz - extracted_dir=$(ls -d */ | head -1) - src_path="${extracted_dir}${src_dir}" - - if [ ! -d "$src_path" ]; then - echo " ✗ Source not found: $src_path" - exit 1 - fi - - sources="$src_path/parser.c" - use_cxx=false - if [ -f "$src_path/scanner.c" ]; then - sources="$sources $src_path/scanner.c" - elif [ -f "$src_path/scanner.cc" ]; then - use_cxx=true - $CXX -c -fPIC -I"$src_path" "$src_path/scanner.cc" -o scanner.o - sources="$sources scanner.o" - fi - - # Use g++ for linking when C++ scanner is present (links libstdc++) - if $use_cxx; then - $CXX -shared -fPIC -I"$src_path" $sources -o ../grammars/libtree-sitter-$lang.so - else - $CC -shared -fPIC -I"$src_path" $sources -o ../grammars/libtree-sitter-$lang.so - fi - cd .. && rm -rf _grammar_build - - echo " ✓ Built $lang" - done - - echo "" - echo "Built grammars:" - ls -la grammars/ - - - name: Create release archive + - name: Create archive run: | - mkdir -p release/${{ matrix.name }} - cp codemap release/${{ matrix.name }}/ - cp -r grammars release/${{ matrix.name }}/ - cp -r scanner/queries release/${{ matrix.name }}/ - cat > release/${{ matrix.name }}/README.txt << 'EOF' - codemap - Generate a brain map of your codebase for LLM context - - Usage: - codemap . # Project structure - codemap --deps # Dependency flow - codemap --diff # Changed files vs main - - Keep grammars/ next to codemap, or set CODEMAP_GRAMMAR_DIR. - More info: https://github.com/JordanCoin/codemap - EOF - cd release && tar -czvf ../${{ matrix.name }}.tar.gz ${{ matrix.name }} - - - name: Upload artifact - uses: actions/upload-artifact@v4 + mkdir -p dist/codemap-linux-arm64 + cp codemap dist/codemap-linux-arm64/ + cp -r grammars dist/codemap-linux-arm64/ + cp -r scanner/queries dist/codemap-linux-arm64/ + cp README.md dist/codemap-linux-arm64/ 2>/dev/null || true + cd dist && tar -czvf codemap-linux-arm64.tar.gz codemap-linux-arm64 + + - uses: actions/upload-artifact@v4 with: - name: ${{ matrix.name }} - path: ${{ matrix.name }}.tar.gz + name: codemap-linux-arm64 + path: dist/codemap-linux-arm64.tar.gz - build-windows: + build-windows-amd64: + if: ${{ !(github.event_name == 'workflow_dispatch' && inputs.bump != 'none') }} runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - - name: Set up Go - uses: actions/setup-go@v5 + - uses: actions/setup-go@v5 with: go-version: '1.21' @@ -247,103 +247,47 @@ jobs: with: version: 0.11.0 - - name: Create zig wrapper + - name: Build grammars run: | - mkdir -p "$HOME/zigcc" - cat > "$HOME/zigcc/zcc" << 'SCRIPT' - #!/bin/sh - zig cc -target x86_64-windows-gnu "$@" - SCRIPT - cat > "$HOME/zigcc/zxx" << 'SCRIPT' - #!/bin/sh - zig c++ -target x86_64-windows-gnu "$@" - SCRIPT - chmod +x "$HOME/zigcc/zcc" "$HOME/zigcc/zxx" + chmod +x scripts/build-grammars.sh + CC="zig cc -target x86_64-windows-gnu" \ + CXX="zig c++ -target x86_64-windows-gnu" \ + ./scripts/build-grammars.sh windows - name: Build Go binary - env: - CGO_ENABLED: 1 - GOOS: windows - GOARCH: amd64 - CC: /home/runner/zigcc/zcc - CXX: /home/runner/zigcc/zxx - run: go build -ldflags="-s -w" -o codemap.exe . - - - name: Build grammars - run: | - set -e - mkdir -p grammars - - echo "$GRAMMARS" | while IFS=: read -r lang repo branch src_dir; do - [ -z "$lang" ] && continue - echo "Building $lang from $repo..." - - # Extract to temp dir to avoid conflicts - rm -rf _grammar_build && mkdir _grammar_build && cd _grammar_build - curl -sL "https://github.com/$repo/archive/refs/heads/$branch.tar.gz" | tar xz - extracted_dir=$(ls -d */ | head -1) - src_path="${extracted_dir}${src_dir}" - - if [ ! -d "$src_path" ]; then - echo " ✗ Source not found: $src_path" - exit 1 - fi - - sources="$src_path/parser.c" - use_cxx=false - if [ -f "$src_path/scanner.c" ]; then - sources="$sources $src_path/scanner.c" - elif [ -f "$src_path/scanner.cc" ]; then - use_cxx=true - zig c++ -target x86_64-windows-gnu -c -fPIC -I"$src_path" "$src_path/scanner.cc" -o scanner.o - sources="$sources scanner.o" - fi - - # Use zig c++ for linking when C++ scanner is present (links libstdc++) - if $use_cxx; then - zig c++ -target x86_64-windows-gnu -shared -fPIC -I"$src_path" $sources -o ../grammars/libtree-sitter-$lang.dll - else - zig cc -target x86_64-windows-gnu -shared -fPIC -I"$src_path" $sources -o ../grammars/libtree-sitter-$lang.dll - fi - cd .. && rm -rf _grammar_build - - echo " ✓ Built $lang" - done - - echo "" - echo "Built grammars:" - ls -la grammars/ - - - name: Create release archive run: | - mkdir -p release/codemap-windows-amd64 - cp codemap.exe release/codemap-windows-amd64/ - cp -r grammars release/codemap-windows-amd64/ - cp -r scanner/queries release/codemap-windows-amd64/ - cat > release/codemap-windows-amd64/README.txt << 'EOF' - codemap - Generate a brain map of your codebase for LLM context - - Usage: - codemap . # Project structure - codemap --deps # Dependency flow - codemap --diff # Changed files vs main - - Keep grammars/ next to codemap.exe, or set CODEMAP_GRAMMAR_DIR. - More info: https://github.com/JordanCoin/codemap - EOF - cd release && zip -r ../codemap-windows-amd64.zip codemap-windows-amd64 + mkdir -p "$HOME/zigcc" + echo '#!/bin/sh' > "$HOME/zigcc/zcc" + echo 'zig cc -target x86_64-windows-gnu "$@"' >> "$HOME/zigcc/zcc" + chmod +x "$HOME/zigcc/zcc" + + CGO_ENABLED=1 GOOS=windows GOARCH=amd64 CC="$HOME/zigcc/zcc" \ + go build -trimpath -ldflags="-s -w" -o codemap.exe . - - name: Upload artifact - uses: actions/upload-artifact@v4 + - name: Create archive + run: | + mkdir -p dist/codemap-windows-amd64 + cp codemap.exe dist/codemap-windows-amd64/ + cp -r grammars dist/codemap-windows-amd64/ + cp -r scanner/queries dist/codemap-windows-amd64/ + cp README.md dist/codemap-windows-amd64/ 2>/dev/null || true + cd dist && zip -r codemap-windows-amd64.zip codemap-windows-amd64 + + - uses: actions/upload-artifact@v4 with: name: codemap-windows-amd64 - path: codemap-windows-amd64.zip + path: dist/codemap-windows-amd64.zip - release: - needs: [build-macos, build-linux, build-windows] + # ============================================================ + # Publish: Create GitHub Release + Update Package Managers + # ============================================================ + publish: + needs: [build-darwin-amd64, build-darwin-arm64, build-linux-amd64, build-linux-arm64, build-windows-amd64] runs-on: ubuntu-latest - if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.skip_release == false) + if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.dry_run == false) steps: + - uses: actions/checkout@v4 + - name: Download all artifacts uses: actions/download-artifact@v4 with: @@ -352,53 +296,139 @@ jobs: - name: List artifacts run: find artifacts -type f - - name: Create Release + - name: Create GitHub Release uses: softprops/action-gh-release@v1 with: files: | - artifacts/**/*.zip artifacts/**/*.tar.gz + artifacts/**/*.zip generate_release_notes: true - update-scoop: - needs: [release] + update-homebrew: + needs: [publish] runs-on: ubuntu-latest - if: github.event_name == 'push' # Only on tag push, not manual workflow steps: - name: Wait for release assets - run: sleep 30 # Give GitHub time to process release assets + run: sleep 30 - - name: Get version from tag - id: version - run: echo "version=${GITHUB_REF_NAME#v}" >> $GITHUB_OUTPUT + - name: Get version and hashes + id: info + env: + TAG_NAME: ${{ github.ref_name }} + run: | + VERSION="${TAG_NAME#v}" + echo "version=$VERSION" >> "$GITHUB_OUTPUT" - - name: Download Windows zip and get hash - id: hash + curl -sL "https://github.com/JordanCoin/codemap/releases/download/${TAG_NAME}/codemap-darwin-arm64.tar.gz" -o darwin-arm64.tar.gz + SHA_ARM64=$(shasum -a 256 darwin-arm64.tar.gz | cut -d' ' -f1) + echo "sha_arm64=$SHA_ARM64" >> "$GITHUB_OUTPUT" + + curl -sL "https://github.com/JordanCoin/codemap/releases/download/${TAG_NAME}/codemap-darwin-amd64.tar.gz" -o darwin-amd64.tar.gz + SHA_AMD64=$(shasum -a 256 darwin-amd64.tar.gz | cut -d' ' -f1) + echo "sha_amd64=$SHA_AMD64" >> "$GITHUB_OUTPUT" + + - name: Update Homebrew tap + uses: actions/checkout@v4 + with: + repository: JordanCoin/homebrew-tap + token: ${{ secrets.HOMEBREW_TAP_TOKEN }} + path: homebrew-tap + + - name: Update formula + env: + VERSION: ${{ steps.info.outputs.version }} + SHA_ARM64: ${{ steps.info.outputs.sha_arm64 }} + SHA_AMD64: ${{ steps.info.outputs.sha_amd64 }} + TAG_NAME: ${{ github.ref_name }} + run: | + cd homebrew-tap + cat > codemap.rb << EOF + class Codemap < Formula + desc "Generate a brain map of your codebase for LLM context" + homepage "https://github.com/JordanCoin/codemap" + version "${VERSION}" + license "MIT" + + on_macos do + if Hardware::CPU.arm? + url "https://github.com/JordanCoin/codemap/releases/download/${TAG_NAME}/codemap-darwin-arm64.tar.gz" + sha256 "${SHA_ARM64}" + else + url "https://github.com/JordanCoin/codemap/releases/download/${TAG_NAME}/codemap-darwin-amd64.tar.gz" + sha256 "${SHA_AMD64}" + end + end + + def install + bin.install "codemap" + (libexec/"grammars").install Dir["grammars/*"] if Dir.exist?("grammars") + (libexec/"queries").install Dir["queries/*"] if Dir.exist?("queries") + end + + def caveats + <<~EOS + Tree-sitter grammars installed to: + #{libexec}/grammars + + For --deps mode, codemap will find them automatically. + EOS + end + + test do + system "#{bin}/codemap", "--help" + end + end + EOF + + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add codemap.rb + git commit -m "Update codemap to ${VERSION}" + git push + + update-scoop: + needs: [publish] + runs-on: ubuntu-latest + steps: + - name: Wait for release assets + run: sleep 30 + + - name: Get version and hash + id: info + env: + TAG_NAME: ${{ github.ref_name }} run: | - curl -L -o codemap.zip "https://github.com/JordanCoin/codemap/releases/download/${GITHUB_REF_NAME}/codemap-windows-amd64.zip" + VERSION="${TAG_NAME#v}" + echo "version=$VERSION" >> "$GITHUB_OUTPUT" + + curl -sL "https://github.com/JordanCoin/codemap/releases/download/${TAG_NAME}/codemap-windows-amd64.zip" -o codemap.zip SHA256=$(sha256sum codemap.zip | cut -d' ' -f1) - echo "sha256=$SHA256" >> $GITHUB_OUTPUT + echo "sha256=$SHA256" >> "$GITHUB_OUTPUT" - - name: Update Scoop manifest + - name: Update Scoop bucket uses: actions/checkout@v4 with: repository: JordanCoin/scoop-codemap token: ${{ secrets.SCOOP_TOKEN }} path: scoop-bucket - - name: Update manifest and push + - name: Update manifest + env: + VERSION: ${{ steps.info.outputs.version }} + SHA256: ${{ steps.info.outputs.sha256 }} + TAG_NAME: ${{ github.ref_name }} run: | cd scoop-bucket cat > codemap.json << EOF { - "version": "${{ steps.version.outputs.version }}", + "version": "${VERSION}", "description": "Generate a brain map of your codebase for LLM context", "homepage": "https://github.com/JordanCoin/codemap", "license": "MIT", "architecture": { "64bit": { - "url": "https://github.com/JordanCoin/codemap/releases/download/${GITHUB_REF_NAME}/codemap-windows-amd64.zip", - "hash": "${{ steps.hash.outputs.sha256 }}" + "url": "https://github.com/JordanCoin/codemap/releases/download/${TAG_NAME}/codemap-windows-amd64.zip", + "hash": "${SHA256}" } }, "bin": "codemap-windows-amd64\\\\codemap.exe", @@ -412,8 +442,9 @@ jobs: } } EOF + git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" git add codemap.json - git commit -m "Update codemap to ${{ steps.version.outputs.version }}" + git commit -m "Update codemap to ${VERSION}" git push diff --git a/release.sh b/release.sh deleted file mode 100755 index 23ad88a..0000000 --- a/release.sh +++ /dev/null @@ -1,112 +0,0 @@ -#!/bin/bash - -# release.sh - Automate codemap release process - -set -e - -# Configuration -TAP_DIR="../homebrew-tap" -FORMULA_FILE="codemap.rb" -REPO_URL="https://github.com/JordanCoin/codemap" - -# 1. Check for uncommitted changes -if ! git diff-index --quiet HEAD --; then - echo "❌ Error: You have uncommitted changes." - echo "Please commit or stash them before releasing." - exit 1 -fi - -# 2. Get current version from git tags -# If no tags exist, default to v1.0 (since user just released 1.0 manually) -CURRENT_VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "v1.0") -# Remove 'v' prefix -CURRENT_VERSION=${CURRENT_VERSION#v} - -echo "Current version: $CURRENT_VERSION" - -# 3. Calculate next version -IFS='.' read -r -a parts <<< "$CURRENT_VERSION" -MAJOR=${parts[0]} -MINOR=${parts[1]} - -# User requested logic: 1.9 -> 2.0 -if [ "$MINOR" -ge 9 ]; then - NEXT_MAJOR=$((MAJOR + 1)) - NEXT_MINOR=0 -else - NEXT_MAJOR=$MAJOR - NEXT_MINOR=$((MINOR + 1)) -fi - -NEXT_VERSION="$NEXT_MAJOR.$NEXT_MINOR" -TAG_NAME="v$NEXT_VERSION" - -echo "Preparing to release: $TAG_NAME" -read -p "Press enter to continue or Ctrl+C to cancel..." - -# 4. Create git tag and push -echo "Creating git tag $TAG_NAME..." -git tag "$TAG_NAME" -git push origin "$TAG_NAME" - -# 5. Create GitHub Release (if gh is installed) -if command -v gh &> /dev/null; then - echo "Creating GitHub Release..." - gh release create "$TAG_NAME" --generate-notes -else - echo "⚠️ 'gh' CLI not found. Skipping GitHub Release creation." - echo "You can create it manually at: $REPO_URL/releases/new?tag=$TAG_NAME" -fi - -echo "Waiting 5 seconds for GitHub to generate tarball..." -sleep 5 - -# 6. Calculate SHA256 -TARBALL_URL="$REPO_URL/archive/refs/tags/$TAG_NAME.tar.gz" -echo "Downloading tarball from $TARBALL_URL..." -SHA256=$(curl -L -s "$TARBALL_URL" | shasum -a 256 | awk '{print $1}') - -if [ -z "$SHA256" ] || [ ${#SHA256} -ne 64 ]; then - echo "Error: Failed to calculate valid SHA256. Got: $SHA256" - exit 1 -fi - -echo "Calculated SHA256: $SHA256" - -# 7. Update codemap.rb locally -echo "Updating $FORMULA_FILE..." -# Use sed to replace url and sha256 (macOS compatible sed -i '') -# We match "url" and "sha256" at the start of the line (indented) to avoid matching the resource block -sed -i '' "s|^ url \".*\"| url \"$TARBALL_URL\"|" "$FORMULA_FILE" -sed -i '' "s|^ sha256 \".*\"| sha256 \"$SHA256\"|" "$FORMULA_FILE" - -# 8. Push local changes -echo "Committing updated formula to main repo..." -git add "$FORMULA_FILE" -git commit -m "Bump version to $TAG_NAME" -git push origin main - -# 9. Update Homebrew Tap -if [ -d "$TAP_DIR" ]; then - echo "Updating Homebrew Tap at $TAP_DIR..." - cp "$FORMULA_FILE" "$TAP_DIR/$FORMULA_FILE" - - # Capture current directory - CURRENT_DIR=$(pwd) - - cd "$TAP_DIR" - git add "$FORMULA_FILE" - git commit -m "Update codemap to $TAG_NAME" - git push origin main - - # Return to original directory - cd "$CURRENT_DIR" - - echo "Homebrew Tap updated successfully!" -else - echo "Warning: Directory $TAP_DIR not found." - echo "Skipping automatic tap update." - echo "Please manually copy $FORMULA_FILE to your homebrew-tap repo and push." -fi - -echo "✅ Release $TAG_NAME complete!" diff --git a/scripts/build-grammars.sh b/scripts/build-grammars.sh new file mode 100755 index 0000000..15ce4fa --- /dev/null +++ b/scripts/build-grammars.sh @@ -0,0 +1,116 @@ +#!/bin/bash +# build-grammars.sh - Build tree-sitter grammars for the current platform +# +# Usage: ./scripts/build-grammars.sh [target] +# target: darwin, linux, or windows (defaults to current OS) +# +# Environment variables: +# CC - C compiler (auto-detected if not set) +# CXX - C++ compiler (auto-detected if not set) + +set -e + +# Grammar definitions: lang:repo:branch:src_dir +GRAMMARS=( + "go:tree-sitter/tree-sitter-go:master:src" + "python:tree-sitter/tree-sitter-python:master:src" + "javascript:tree-sitter/tree-sitter-javascript:master:src" + "typescript:tree-sitter/tree-sitter-typescript:master:typescript/src" + "rust:tree-sitter/tree-sitter-rust:master:src" + "ruby:tree-sitter/tree-sitter-ruby:master:src" + "c:tree-sitter/tree-sitter-c:master:src" + "cpp:tree-sitter/tree-sitter-cpp:master:src" + "java:tree-sitter/tree-sitter-java:master:src" + "swift:tree-sitter/tree-sitter-swift:master:src" + "bash:tree-sitter/tree-sitter-bash:master:src" + "kotlin:fwcd/tree-sitter-kotlin:main:src" + "c_sharp:tree-sitter/tree-sitter-c-sharp:master:src" + "php:tree-sitter/tree-sitter-php:master:php/src" + "dart:UserNobody14/tree-sitter-dart:master:src" + "r:r-lib/tree-sitter-r:main:src" +) + +# Detect target platform +TARGET="${1:-$(uname -s | tr '[:upper:]' '[:lower:]')}" +case "$TARGET" in + darwin|macos) + TARGET="darwin" + EXT="dylib" + CC="${CC:-clang}" + CXX="${CXX:-clang++}" + SHARED_FLAGS="-shared -fPIC" + ;; + linux) + EXT="so" + CC="${CC:-gcc}" + CXX="${CXX:-g++}" + SHARED_FLAGS="-shared -fPIC" + ;; + windows|win) + TARGET="windows" + EXT="dll" + # Default to Zig for Windows cross-compilation + CC="${CC:-zig cc -target x86_64-windows-gnu}" + CXX="${CXX:-zig c++ -target x86_64-windows-gnu}" + SHARED_FLAGS="-shared -fPIC" + ;; + *) + echo "Unknown target: $TARGET" + echo "Usage: $0 [darwin|linux|windows]" + exit 1 + ;; +esac + +echo "Building grammars for $TARGET (.$EXT)" +echo "CC=$CC" +echo "CXX=$CXX" +echo "" + +mkdir -p grammars +BUILD_DIR=$(mktemp -d) +trap "rm -rf $BUILD_DIR" EXIT + +for grammar in "${GRAMMARS[@]}"; do + IFS=: read -r lang repo branch src_dir <<< "$grammar" + + echo "Building $lang..." + + # Download and extract to clean temp dir + rm -rf "$BUILD_DIR"/* + cd "$BUILD_DIR" + curl -sL "https://github.com/$repo/archive/refs/heads/$branch.tar.gz" | tar xz + extracted_dir=$(ls -d */ | head -1) + src_path="${extracted_dir}${src_dir}" + + if [ ! -d "$src_path" ]; then + echo " ✗ Source not found: $src_path" + exit 1 + fi + + # Compile + sources="$src_path/parser.c" + use_cxx=false + + if [ -f "$src_path/scanner.c" ]; then + sources="$sources $src_path/scanner.c" + elif [ -f "$src_path/scanner.cc" ]; then + use_cxx=true + $CXX -c -fPIC -I"$src_path" "$src_path/scanner.cc" -o scanner.o + sources="$sources scanner.o" + fi + + output_file="$OLDPWD/grammars/libtree-sitter-$lang.$EXT" + + if $use_cxx; then + $CXX $SHARED_FLAGS -I"$src_path" $sources -o "$output_file" + else + $CC $SHARED_FLAGS -I"$src_path" $sources -o "$output_file" + fi + + cd "$OLDPWD" + echo " ✓ Built $lang" +done + +echo "" +echo "Built ${#GRAMMARS[@]} grammars:" +ls -la grammars/