Sync POS Tags from Kiwi Upstream #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| echo "version=${{ github.event.inputs.kiwi_version }}" >> $GITHUB_OUTPUT | |
| else | |
| # Get latest release from GitHub API | |
| VERSION=$(curl -s https://api.github.com/repos/bab2min/Kiwi/releases/latest | jq -r '.tag_name') | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| fi | |
| echo "Kiwi version: $(cat $GITHUB_OUTPUT | grep version | cut -d= -f2)" | |
| - 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: Create Pull Request | |
| if: steps.extract.outputs.changed == 'true' | |
| uses: peter-evans/create-pull-request@v6 | |
| 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.extract.outputs.added }} lines | |
| - Removed: ${{ steps.extract.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: | | |
| sync | |
| automated | |
| - name: Update Makefile version | |
| if: steps.extract.outputs.changed == 'true' | |
| run: | | |
| sed -i "s/KIWI_VERSION := .*/KIWI_VERSION := ${{ steps.get_version.outputs.version }}/" Makefile | |
| - name: Commit and push changes | |
| if: steps.extract.outputs.changed == 'true' | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| # Replace postype.go with generated version | |
| mv postype_generated.go postype.go | |
| # Stage changes | |
| git add postype.go Makefile | |
| # Check if there are changes to commit | |
| if git diff --staged --quiet; then | |
| echo "No changes to commit" | |
| else | |
| git commit -m "sync: update POS tags from Kiwi ${{ steps.get_version.outputs.version }}" | |
| git push origin sync/postypes-${{ steps.get_version.outputs.version }} | |
| fi | |
| - name: Create PR manually (fallback) | |
| if: steps.extract.outputs.changed == 'true' && failure() | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| # Fallback: create PR using gh CLI | |
| gh pr create \ | |
| --title "sync: update POS tags from Kiwi ${{ steps.get_version.outputs.version }}" \ | |
| --body "## POS Tag Sync from Kiwi ${{ steps.get_version.outputs.version }} | |
| Automatically generated PR to sync POS tags with upstream Kiwi. | |
| **Changes**: +${{ steps.extract.outputs.added }} -${{ steps.extract.outputs.removed }}" \ | |
| --label "sync,automated" \ | |
| --head sync/postypes-${{ steps.get_version.outputs.version }} \ | |
| --base main | |
| - 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.extract.outputs.added }} lines" >> $GITHUB_STEP_SUMMARY | |
| echo "- Removed: ${{ steps.extract.outputs.removed }} lines" >> $GITHUB_STEP_SUMMARY | |
| echo "- PR Created: Yes" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "- Status: Already in sync" >> $GITHUB_STEP_SUMMARY | |
| fi |