From 7e7b0f76e0ba53c6a18dd92c2dd4f997cb63aaab Mon Sep 17 00:00:00 2001 From: "Wu, Zhenyu" Date: Wed, 14 Oct 2026 17:30:10 +0800 Subject: [PATCH] chore: add init to run `tree-sitter init` --- .github/workflows/package-crates.yml | 14 ++++++- .github/workflows/package-maven.yml | 15 ++++++- .github/workflows/package-npm.yml | 58 +++++++++++++++++++++++----- .github/workflows/package-pypi.yml | 27 ++++++++++++- .github/workflows/release.yml | 13 +++++++ README.md | 20 ++++++++++ 6 files changed, 134 insertions(+), 13 deletions(-) diff --git a/.github/workflows/package-crates.yml b/.github/workflows/package-crates.yml index 5932674..47e5a52 100644 --- a/.github/workflows/package-crates.yml +++ b/.github/workflows/package-crates.yml @@ -15,6 +15,10 @@ on: description: The Rust toolchain default: ${{vars.RUST_TOOLCHAIN || 'stable'}} type: string + init: + description: Initialize a grammar repository + default: false + type: boolean generate: description: Generate the parser artifacts default: false @@ -43,7 +47,7 @@ jobs: with: toolchain: ${{inputs.rust-toolchain}} - name: Set up tree-sitter CLI - if: ${{inputs.generate}} + if: ${{inputs.generate || inputs.init}} uses: tree-sitter/setup-action/cli@v2 - name: Install dependencies run: |- @@ -57,6 +61,14 @@ jobs: (.key | startswith("tree-sitter-")) and (.key != "tree-sitter-cli") )) | length > 0 + - name: Initialize grammar repository + if: ${{inputs.init}} + run: | + while read -r grammar_dir; do + pushd "$grammar_dir" + tree-sitter init + popd > /dev/null + done < <(jq -r '.grammars[].path // "."' tree-sitter.json) - name: Regenerate parser if: ${{inputs.generate}} run: | diff --git a/.github/workflows/package-maven.yml b/.github/workflows/package-maven.yml index e817437..4b1e3f5 100644 --- a/.github/workflows/package-maven.yml +++ b/.github/workflows/package-maven.yml @@ -23,6 +23,10 @@ on: description: The Java distribution default: temurin type: string + init: + description: Initialize a grammar repository + default: false + type: boolean generate: description: Generate the parser artifacts default: false @@ -90,7 +94,7 @@ jobs: server-password: MAVEN_CENTRAL_TOKEN gpg-private-key: ${{secrets.GPG_PRIVATE_KEY}} - name: Set up tree-sitter CLI - if: ${{inputs.generate}} + if: ${{inputs.generate || inputs.init}} uses: tree-sitter/setup-action/cli@v2 - name: Install dependencies if: ${{inputs.generate}} @@ -106,6 +110,15 @@ jobs: (.key | startswith("tree-sitter-")) and (.key != "tree-sitter-cli") )) | length > 0 + - name: Initialize grammar repository + if: ${{inputs.init}} + shell: bash + run: | + while read -r grammar_dir; do + pushd "$grammar_dir" + tree-sitter init + popd > /dev/null + done < <(jq -r '.grammars[].path // "."' tree-sitter.json) - name: Regenerate parser if: ${{inputs.generate}} shell: bash diff --git a/.github/workflows/package-npm.yml b/.github/workflows/package-npm.yml index 6e0a54b..48a4470 100644 --- a/.github/workflows/package-npm.yml +++ b/.github/workflows/package-npm.yml @@ -15,6 +15,10 @@ on: description: The NodeJS version default: ${{vars.NODE_VERSION || '22'}} type: string + init: + description: Initialize a grammar repository + default: false + type: boolean generate: description: Generate the parser artifacts default: false @@ -43,20 +47,31 @@ jobs: - name: Set up NodeJS uses: actions/setup-node@v7 with: - cache: npm + cache: ${{!inputs.init && 'npm' || ''}} node-version: ${{inputs.node-version}} - - name: Install dependencies - run: npm i --omit peer --omit optional + - name: Set up tree-sitter CLI + if: ${{inputs.init}} + uses: tree-sitter/setup-action/cli@v2 + - name: Initialize grammar repository + if: ${{inputs.init}} + run: | + while read -r grammar_dir; do + pushd "$grammar_dir" + tree-sitter init + popd > /dev/null + done < <(jq -r '.grammars[].path // "."' tree-sitter.json) - name: Regenerate parser if: ${{inputs.generate}} run: | while read -r grammar_dir; do pushd "$grammar_dir" - npm x -- tree-sitter generate + tree-sitter generate popd > /dev/null done < <(jq -r '.grammars[].path // "."' tree-sitter.json) env: TREE_SITTER_ABI_VERSION: ${{inputs.abi-version}} + - name: Install dependencies + run: npm i --omit peer --omit optional - name: Build Wasm binaries run: |- while read -r grammar_dir; do @@ -87,10 +102,20 @@ jobs: - name: Set up NodeJS uses: actions/setup-node@v7 with: - cache: npm + cache: ${{!inputs.init && 'npm' || ''}} node-version: ${{inputs.node-version}} - - name: Install dependencies - run: npm i --omit peer --omit optional + - name: Set up tree-sitter CLI + if: ${{inputs.init}} + uses: tree-sitter/setup-action/cli@v2 + - name: Initialize grammar repository + if: ${{inputs.init}} + run: | + while read -r grammar_dir; do + grammar_dir="${grammar_dir%$'\r'}" + pushd "$grammar_dir" + tree-sitter init + popd > /dev/null + done < <(jq -r '.grammars[].path // "."' tree-sitter.json) - name: Regenerate parser if: ${{inputs.generate}} shell: bash @@ -98,9 +123,13 @@ jobs: while read -r grammar_dir; do grammar_dir="${grammar_dir%$'\r'}" pushd "$grammar_dir" - npm x -- tree-sitter generate + tree-sitter generate popd > /dev/null done < <(jq -r '.grammars[].path // "."' tree-sitter.json) + env: + TREE_SITTER_ABI_VERSION: ${{inputs.abi-version}} + - name: Install dependencies + run: npm i --omit peer --omit optional - name: Build binary run: npm x -- prebuildify -t 20.19.5 - name: Upload binaries @@ -123,9 +152,20 @@ jobs: - name: Set up NodeJS uses: actions/setup-node@v7 with: - cache: npm + cache: ${{!inputs.init && 'npm' || ''}} node-version: ${{inputs.node-version}} registry-url: https://registry.npmjs.org/ + - name: Set up tree-sitter CLI + if: ${{inputs.init}} + uses: tree-sitter/setup-action/cli@v2 + - name: Initialize grammar repository + if: ${{inputs.init}} + run: | + while read -r grammar_dir; do + pushd "$grammar_dir" + tree-sitter init + popd > /dev/null + done < <(jq -r '.grammars[].path // "."' tree-sitter.json) - name: Download binaries uses: actions/download-artifact@v8 with: diff --git a/.github/workflows/package-pypi.yml b/.github/workflows/package-pypi.yml index eab1db8..dd79379 100644 --- a/.github/workflows/package-pypi.yml +++ b/.github/workflows/package-pypi.yml @@ -15,6 +15,10 @@ on: description: The Python version default: ${{vars.PYTHON_VERSION || '3.11'}} type: string + init: + description: Initialize a grammar repository + default: false + type: boolean generate: description: Generate the parser artifacts default: false @@ -42,7 +46,7 @@ jobs: with: python-version: ${{inputs.python-version}} - name: Set up tree-sitter CLI - if: ${{inputs.generate}} + if: ${{inputs.generate || inputs.init}} uses: tree-sitter/setup-action/cli@v2 - name: Install dependencies run: |- @@ -56,6 +60,15 @@ jobs: (.key | startswith("tree-sitter-")) and (.key != "tree-sitter-cli") )) | length > 0 + - name: Initialize grammar repository + if: ${{inputs.init}} + shell: bash + run: | + while read -r grammar_dir; do + pushd "$grammar_dir" + tree-sitter init + popd > /dev/null + done < <(jq -r '.grammars[].path // "."' tree-sitter.json) - name: Regenerate parser if: ${{inputs.generate}} shell: bash @@ -94,7 +107,7 @@ jobs: - name: Checkout repository uses: actions/checkout@v7 - name: Set up tree-sitter CLI - if: ${{inputs.generate}} + if: ${{inputs.generate || inputs.init}} uses: tree-sitter/setup-action/cli@v2 - name: Install dependencies shell: bash @@ -109,6 +122,16 @@ jobs: (.key | startswith("tree-sitter-")) and (.key != "tree-sitter-cli") )) | length > 0 + - name: Initialize grammar repository + if: ${{inputs.init}} + shell: bash + run: | + while read -r grammar_dir; do + grammar_dir="${grammar_dir%$'\r'}" + pushd "$grammar_dir" + tree-sitter init + popd > /dev/null + done < <(jq -r '.grammars[].path // "."' tree-sitter.json) - name: Regenerate parser if: ${{inputs.generate}} shell: bash diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4798bab..c5d2c6b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,6 +3,10 @@ name: Publish GitHub release on: workflow_call: inputs: + init: + description: Initialize a grammar repository + default: false + type: boolean generate: description: Generate the parser artifacts default: false @@ -43,6 +47,15 @@ jobs: (.key | startswith("tree-sitter-")) and (.key != "tree-sitter-cli") )) | length > 0 + - name: Initialize grammar repository + if: inputs.init + shell: bash + run: | + while read -r grammar_dir; do + pushd "$grammar_dir" + tree-sitter init + popd > /dev/null + done < <(jq -r '.grammars[].path // "."' tree-sitter.json) - name: Generate parser if: inputs.generate shell: bash diff --git a/README.md b/README.md index b1b1c6d..4e55749 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,10 @@ jobs: ```yaml inputs: + init: + description: Initialize a grammar repository + default: false + type: boolean generate: description: Generate the parser artifacts default: false @@ -107,6 +111,10 @@ inputs: description: The NodeJS version default: ${{vars.NODE_VERSION || '22'}} type: string + init: + description: Initialize a grammar repository + default: false + type: boolean generate: description: Generate the parser artifacts default: false @@ -137,6 +145,10 @@ inputs: description: The Rust toolchain default: ${{vars.RUST_TOOLCHAIN || 'stable'}} type: string + init: + description: Initialize a grammar repository + default: false + type: boolean generate: description: Generate the parser artifacts default: false @@ -167,6 +179,10 @@ inputs: description: The Python version default: ${{vars.PYTHON_VERSION || '3.x'}} type: string + init: + description: Initialize a grammar repository + default: false + type: boolean generate: description: Generate the parser artifacts default: false @@ -205,6 +221,10 @@ inputs: description: The Java distribution default: temurin type: string + init: + description: Initialize a grammar repository + default: false + type: boolean generate: description: Generate the parser artifacts default: false