|
| 1 | +name: ast-grep distribution |
| 2 | + |
| 3 | +# Builds the tree-sitter parser shared libraries that ast-grep loads as the |
| 4 | +# `nextflow` custom language, verifies each is a usable parser, and smoke-tests |
| 5 | +# the shipped sgconfig + outline rules end-to-end. |
| 6 | + |
| 7 | +on: |
| 8 | + push: |
| 9 | + branches: [main, ast-grep-distribution] |
| 10 | + paths: |
| 11 | + - grammar.js |
| 12 | + - src/** |
| 13 | + - sgconfig.yml |
| 14 | + - rules/** |
| 15 | + - outline/** |
| 16 | + - lib/** |
| 17 | + - scripts/install-ast-grep.sh |
| 18 | + - .github/workflows/ast-grep-distribution.yml |
| 19 | + pull_request: |
| 20 | + paths: |
| 21 | + - grammar.js |
| 22 | + - src/** |
| 23 | + - sgconfig.yml |
| 24 | + - rules/** |
| 25 | + - outline/** |
| 26 | + - lib/** |
| 27 | + - scripts/install-ast-grep.sh |
| 28 | + - .github/workflows/ast-grep-distribution.yml |
| 29 | + workflow_dispatch: |
| 30 | + |
| 31 | +jobs: |
| 32 | + build: |
| 33 | + name: Build & verify (${{ matrix.triple }}) |
| 34 | + runs-on: ${{ matrix.os }} |
| 35 | + strategy: |
| 36 | + fail-fast: false |
| 37 | + matrix: |
| 38 | + include: |
| 39 | + - os: macos-14 |
| 40 | + triple: aarch64-apple-darwin |
| 41 | + libdir: lib/macos-arm64 |
| 42 | + libname: libnextflow.dylib |
| 43 | + - os: ubuntu-latest |
| 44 | + triple: x86_64-unknown-linux-gnu |
| 45 | + libdir: lib/linux-x64 |
| 46 | + libname: libnextflow.so |
| 47 | + steps: |
| 48 | + - uses: actions/checkout@v4 |
| 49 | + |
| 50 | + - uses: actions/setup-node@v4 |
| 51 | + with: |
| 52 | + node-version: 20 |
| 53 | + |
| 54 | + # Install the CLI globally rather than via `npm ci`: building the parser |
| 55 | + # library only needs the tree-sitter CLI, not the project's node bindings |
| 56 | + # (whose install runs node-gyp). The global install's postinstall fetches |
| 57 | + # the platform tree-sitter binary. |
| 58 | + - name: Install tree-sitter CLI |
| 59 | + run: npm install -g tree-sitter-cli@^0.24.5 |
| 60 | + |
| 61 | + - name: Generate parser |
| 62 | + run: tree-sitter generate |
| 63 | + |
| 64 | + - name: Build parser library |
| 65 | + run: tree-sitter build --output "${{ matrix.libname }}" |
| 66 | + |
| 67 | + - name: Verify parser symbol |
| 68 | + run: | |
| 69 | + lib="${{ matrix.libname }}" |
| 70 | + if [ "${{ runner.os }}" = "macOS" ]; then |
| 71 | + symbols=$(nm -gU "$lib") |
| 72 | + else |
| 73 | + symbols=$(nm -D "$lib") |
| 74 | + fi |
| 75 | + if echo "$symbols" | grep -q tree_sitter_nextflow; then |
| 76 | + echo "✓ tree_sitter_nextflow exported by $lib" |
| 77 | + else |
| 78 | + echo "✗ tree_sitter_nextflow not found in $lib" >&2 |
| 79 | + exit 1 |
| 80 | + fi |
| 81 | +
|
| 82 | + - name: Stage library at distribution path |
| 83 | + run: | |
| 84 | + mkdir -p "${{ matrix.libdir }}" |
| 85 | + cp "${{ matrix.libname }}" "${{ matrix.libdir }}/${{ matrix.libname }}" |
| 86 | +
|
| 87 | + - name: Install ast-grep |
| 88 | + run: npm install -g @ast-grep/cli@^0.44.0 |
| 89 | + |
| 90 | + - name: Smoke-test outline rules against freshly built parser |
| 91 | + run: | |
| 92 | + cat > /tmp/smoke.nf <<'NF' |
| 93 | + include { FASTQC, MULTIQC as QC } from './modules/qc' |
| 94 | +
|
| 95 | + process ALIGN { |
| 96 | + script: |
| 97 | + """echo hi""" |
| 98 | + } |
| 99 | +
|
| 100 | + workflow RNASEQ { |
| 101 | + x = 1 |
| 102 | + } |
| 103 | +
|
| 104 | + workflow { |
| 105 | + y = 2 |
| 106 | + } |
| 107 | + NF |
| 108 | + out=$(ast-grep outline --lang nextflow \ |
| 109 | + --outline-rules outline/nextflow.yml \ |
| 110 | + --no-default-outline-rules --items all --json=compact /tmp/smoke.nf) |
| 111 | + echo "$out" |
| 112 | + for sym in FASTQC MULTIQC ALIGN RNASEQ main; do |
| 113 | + echo "$out" | grep -q "\"name\":\"$sym\"" || { echo "✗ outline missing $sym" >&2; exit 1; } |
| 114 | + done |
| 115 | + echo "✓ outline extracted all expected symbols" |
| 116 | +
|
| 117 | + - name: Upload parser library |
| 118 | + uses: actions/upload-artifact@v4 |
| 119 | + with: |
| 120 | + name: libnextflow-${{ matrix.triple }} |
| 121 | + path: ${{ matrix.libdir }}/${{ matrix.libname }} |
| 122 | + if-no-files-found: error |
0 commit comments