Skip to content

Sync POS Tags from Kiwi Upstream #7

Sync POS Tags from Kiwi Upstream

Sync POS Tags from Kiwi Upstream #7

name: Sync POS Tags from Kiwi Upstream
on:
schedule:
# Run weekly on Monday at 9:00 AM UTC
- cron: '0 9 * * 1'
workflow_dispatch:
inputs:
kiwi_version:
description: 'Kiwi version to sync (e.g., v0.23.2)'
required: false
default: ''
permissions:
contents: write
pull-requests: write
jobs:
check-and-sync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Install Go
uses: actions/setup-go@v7
with:
go-version-file: go.mod
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies
run: |
python -m venv .venv
source .venv/bin/activate
pip install tree-sitter tree-sitter-cpp
- name: Get latest Kiwi version
id: get_version
run: |
if [ -n "${{ github.event.inputs.kiwi_version }}" ]; then
VERSION="${{ github.event.inputs.kiwi_version }}"
else
# Get latest release from GitHub API
VERSION=$(curl -s https://api.github.com/repos/bab2min/Kiwi/releases/latest | jq -r '.tag_name')
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Kiwi version: $VERSION"
- name: Extract POS tags
id: extract
run: |
source .venv/bin/activate
python scripts/extract_postags.py ${{ steps.get_version.outputs.version }}
# Check if there are changes
if diff -q postype.go postype_generated.go > /dev/null 2>&1; then
echo "changed=false" >> $GITHUB_OUTPUT
echo "No changes detected"
else
echo "changed=true" >> $GITHUB_OUTPUT
echo "Changes detected"
fi
- name: Generate diff summary
if: steps.extract.outputs.changed == 'true'
id: diff
run: |
# Generate diff summary
DIFF=$(diff -u postype.go postype_generated.go || true)
echo "diff<<EOF" >> $GITHUB_OUTPUT
echo "$DIFF" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
# Count changes
ADDED=$(diff postype.go postype_generated.go | grep "^>" | wc -l || echo "0")
REMOVED=$(diff postype.go postype_generated.go | grep "^<" | wc -l || echo "0")
echo "added=$ADDED" >> $GITHUB_OUTPUT
echo "removed=$REMOVED" >> $GITHUB_OUTPUT
- name: Update files
if: steps.extract.outputs.changed == 'true'
run: |
# Replace postype.go with generated version
mv postype_generated.go postype.go
# Update Makefile version
sed -i "s/KIWI_VERSION := .*/KIWI_VERSION := ${{ steps.get_version.outputs.version }}/" Makefile
# PRs opened with GITHUB_TOKEN do not trigger CI, so the generated code is
# verified here instead. Without this a non-compiling postype.go can be
# proposed and merged unnoticed.
- name: Verify generated code
if: steps.extract.outputs.changed == 'true'
run: |
make install-kiwi
make test
- name: Create Pull Request
if: steps.extract.outputs.changed == 'true'
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "sync: update POS tags from Kiwi ${{ steps.get_version.outputs.version }}"
branch: sync/postypes-${{ steps.get_version.outputs.version }}
delete-branch: true
title: "sync: update POS tags from Kiwi ${{ steps.get_version.outputs.version }}"
body: |
## POS Tag Sync from Kiwi ${{ steps.get_version.outputs.version }}
This PR was automatically generated by the POS tag sync workflow.
### Changes
- Added: ${{ steps.diff.outputs.added }} lines
- Removed: ${{ steps.diff.outputs.removed }} lines
### Diff Summary
```
${{ steps.diff.outputs.diff }}
```
### Verification
- [ ] POS tags match C++ source
- [ ] Tests pass
- [ ] No breaking changes
---
*This PR was created by [sync-postypes.yaml](.github/workflows/sync-postypes.yaml)*
labels: |
automated
- name: Summary
if: always()
run: |
echo "## Sync Summary" >> $GITHUB_STEP_SUMMARY
echo "- Kiwi Version: ${{ steps.get_version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "- Changes Detected: ${{ steps.extract.outputs.changed }}" >> $GITHUB_STEP_SUMMARY
if [ "${{ steps.extract.outputs.changed }}" == "true" ]; then
echo "- Added: ${{ steps.diff.outputs.added }} lines" >> $GITHUB_STEP_SUMMARY
echo "- Removed: ${{ steps.diff.outputs.removed }} lines" >> $GITHUB_STEP_SUMMARY
echo "- PR Created: Yes" >> $GITHUB_STEP_SUMMARY
else
echo "- Status: Already in sync" >> $GITHUB_STEP_SUMMARY
fi