|
| 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: Create Pull Request |
| 84 | + if: steps.extract.outputs.changed == 'true' |
| 85 | + uses: peter-evans/create-pull-request@v6 |
| 86 | + with: |
| 87 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 88 | + commit-message: "sync: update POS tags from Kiwi ${{ steps.get_version.outputs.version }}" |
| 89 | + branch: sync/postypes-${{ steps.get_version.outputs.version }} |
| 90 | + delete-branch: true |
| 91 | + title: "sync: update POS tags from Kiwi ${{ steps.get_version.outputs.version }}" |
| 92 | + body: | |
| 93 | + ## POS Tag Sync from Kiwi ${{ steps.get_version.outputs.version }} |
| 94 | +
|
| 95 | + This PR was automatically generated by the POS tag sync workflow. |
| 96 | +
|
| 97 | + ### Changes |
| 98 | + - Added: ${{ steps.extract.outputs.added }} lines |
| 99 | + - Removed: ${{ steps.extract.outputs.removed }} lines |
| 100 | +
|
| 101 | + ### Diff Summary |
| 102 | + ``` |
| 103 | + ${{ steps.diff.outputs.diff }} |
| 104 | + ``` |
| 105 | +
|
| 106 | + ### Verification |
| 107 | + - [ ] POS tags match C++ source |
| 108 | + - [ ] Tests pass |
| 109 | + - [ ] No breaking changes |
| 110 | +
|
| 111 | + --- |
| 112 | + *This PR was created by [sync-postypes.yaml](.github/workflows/sync-postypes.yaml)* |
| 113 | + labels: | |
| 114 | + sync |
| 115 | + automated |
| 116 | +
|
| 117 | + - name: Update Makefile version |
| 118 | + if: steps.extract.outputs.changed == 'true' |
| 119 | + run: | |
| 120 | + sed -i "s/KIWI_VERSION := .*/KIWI_VERSION := ${{ steps.get_version.outputs.version }}/" Makefile |
| 121 | +
|
| 122 | + - name: Commit and push changes |
| 123 | + if: steps.extract.outputs.changed == 'true' |
| 124 | + run: | |
| 125 | + git config user.name "github-actions[bot]" |
| 126 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 127 | +
|
| 128 | + # Replace postype.go with generated version |
| 129 | + mv postype_generated.go postype.go |
| 130 | +
|
| 131 | + # Stage changes |
| 132 | + git add postype.go Makefile |
| 133 | +
|
| 134 | + # Check if there are changes to commit |
| 135 | + if git diff --staged --quiet; then |
| 136 | + echo "No changes to commit" |
| 137 | + else |
| 138 | + git commit -m "sync: update POS tags from Kiwi ${{ steps.get_version.outputs.version }}" |
| 139 | + git push origin sync/postypes-${{ steps.get_version.outputs.version }} |
| 140 | + fi |
| 141 | +
|
| 142 | + - name: Create PR manually (fallback) |
| 143 | + if: steps.extract.outputs.changed == 'true' && failure() |
| 144 | + env: |
| 145 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 146 | + run: | |
| 147 | + # Fallback: create PR using gh CLI |
| 148 | + gh pr create \ |
| 149 | + --title "sync: update POS tags from Kiwi ${{ steps.get_version.outputs.version }}" \ |
| 150 | + --body "## POS Tag Sync from Kiwi ${{ steps.get_version.outputs.version }} |
| 151 | +
|
| 152 | + Automatically generated PR to sync POS tags with upstream Kiwi. |
| 153 | +
|
| 154 | + **Changes**: +${{ steps.extract.outputs.added }} -${{ steps.extract.outputs.removed }}" \ |
| 155 | + --label "sync,automated" \ |
| 156 | + --head sync/postypes-${{ steps.get_version.outputs.version }} \ |
| 157 | + --base main |
| 158 | +
|
| 159 | + - name: Summary |
| 160 | + if: always() |
| 161 | + run: | |
| 162 | + echo "## Sync Summary" >> $GITHUB_STEP_SUMMARY |
| 163 | + echo "- Kiwi Version: ${{ steps.get_version.outputs.version }}" >> $GITHUB_STEP_SUMMARY |
| 164 | + echo "- Changes Detected: ${{ steps.extract.outputs.changed }}" >> $GITHUB_STEP_SUMMARY |
| 165 | + if [ "${{ steps.extract.outputs.changed }}" == "true" ]; then |
| 166 | + echo "- Added: ${{ steps.extract.outputs.added }} lines" >> $GITHUB_STEP_SUMMARY |
| 167 | + echo "- Removed: ${{ steps.extract.outputs.removed }} lines" >> $GITHUB_STEP_SUMMARY |
| 168 | + echo "- PR Created: Yes" >> $GITHUB_STEP_SUMMARY |
| 169 | + else |
| 170 | + echo "- Status: Already in sync" >> $GITHUB_STEP_SUMMARY |
| 171 | + fi |
0 commit comments