Skip to content

Commit 998ffa0

Browse files
feat: add POS tag sync workflow with C++ upstream (closes #40)
- Add tree-sitter based script to extract POS tags from C++ source - Add GitHub Actions workflow for automatic sync (weekly + manual) - Add Makefile targets: sync-postypes, check-postypes - Update postype.go with tags from Kiwi v0.23.2 - Add .venv to .gitignore Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent b869bf7 commit 998ffa0

5 files changed

Lines changed: 513 additions & 118 deletions

File tree

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
name: Sync POS Tags from Kiwi Upstream
2+
3+
on:
4+
schedule:
5+
# Run weekly on Monday at 9:00 AM UTC
6+
- cron: '0 9 * * 1'
7+
workflow_dispatch:
8+
inputs:
9+
kiwi_version:
10+
description: 'Kiwi version to sync (e.g., v0.23.2)'
11+
required: false
12+
default: ''
13+
14+
permissions:
15+
contents: write
16+
pull-requests: write
17+
18+
jobs:
19+
check-and-sync:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v7
23+
24+
- name: Install Go
25+
uses: actions/setup-go@v7
26+
with:
27+
go-version-file: go.mod
28+
29+
- name: Set up Python
30+
uses: actions/setup-python@v5
31+
with:
32+
python-version: '3.12'
33+
34+
- name: Install dependencies
35+
run: |
36+
python -m venv .venv
37+
source .venv/bin/activate
38+
pip install tree-sitter tree-sitter-cpp
39+
40+
- name: Get latest Kiwi version
41+
id: get_version
42+
run: |
43+
if [ -n "${{ github.event.inputs.kiwi_version }}" ]; then
44+
echo "version=${{ github.event.inputs.kiwi_version }}" >> $GITHUB_OUTPUT
45+
else
46+
# Get latest release from GitHub API
47+
VERSION=$(curl -s https://api.github.com/repos/bab2min/Kiwi/releases/latest | jq -r '.tag_name')
48+
echo "version=$VERSION" >> $GITHUB_OUTPUT
49+
fi
50+
echo "Kiwi version: $(cat $GITHUB_OUTPUT | grep version | cut -d= -f2)"
51+
52+
- name: Extract POS tags
53+
id: extract
54+
run: |
55+
source .venv/bin/activate
56+
python scripts/extract_postags.py ${{ steps.get_version.outputs.version }}
57+
58+
# Check if there are changes
59+
if diff -q postype.go postype_generated.go > /dev/null 2>&1; then
60+
echo "changed=false" >> $GITHUB_OUTPUT
61+
echo "No changes detected"
62+
else
63+
echo "changed=true" >> $GITHUB_OUTPUT
64+
echo "Changes detected"
65+
fi
66+
67+
- name: Generate diff summary
68+
if: steps.extract.outputs.changed == 'true'
69+
id: diff
70+
run: |
71+
# Generate diff summary
72+
DIFF=$(diff -u postype.go postype_generated.go || true)
73+
echo "diff<<EOF" >> $GITHUB_OUTPUT
74+
echo "$DIFF" >> $GITHUB_OUTPUT
75+
echo "EOF" >> $GITHUB_OUTPUT
76+
77+
# Count changes
78+
ADDED=$(diff postype.go postype_generated.go | grep "^>" | wc -l || echo "0")
79+
REMOVED=$(diff postype.go postype_generated.go | grep "^<" | wc -l || echo "0")
80+
echo "added=$ADDED" >> $GITHUB_OUTPUT
81+
echo "removed=$REMOVED" >> $GITHUB_OUTPUT
82+
83+
- name: Update files
84+
if: steps.extract.outputs.changed == 'true'
85+
run: |
86+
# Replace postype.go with generated version
87+
mv postype_generated.go postype.go
88+
89+
# Update Makefile version
90+
sed -i "s/KIWI_VERSION := .*/KIWI_VERSION := ${{ steps.get_version.outputs.version }}/" Makefile
91+
92+
- name: Create Pull Request
93+
if: steps.extract.outputs.changed == 'true'
94+
uses: peter-evans/create-pull-request@v7
95+
with:
96+
token: ${{ secrets.GITHUB_TOKEN }}
97+
commit-message: "sync: update POS tags from Kiwi ${{ steps.get_version.outputs.version }}"
98+
branch: sync/postypes-${{ steps.get_version.outputs.version }}
99+
delete-branch: true
100+
title: "sync: update POS tags from Kiwi ${{ steps.get_version.outputs.version }}"
101+
body: |
102+
## POS Tag Sync from Kiwi ${{ steps.get_version.outputs.version }}
103+
104+
This PR was automatically generated by the POS tag sync workflow.
105+
106+
### Changes
107+
- Added: ${{ steps.diff.outputs.added }} lines
108+
- Removed: ${{ steps.diff.outputs.removed }} lines
109+
110+
### Diff Summary
111+
```
112+
${{ steps.diff.outputs.diff }}
113+
```
114+
115+
### Verification
116+
- [ ] POS tags match C++ source
117+
- [ ] Tests pass
118+
- [ ] No breaking changes
119+
120+
---
121+
*This PR was created by [sync-postypes.yaml](.github/workflows/sync-postypes.yaml)*
122+
labels: |
123+
automated
124+
125+
- name: Summary
126+
if: always()
127+
run: |
128+
echo "## Sync Summary" >> $GITHUB_STEP_SUMMARY
129+
echo "- Kiwi Version: ${{ steps.get_version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
130+
echo "- Changes Detected: ${{ steps.extract.outputs.changed }}" >> $GITHUB_STEP_SUMMARY
131+
if [ "${{ steps.extract.outputs.changed }}" == "true" ]; then
132+
echo "- Added: ${{ steps.diff.outputs.added }} lines" >> $GITHUB_STEP_SUMMARY
133+
echo "- Removed: ${{ steps.diff.outputs.removed }} lines" >> $GITHUB_STEP_SUMMARY
134+
echo "- PR Created: Yes" >> $GITHUB_STEP_SUMMARY
135+
else
136+
echo "- Status: Already in sync" >> $GITHUB_STEP_SUMMARY
137+
fi

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@ models/
2323
include/
2424
ModelGenerator/
2525

26+
27+
# Python virtual environment
28+
.venv/

Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,23 @@ format:
2525
# go install mvdan.cc/gofumpt@latest
2626
gofumpt -l -w .
2727

28+
.PHONY: sync-postypes
29+
sync-postypes:
30+
@echo "Extracting POS tags from Kiwi $(KIWI_VERSION)..."
31+
source .venv/bin/activate && python scripts/extract_postags.py $(KIWI_VERSION)
32+
@echo "Generated postype_generated.go"
33+
@echo "Comparing with current postype.go..."
34+
@diff -u postype.go postype_generated.go || true
35+
@echo "To apply changes, run: mv postype_generated.go postype.go"
36+
37+
.PHONY: check-postypes
38+
check-postypes:
39+
@source .venv/bin/activate && python scripts/extract_postags.py $(KIWI_VERSION)
40+
@if diff -q postype.go postype_generated.go > /dev/null 2>&1; then \
41+
echo "POS types are in sync with Kiwi $(KIWI_VERSION)"; \
42+
else \
43+
echo "POS types are OUT OF SYNC with Kiwi $(KIWI_VERSION)"; \
44+
echo "Run 'make sync-postypes' to update"; \
45+
exit 1; \
46+
fi
47+

0 commit comments

Comments
 (0)