Update syntax grammars #25
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: Update syntax grammars | |
| on: | |
| schedule: | |
| - cron: "0 9 * * 1" # every Monday at 09:00 UTC | |
| workflow_dispatch: | |
| jobs: | |
| update-grammars: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 | |
| - name: Create GitHub App Token | |
| uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1 | |
| id: app-token | |
| with: | |
| client-id: ${{ vars.PR_AUTOMATION_BOT_PUBLIC_CLIENT_ID }} | |
| private-key: ${{ secrets.PR_AUTOMATION_BOT_PUBLIC_PRIVATE_KEY }} | |
| - name: Fetch latest vscode-motoko release | |
| id: release | |
| env: | |
| GH_TOKEN: ${{ steps.app-token.outputs.token }} | |
| run: | | |
| tag=$(gh api repos/dfinity/vscode-motoko/releases/latest --jq '.tag_name') | |
| echo "tag=$tag" >> "$GITHUB_OUTPUT" | |
| echo "Latest vscode-motoko release: $tag" | |
| - name: Check if PR already exists for this release | |
| id: existing | |
| env: | |
| GH_TOKEN: ${{ steps.app-token.outputs.token }} | |
| run: | | |
| tag="${{ steps.release.outputs.tag }}" | |
| branch="chore/update-syntax-grammars-${tag}" | |
| count=$(gh pr list --head "$branch" --state all --json number --jq 'length') | |
| if [ "$count" -gt 0 ]; then | |
| echo "skip=true" >> "$GITHUB_OUTPUT" | |
| echo "PR already exists for ${tag}, skipping." | |
| else | |
| echo "skip=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Download and convert grammars | |
| if: steps.existing.outputs.skip == 'false' | |
| run: | | |
| tag="${{ steps.release.outputs.tag }}" | |
| for file in Major.tmLanguage Candid.tmLanguage; do | |
| curl -fsSL "https://raw.githubusercontent.com/dfinity/vscode-motoko/${tag}/syntaxes/${file}" \ | |
| -o "/tmp/${file}" | |
| done | |
| python3 <<'PYEOF' | |
| import plistlib, json, pathlib | |
| for src, dest in [ | |
| ("/tmp/Major.tmLanguage", "syntaxes/motoko.tmLanguage.json"), | |
| ("/tmp/Candid.tmLanguage", "syntaxes/candid.tmLanguage.json"), | |
| ]: | |
| with open(src, "rb") as f: | |
| data = plistlib.load(f) | |
| pathlib.Path(dest).write_text( | |
| json.dumps(data, indent=2, ensure_ascii=False) + "\n" | |
| ) | |
| print(f"Converted {src} -> {dest}") | |
| PYEOF | |
| - name: Check for changes | |
| if: steps.existing.outputs.skip == 'false' | |
| id: diff | |
| run: | | |
| if git diff --quiet syntaxes/; then | |
| echo "changed=false" >> "$GITHUB_OUTPUT" | |
| echo "No grammar changes detected." | |
| else | |
| echo "changed=true" >> "$GITHUB_OUTPUT" | |
| echo "Grammar changes detected:" | |
| git diff --stat syntaxes/ | |
| fi | |
| - name: Create pull request | |
| if: steps.existing.outputs.skip == 'false' && steps.diff.outputs.changed == 'true' | |
| env: | |
| GH_TOKEN: ${{ steps.app-token.outputs.token }} | |
| run: | | |
| tag="${{ steps.release.outputs.tag }}" | |
| branch="chore/update-syntax-grammars-${tag}" | |
| git config user.name "pr-automation-bot-public[bot]" | |
| git config user.email "pr-automation-bot-public[bot]@users.noreply.github.com" | |
| git checkout -b "$branch" | |
| git add syntaxes/ | |
| git commit -m "chore: update Motoko and Candid grammars to vscode-motoko ${tag}" | |
| git push -u origin "$branch" | |
| body=$(cat <<EOF | |
| ## Summary | |
| Updates Motoko and Candid TextMate grammars to [vscode-motoko ${tag}](https://github.com/dfinity/vscode-motoko/releases/tag/${tag}). | |
| These grammars power syntax highlighting for \`\`\`motoko\`\`\` and \`\`\`candid\`\`\` code blocks via Shiki / Expressive Code. | |
| **Source:** \`dfinity/vscode-motoko\` → \`syntaxes/Major.tmLanguage\` and \`syntaxes/Candid.tmLanguage\` | |
| **Transformation:** plist XML → JSON (automated by this workflow) | |
| ## Test plan | |
| - [ ] Verify \`npm run build\` passes | |
| - [ ] Spot-check Motoko syntax highlighting on a page with code blocks (e.g., timers guide) | |
| EOF | |
| ) | |
| gh pr create \ | |
| --title "chore: update syntax grammars to vscode-motoko ${tag}" \ | |
| --body "$body" |