Skip to content

Feature/highlight coverage #1

Feature/highlight coverage

Feature/highlight coverage #1

Workflow file for this run

name: CI
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
test-parser:
name: Test Parser
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18, 20]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Install Tree Sitter CLI
run: npm install -g tree-sitter-cli
- name: Verify Tree Sitter CLI installation
run: tree-sitter --version
- name: Install dependencies
run: npm ci
- name: Generate parser
run: tree-sitter generate
- name: Build parser
run: tree-sitter build
- name: Run parser tests
run: tree-sitter test
- name: Test parsing examples
run: tree-sitter parse examples/*.adoc --stat
test-highlighting:
name: Test Syntax Highlighting
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install Tree Sitter CLI
run: npm install -g tree-sitter-cli
- name: Install dependencies
run: npm ci
- name: Generate and build parser
run: |
tree-sitter generate
tree-sitter build
- name: Test highlighting queries
run: |
# Test that highlight queries are syntactically valid
for case_file in test/highlight/cases/*.adoc; do
if [ -f "$case_file" ]; then
echo "Testing highlighting for $(basename "$case_file")..."
tree-sitter query -c queries/highlights.scm "$case_file" > /dev/null
fi
done
- name: Run highlighting tests
run: bash test/highlight/tools/run.sh
- name: Generate HTML highlighting examples
run: |
mkdir -p .github-artifacts/highlighting-examples
for case_file in test/highlight/cases/*.adoc; do
if [ -f "$case_file" ]; then
basename=$(basename "$case_file" .adoc)
echo "Generating HTML for $basename..."
tree-sitter highlight --html "$case_file" > ".github-artifacts/highlighting-examples/${basename}.html"
fi
done
- name: Upload highlighting examples
uses: actions/upload-artifact@v4
with:
name: highlighting-examples-${{ github.sha }}
path: .github-artifacts/highlighting-examples/
retention-days: 30
test-bindings:
name: Test Language Bindings
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
include:
- os: ubuntu-latest
platform: linux
- os: windows-latest
platform: windows
- os: macos-latest
platform: macos
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install Tree Sitter CLI
run: npm install -g tree-sitter-cli
- name: Install dependencies
run: npm ci
- name: Generate parser
run: tree-sitter generate
- name: Build parser
run: tree-sitter build
- name: Test Node.js bindings
run: npm test
- name: Test basic parsing functionality
shell: bash
run: |
node -e "
const Parser = require('tree-sitter');
const AsciiDoc = require('./bindings/node');
const parser = new Parser();
parser.setLanguage(AsciiDoc);
const tree = parser.parse('= Hello World\\n\\nThis is a test.');
console.log('Parse successful:', tree.rootNode.type === 'source_file');
"
lint-and-format:
name: Lint and Format
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Check grammar.js formatting
run: |
# Basic syntax check for grammar.js
node -c grammar.js
- name: Validate JSON files
run: |
# Validate tree-sitter.json and package.json
node -e "JSON.parse(require('fs').readFileSync('tree-sitter.json', 'utf8'))"
node -e "JSON.parse(require('fs').readFileSync('package.json', 'utf8'))"
- name: Check query files syntax
run: |
if [ -f queries/highlights.scm ]; then
# Basic syntax check - tree-sitter will validate the query format
tree-sitter generate
tree-sitter build
echo "= Test" | tree-sitter query queries/highlights.scm - > /dev/null
fi
benchmark:
name: Performance Benchmark
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install Tree Sitter CLI
run: npm install -g tree-sitter-cli
- name: Install dependencies
run: npm ci
- name: Generate and build parser
run: |
tree-sitter generate
tree-sitter build
- name: Run parsing benchmarks
run: |
echo "Running performance benchmarks..."
# Create a larger test file for benchmarking
cat > benchmark-test.adoc << 'EOF'
= Large AsciiDoc Document
:author: Benchmark Test
:version: 1.0
== Introduction
This is a larger document used for performance testing.
=== Multiple Sections
We need multiple sections to test parser performance.
* Unordered list item 1
* Unordered list item 2
** Nested item A
** Nested item B
* Unordered list item 3
1. Ordered list item 1
2. Ordered list item 2
3. Ordered list item 3
ifdef::debug[]
This is conditional content for debugging.
endif::debug[]
ifndef::production[]
This appears in non-production builds.
endif::production[]
==== Subsection with More Content
More paragraph content to increase file size and complexity.
This helps us test the parser's performance on larger documents.
Term 1:: Definition for term 1
Term 2:: Definition for term 2
Longer Term:: A longer definition that spans multiple words
<1> Callout item one
<2> Callout item two
<3> Callout item three
EOF
# Copy the content multiple times to make it larger
for i in {1..10}; do
echo "" >> benchmark-test.adoc
echo "== Section $i" >> benchmark-test.adoc
cat benchmark-test.adoc >> temp.adoc
mv temp.adoc benchmark-test.adoc
done
echo "File size: $(wc -c < benchmark-test.adoc) bytes"
echo "Line count: $(wc -l < benchmark-test.adoc) lines"
# Parse with timing
time tree-sitter parse benchmark-test.adoc --stat
release-check:
name: Release Readiness Check
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' || github.base_ref == 'main'
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install Tree Sitter CLI
run: npm install -g tree-sitter-cli
- name: Install dependencies
run: npm ci
- name: Generate parser
run: tree-sitter generate
- name: Build parser
run: tree-sitter build
- name: Validate package completeness
run: |
echo "Checking package completeness for release..."
# Check required files exist
required_files=(
"grammar.js"
"tree-sitter.json"
"package.json"
"README.md"
"queries/highlights.scm"
"src/parser.c"
"src/node-types.json"
"src/grammar.json"
)
missing_files=()
for file in "${required_files[@]}"; do
if [[ ! -f "$file" ]]; then
missing_files+=("$file")
fi
done
if [[ ${#missing_files[@]} -gt 0 ]]; then
echo "❌ Missing required files:"
printf ' - %s\n' "${missing_files[@]}"
exit 1
fi
echo "✅ All required files present"
- name: Test package installation simulation
run: |
# Test that the package can be installed (without actually publishing)
npm pack
echo "✅ Package can be built successfully"