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