|
| 1 | +name: Verify TinyTeX Pattern Coverage |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '0 2 * * *' # Daily 2am UTC (matches TinyTeX daily release) |
| 6 | + workflow_dispatch: # Manual trigger for testing |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: read |
| 10 | + issues: write |
| 11 | + actions: write |
| 12 | + |
| 13 | +jobs: |
| 14 | + verify: |
| 15 | + name: Check TinyTeX Pattern Updates |
| 16 | + runs-on: ubuntu-latest |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Checkout repository |
| 20 | + uses: actions/checkout@v4 |
| 21 | + |
| 22 | + - name: Download and extract regex.json |
| 23 | + env: |
| 24 | + GH_TOKEN: ${{ github.token }} |
| 25 | + run: | |
| 26 | + if ! gh release download daily --repo rstudio/tinytex-releases --pattern "regex.tar.gz"; then |
| 27 | + echo "::warning::Failed to download TinyTeX daily release - may not be published yet" |
| 28 | + exit 0 |
| 29 | + fi |
| 30 | + tar -xzf regex.tar.gz |
| 31 | + echo "✓ Downloaded and extracted regex.json" |
| 32 | +
|
| 33 | + - name: Restore cached regex.json |
| 34 | + id: cache-restore |
| 35 | + uses: actions/cache/restore@v4 |
| 36 | + with: |
| 37 | + path: .cache/regex.json |
| 38 | + key: tinytex-regex-latest |
| 39 | + |
| 40 | + - name: Compare versions |
| 41 | + id: compare |
| 42 | + run: | |
| 43 | + if [ -f .cache/regex.json ]; then |
| 44 | + if git diff --no-index --quiet .cache/regex.json regex.json; then |
| 45 | + echo "changed=false" >> $GITHUB_OUTPUT |
| 46 | + echo "first_run=false" >> $GITHUB_OUTPUT |
| 47 | + echo "✓ No changes detected" |
| 48 | + else |
| 49 | + echo "changed=true" >> $GITHUB_OUTPUT |
| 50 | + echo "first_run=false" >> $GITHUB_OUTPUT |
| 51 | + echo "✗ Changes detected" |
| 52 | + git diff --no-index .cache/regex.json regex.json > pattern-diff.txt || true |
| 53 | + fi |
| 54 | + else |
| 55 | + echo "changed=false" >> $GITHUB_OUTPUT |
| 56 | + echo "first_run=true" >> $GITHUB_OUTPUT |
| 57 | + echo "⚠ No cached version (first run)" |
| 58 | + fi |
| 59 | +
|
| 60 | + - name: Handle first run |
| 61 | + if: steps.compare.outputs.first_run == 'true' |
| 62 | + env: |
| 63 | + GH_TOKEN: ${{ github.token }} |
| 64 | + run: | |
| 65 | + # Get tinytex commit SHA |
| 66 | + TINYTEX_COMMIT=$(gh api repos/rstudio/tinytex/commits/main --jq '.sha') |
| 67 | + TINYTEX_SHORT=$(echo $TINYTEX_COMMIT | cut -c1-7) |
| 68 | +
|
| 69 | + # Count patterns and categories |
| 70 | + PATTERN_COUNT=$(jq '[.[] | length] | add' regex.json) |
| 71 | + CATEGORY_COUNT=$(jq 'keys | length' regex.json) |
| 72 | +
|
| 73 | + # Write GitHub Actions summary |
| 74 | + echo "## TinyTeX Pattern Baseline Established" >> "$GITHUB_STEP_SUMMARY" |
| 75 | + echo "" >> "$GITHUB_STEP_SUMMARY" |
| 76 | + echo "- **Date:** $(date +%Y-%m-%d)" >> "$GITHUB_STEP_SUMMARY" |
| 77 | + echo "- **TinyTeX commit:** [\`$TINYTEX_SHORT\`](https://github.com/rstudio/tinytex/commit/$TINYTEX_COMMIT)" >> "$GITHUB_STEP_SUMMARY" |
| 78 | + echo "- **Pattern source:** [R/latex.R](https://github.com/rstudio/tinytex/blob/$TINYTEX_COMMIT/R/latex.R)" >> "$GITHUB_STEP_SUMMARY" |
| 79 | + echo "- **Baseline:** $PATTERN_COUNT patterns across $CATEGORY_COUNT categories" >> "$GITHUB_STEP_SUMMARY" |
| 80 | + echo "- **Cache key:** tinytex-regex-latest" >> "$GITHUB_STEP_SUMMARY" |
| 81 | + echo "" >> "$GITHUB_STEP_SUMMARY" |
| 82 | + echo "No issue created (first run - baseline established)." >> "$GITHUB_STEP_SUMMARY" |
| 83 | +
|
| 84 | + # Prepare cache directory |
| 85 | + mkdir -p .cache |
| 86 | + cp regex.json .cache/regex.json |
| 87 | +
|
| 88 | + echo "✓ Baseline established - cache will be saved" |
| 89 | +
|
| 90 | + - name: Exit if unchanged |
| 91 | + if: steps.compare.outputs.changed == 'false' && steps.compare.outputs.first_run == 'false' |
| 92 | + run: | |
| 93 | + echo "No pattern changes detected. Cache hit - exiting." |
| 94 | + exit 0 |
| 95 | +
|
| 96 | + - name: Prepare readable diff |
| 97 | + if: steps.compare.outputs.changed == 'true' |
| 98 | + run: | |
| 99 | + # Pretty-print both JSON files for readable diff |
| 100 | + if [ -f .cache/regex.json ]; then |
| 101 | + jq --sort-keys . .cache/regex.json > old-formatted.json |
| 102 | + jq --sort-keys . regex.json > new-formatted.json |
| 103 | + git diff --no-index old-formatted.json new-formatted.json > readable-diff.txt || true |
| 104 | + else |
| 105 | + jq --sort-keys . regex.json > new-formatted.json |
| 106 | + echo "First run - no previous version to compare" > readable-diff.txt |
| 107 | + fi |
| 108 | +
|
| 109 | + - name: Create or update issue |
| 110 | + if: steps.compare.outputs.changed == 'true' |
| 111 | + env: |
| 112 | + GH_TOKEN: ${{ github.token }} |
| 113 | + run: | |
| 114 | + ISSUE_TITLE="TinyTeX patterns require review" |
| 115 | + CURRENT_DATE=$(date +%Y-%m-%d) |
| 116 | +
|
| 117 | + # Search for existing open issue |
| 118 | + ISSUE_NUM=$(gh issue list \ |
| 119 | + --label "tinytex-patterns" \ |
| 120 | + --state open \ |
| 121 | + --json number,title \ |
| 122 | + --jq ".[] | select(.title == \"$ISSUE_TITLE\") | .number") |
| 123 | +
|
| 124 | + if [ -z "$ISSUE_NUM" ]; then |
| 125 | + echo "No matching issue found, creating new one..." |
| 126 | +
|
| 127 | + # Use template and replace placeholders |
| 128 | + sed "s|{{DATE}}|$CURRENT_DATE|g" .github/workflows/templates/tinytex-issue-body.md | \ |
| 129 | + sed -e "/{{DIFF}}/r readable-diff.txt" -e "/{{DIFF}}/d" > issue-body.md |
| 130 | +
|
| 131 | + gh issue create \ |
| 132 | + --title "$ISSUE_TITLE" \ |
| 133 | + --assignee cderv \ |
| 134 | + --label "tinytex-patterns" \ |
| 135 | + --body-file issue-body.md |
| 136 | + else |
| 137 | + echo "Found existing issue #$ISSUE_NUM, adding comment..." |
| 138 | +
|
| 139 | + # Use template and replace placeholders |
| 140 | + sed "s|{{DATE}}|$CURRENT_DATE|g" .github/workflows/templates/tinytex-comment-body.md | \ |
| 141 | + sed -e "/{{DIFF}}/r readable-diff.txt" -e "/{{DIFF}}/d" > comment-body.md |
| 142 | +
|
| 143 | + gh issue comment "$ISSUE_NUM" --body-file comment-body.md |
| 144 | + fi |
| 145 | +
|
| 146 | + - name: Update cache with new patterns |
| 147 | + if: steps.compare.outputs.changed == 'true' |
| 148 | + run: | |
| 149 | + mkdir -p .cache |
| 150 | + cp regex.json .cache/regex.json |
| 151 | + echo "✓ Cache updated with new patterns" |
| 152 | +
|
| 153 | + - name: Delete old cache |
| 154 | + if: steps.compare.outputs.changed == 'true' |
| 155 | + continue-on-error: true |
| 156 | + env: |
| 157 | + GH_TOKEN: ${{ github.token }} |
| 158 | + run: | |
| 159 | + gh cache delete tinytex-regex-latest || echo "No existing cache to delete" |
| 160 | +
|
| 161 | + - name: Save new cache |
| 162 | + if: steps.compare.outputs.changed == 'true' || steps.compare.outputs.first_run == 'true' |
| 163 | + uses: actions/cache/save@v4 |
| 164 | + with: |
| 165 | + path: .cache/regex.json |
| 166 | + key: tinytex-regex-latest |
| 167 | + |
| 168 | + - name: Summary |
| 169 | + if: always() |
| 170 | + run: | |
| 171 | + if [ "${{ steps.compare.outputs.first_run }}" == "true" ]; then |
| 172 | + echo "✓ Baseline established - cache created" |
| 173 | + elif [ "${{ steps.compare.outputs.changed }}" == "true" ]; then |
| 174 | + echo "✗ Pattern changes detected - issue created/updated" |
| 175 | + else |
| 176 | + echo "✓ No pattern changes - cache hit" |
| 177 | + fi |
0 commit comments