Repository navigation
117 lines (113 loc) · 4.63 KB
/
Copy pathast-shape-test.yaml
File metadata and controls
117 lines (113 loc) · 4.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
name: ast-shape-test
# Every binding decodes the same parser output, and each one hand-rolls that
# decoder. A wrong field shape is silent — a list read as a single node yields
# an empty result, a NodeRef<Identifier> read as a Node<String> yields a
# zero-valued node — so the language test suites cannot see it. This workflow
# cross-checks all of them against the Rust struct definitions in one go, which
# is why it lives apart from any single language's build.
on:
push:
branches:
- main
- master
tags:
- '*'
pull_request:
branches:
- main
paths:
- "hack/**"
# One entry per binding's AST decoder. A new binding means a new entry
# here too, or its decoder is only ever checked locally.
- "ruby/lib/kcl_lib/ast.rb"
- "julia/src/ast.jl"
- "lua/kcl_lib/ast.lua"
- "dart/lib/src/ast/**"
- "python/kcl_lib/ast/**"
- "wasm/src/ast/**"
- "nodejs/src/ast/**"
- "dotnet/KclLib.AST/**"
- "zig/src/ast/**"
- "swift/Sources/KclLibAST/**"
- "go/ast/**"
- "php/src/Ast/**"
- "java/src/main/java/com/kcl/ast/**"
- "kotlin/src/main/kotlin/com/kcl/ast/**"
- "c/include/kcl_lib_ast.h"
- "c/lib/kcl_lib_ast.c"
- "cpp/include/kcl_lib_ast.hpp"
- ".github/workflows/ast-shape-test.yaml"
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
cancel-in-progress: true
permissions:
contents: read
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
path: lib
# The Rust struct definitions are the thing everything is checked against,
# and they live in the kcl repo rather than here. Checked out next to this
# one so the default `../../kcl` path resolves.
- name: Checkout kcl
uses: actions/checkout@v7
with:
repository: kcl-lang/kcl
path: kcl
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.4"
- name: Check every binding against the Rust struct definitions
working-directory: "lib"
run: ruby hack/check_ast_field_types.rb
# The self-test breaks each decoder on purpose and asserts the rules fire.
# Without it a collector that matches nothing would report "ok" for every
# binding, which is the failure mode this whole setup exists to prevent.
- name: Verify the checker still catches a broken decoder
working-directory: "lib"
run: ruby hack/test_check_ast_field_types.rb
# index.d.mts is hand-written and src/ast/*.mjs is hand-written, and a
# tsc run cannot compare them: the repo's tsconfig includes `.` with the
# default extensions and `.d.mts` is not one of them, so the published
# declaration is not in the program. This checker emits a declaration from
# the loaders' JSDoc and diffs the two, so it needs a real tsc.
- uses: pnpm/action-setup@v6
with:
version: 10
- name: Setup node
uses: actions/setup-node@v7
with:
node-version: '22'
- name: Install dependencies
working-directory: "lib/nodejs"
run: pnpm i
- name: Check the published AST declaration against the loaders
working-directory: "lib"
run: ruby hack/check_ast_decl_drift.rb
# Same reasoning as the field-types self-test above, one level up: this
# checker emits a declaration with tsc and diffs it, and a mutation that
# silently matches nothing would leave it green. Without this step
# check_ast_decl_drift.rb runs in CI but is never itself tested, which is
# the arrangement that let it pass on a gutted loader.
- name: Verify the declaration checker still catches drift
working-directory: "lib"
run: ruby hack/test_check_ast_decl_drift.rb
# Field shapes are half the question a caller runs into; how a node is
# built is the other half. This checker holds every binding's node
# constructors to the same three rules — one exists, every field is
# reachable through it, and no parameter names a field ast.rs does not
# declare — with kotlin/.../AstBuild.kt as the reference form.
- name: Check every binding's AST constructors against ast.rs
working-directory: "lib"
run: ruby hack/check_ast_constructors.rb
# The self-test breaks constructors on purpose and asserts the rules fire,
# for the same reason as the two above: a collector that silently matches
# nothing must fail loudly, not report "ok" for every binding.
- name: Verify the constructor checker still catches a gutted binding
working-directory: "lib"
run: ruby hack/test_check_ast_constructors.rb