Skip to content

Commit 53b4bb8

Browse files
Copilothzhangxyz
andauthored
Add bnf-pytest.yml and bnf-jest.yml workflows with dedicated publish environments (#80)
* Initial plan * Add bnf-pytest.yml and bnf-jest.yml workflows with pypi-bnf and npm-bnf environments Co-authored-by: hzhangxyz <[email protected]> * Update caching policy. * Add ANTLR4 setup and simplify Python build to use python -m build Co-authored-by: hzhangxyz <[email protected]> * Update cache policy. * Update version of setup-antlr4. * Update setup.py for apyds_bnf. * Use pip to install antlr4. --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: hzhangxyz <[email protected]> Co-authored-by: Hao Zhang <[email protected]>
1 parent 2a08679 commit 53b4bb8

File tree

4 files changed

+175
-13
lines changed

4 files changed

+175
-13
lines changed

.github/workflows/bnf-jest.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: bnf-jest
2+
permissions:
3+
contents: read
4+
5+
on:
6+
- pull_request
7+
- push
8+
9+
env:
10+
NODE_LATEST_VERSION: '24'
11+
12+
jobs:
13+
bnf-jest:
14+
runs-on: ubuntu-latest
15+
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
node-version: ['20', '22', '24']
20+
21+
steps:
22+
- uses: actions/checkout@v6
23+
24+
- name: install antlr4
25+
run: pip install antlr4-tools
26+
27+
- uses: actions/setup-node@v6
28+
with:
29+
node-version: ${{ matrix.node-version }}
30+
cache: 'npm'
31+
32+
- name: dependencies
33+
working-directory: bnf
34+
run: npm ci
35+
36+
- name: jest
37+
working-directory: bnf
38+
run: npm run all
39+
40+
npm:
41+
runs-on: ubuntu-latest
42+
needs: bnf-jest
43+
44+
if: "github.event_name == 'push' && startsWith(github.ref, 'refs/tags')"
45+
46+
environment:
47+
name: npm-bnf
48+
url: https://www.npmjs.com/package/atsds-bnf
49+
permissions:
50+
id-token: write
51+
52+
steps:
53+
- uses: actions/checkout@v6
54+
55+
- name: recovery tag information
56+
run: git fetch --tags --force
57+
58+
- name: install antlr4
59+
run: pip install antlr4-tools
60+
61+
- uses: actions/setup-node@v6
62+
with:
63+
node-version: ${{ env.NODE_LATEST_VERSION }}
64+
cache: 'npm'
65+
66+
- name: version
67+
working-directory: bnf
68+
run: npm version from-git --no-git-tag-version
69+
70+
- name: extract tag
71+
run: |
72+
GIT_TAG=${GITHUB_REF#refs/tags/}
73+
TAG=$(echo $GIT_TAG | sed -E 's/^v//' | sed -E 's/[0-9\.-]//g' | sed -E 's/^$/latest/g')
74+
echo TAG=$TAG >> $GITHUB_ENV
75+
76+
- name: dependencies
77+
working-directory: bnf
78+
run: npm ci
79+
80+
- name: build
81+
working-directory: bnf
82+
run: npm run build
83+
84+
- name: publish
85+
working-directory: bnf
86+
run: npm publish --tag $TAG

.github/workflows/bnf-pytest.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: bnf-pytest
2+
permissions:
3+
contents: read
4+
5+
on:
6+
- pull_request
7+
- push
8+
9+
env:
10+
PYTHON_LATEST_VERSION: '3.14'
11+
12+
jobs:
13+
bnf-pytest:
14+
runs-on: ubuntu-latest
15+
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
python-version: ['3.10', '3.11', '3.12', '3.13', '3.14']
20+
21+
steps:
22+
- uses: actions/checkout@v6
23+
24+
- name: install antlr4
25+
run: pip install antlr4-tools
26+
27+
- uses: astral-sh/setup-uv@v7
28+
with:
29+
python-version: ${{ matrix.python-version }}
30+
enable-cache: true
31+
32+
- name: dependencies
33+
working-directory: bnf
34+
run: uv sync --locked --extra dev
35+
36+
- name: pytest
37+
working-directory: bnf
38+
run: uv run pytest
39+
40+
build:
41+
runs-on: ubuntu-latest
42+
needs: bnf-pytest
43+
44+
if: "github.event_name == 'push' && startsWith(github.ref, 'refs/tags')"
45+
46+
steps:
47+
- uses: actions/checkout@v6
48+
49+
- name: recovery tag information
50+
run: git fetch --tags --force
51+
52+
- name: install antlr4
53+
run: pip install antlr4-tools
54+
55+
- uses: astral-sh/setup-uv@v7
56+
with:
57+
python-version: ${{ matrix.python-version }}
58+
enable-cache: true
59+
60+
- name: build
61+
working-directory: bnf
62+
run: uv build
63+
64+
- uses: actions/upload-artifact@v5
65+
with:
66+
name: dist
67+
path: bnf/dist/*.whl
68+
69+
upload:
70+
runs-on: ubuntu-latest
71+
needs: build
72+
73+
environment:
74+
name: pypi-bnf
75+
url: https://pypi.org/project/apyds-bnf
76+
permissions:
77+
id-token: write
78+
79+
steps:
80+
- uses: actions/download-artifact@v6
81+
with:
82+
name: dist
83+
path: dist
84+
85+
- uses: pypa/gh-action-pypi-publish@release/v1
86+
with:
87+
packages-dir: dist

bnf/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ version_scheme = "no-guess-dev"
2626
fallback_version = "0.0.0"
2727
root = ".."
2828

29-
[tool.setuptools.packages.find]
30-
include = ["apyds_bnf"]
29+
[tool.setuptools]
30+
packages = ["apyds_bnf"]
3131

3232
[project.optional-dependencies]
3333
dev = [

bnf/setup.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,19 @@
1-
"""
2-
Setup script for apyds-bnf package with ANTLR parser generation
3-
"""
4-
51
import subprocess
62
from pathlib import Path
7-
83
from setuptools import setup
94
from setuptools.command.build_py import build_py
105

116

127
class BuildWithAntlr(build_py):
13-
"""Custom build command that generates ANTLR parsers before building"""
14-
158
def run(self):
16-
"""Generate ANTLR parsers and then run the standard build"""
179
self.generate_antlr_parsers()
1810
super().run()
1911

2012
def generate_antlr_parsers(self):
21-
"""Generate Python parsers from ANTLR grammars"""
2213
base_dir = Path(__file__).parent
2314
grammars_dir = base_dir
2415
output_dir = base_dir / "apyds_bnf"
2516

26-
# Generate parsers for both grammars
2717
for grammar in ["Ds.g4", "Dsp.g4"]:
2818
grammar_path = grammars_dir / grammar
2919

@@ -44,7 +34,6 @@ def generate_antlr_parsers(self):
4434
print(f"Successfully generated parser for {grammar}")
4535

4636

47-
# Use pyproject.toml for configuration, but provide custom build command
4837
if __name__ == "__main__":
4938
setup(
5039
cmdclass={

0 commit comments

Comments
 (0)