Skip to content

Commit fe6f449

Browse files
committed
JavaScript: Add CI configuration for software tests and Dependabot
1 parent 609e7a5 commit fe6f449

File tree

8 files changed

+112
-8
lines changed

8 files changed

+112
-8
lines changed

.github/dependabot.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
5+
16
version: 2
27

38
updates:
@@ -7,6 +12,11 @@ updates:
712
schedule:
813
interval: "weekly"
914

15+
- package-ecosystem: "npm"
16+
directory: "/cratedb_sqlparse_js"
17+
schedule:
18+
interval: "weekly"
19+
1020
- package-ecosystem: "pip"
1121
directory: "/cratedb_sqlparse_py"
1222
schedule:

.github/workflows/javascript.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
---
2+
name: JavaScript Tests
3+
4+
on:
5+
pull_request: ~
6+
push:
7+
branches: [ main ]
8+
9+
# Allow job to be triggered manually.
10+
workflow_dispatch:
11+
12+
# Run job each night after CrateDB nightly has been published.
13+
schedule:
14+
- cron: '0 3 * * *'
15+
16+
# Cancel in-progress jobs when pushing to the same branch.
17+
concurrency:
18+
cancel-in-progress: true
19+
group: ${{ github.workflow }}-${{ github.ref }}
20+
21+
# Select JavaScript grammar.
22+
defaults:
23+
run:
24+
working-directory: cratedb_sqlparse_js
25+
26+
jobs:
27+
28+
tests:
29+
30+
runs-on: ${{ matrix.os }}
31+
strategy:
32+
fail-fast: false
33+
matrix:
34+
os: ["ubuntu-latest"]
35+
node-version: ["18", "20", "22"]
36+
37+
env:
38+
OS: ${{ matrix.os }}
39+
NODEJS: ${{ matrix.node-version }}
40+
41+
# https://docs.github.com/en/actions/using-containerized-services/about-service-containers
42+
services:
43+
cratedb:
44+
image: crate/crate:nightly
45+
ports:
46+
- 4200:4200
47+
- 5432:5432
48+
env:
49+
CRATE_HEAP_SIZE: 4g
50+
51+
name: JavaScript ${{ matrix.node-version }} on OS ${{ matrix.os }}
52+
steps:
53+
54+
- name: Acquire sources
55+
uses: actions/checkout@v4
56+
57+
# https://github.com/actions/setup-python
58+
- name: Set up Python
59+
uses: actions/setup-python@v5
60+
with:
61+
python-version: 3.12
62+
architecture: x64
63+
64+
# https://github.com/actions/setup-node
65+
- name: Set up Node.js
66+
uses: actions/setup-node@v4
67+
with:
68+
node-version: ${{ matrix.node-version }}
69+
cache: 'npm'
70+
cache-dependency-path: 'package-lock.json'
71+
72+
- name: Generate runtime grammar
73+
run: |
74+
cd ..
75+
pip install --requirement requirements.txt
76+
python setup_grammar.py javascript
77+
78+
- name: Set up project
79+
run: npm install
80+
81+
- name: Run linter and software tests
82+
run: npm test
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
cache: 'pip'
6363
cache-dependency-path: 'pyproject.toml'
6464

65-
- name: Setup project
65+
- name: Set up project
6666
run: |
6767
6868
# `setuptools 0.64.0` adds support for editable install hooks (PEP 660).

cratedb_sqlparse_js/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cratedb_sqlparse_js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"sql-dialect"
2626
],
2727
"scripts": {
28-
"test": "vitest",
28+
"test": "vitest run",
2929
"build": "vite build"
3030
},
3131
"devDependencies": {

cratedb_sqlparse_py/tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def generate():
1919
# Test module for availability.
2020
find_spec("cratedb_sqlparse.generated_parser.SqlBaseParser")
2121
except ImportError:
22-
subprocess.check_call([sys.executable, SETUP_GRAMMAR], cwd=HERE.parent.parent) # noqa: S603
22+
subprocess.check_call([sys.executable, SETUP_GRAMMAR, "python"], cwd=HERE.parent.parent) # noqa: S603
2323

2424
try:
2525
# Test module for availability.

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[tool.poe.tasks]
22

33
generate = [
4-
{ cmd = "python setup_grammar.py" },
4+
{ cmd = "python setup_grammar.py python" },
5+
{ cmd = "python setup_grammar.py javascript" },
56
]

setup_grammar.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,21 @@ def set_version(target: Antlr4Target, version: str):
143143

144144

145145
if __name__ == '__main__':
146+
"""
147+
Invoke the grammar compiler / generator.
148+
149+
TODO: Converge `version` into command-line argument?
150+
TODO: Improve efficiency by generating runtime parser for all implemented languages at once.
151+
"""
146152
setup_logging()
147-
# TODO: Converge into command-line argument?
153+
input_target = sys.argv[1]
148154
version = '5.6.4'
149-
target = Antlr4Target.python
155+
if input_target.startswith("py"):
156+
target = Antlr4Target.python
157+
elif input_target.startswith("js") or input_target.startswith("java"):
158+
target = Antlr4Target.js
159+
else:
160+
raise NotImplementedError(f"Parser generator for target {input_target} not implemented")
150161
download_cratedb_grammar(version)
151162
compile_grammar(target)
152163
patch_lexer(target)

0 commit comments

Comments
 (0)