Repository navigation
215 lines (188 loc) · 7.99 KB
/
Copy pathverify-tinytex-patterns.yml
File metadata and controls
215 lines (188 loc) · 7.99 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
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 and hyphen.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
# Files compared by the later steps
PATTERN_FILES="regex.json hyphen.json"
if [ ! -f hyphen.json ]; then
echo "::warning::hyphen.json not found in regex.tar.gz"
PATTERN_FILES="regex.json"
fi
echo "PATTERN_FILES=$PATTERN_FILES" >> "$GITHUB_ENV"
echo "✓ Downloaded and extracted: $PATTERN_FILES"
- name: Restore cached patterns
id: cache-restore
uses: actions/cache/restore@v5
with:
path: .cache
key: tinytex-patterns
- name: Compare versions
id: compare
run: |
# The download step sets PATTERN_FILES only when it extracted the files
if [ -z "${PATTERN_FILES:-}" ]; then
echo "changed=false" >> $GITHUB_OUTPUT
echo "first_run=false" >> $GITHUB_OUTPUT
echo "skipped=true" >> $GITHUB_OUTPUT
echo "::warning::No pattern files downloaded - comparison skipped"
exit 0
fi
if [ ! -f .cache/regex.json ]; then
echo "changed=false" >> $GITHUB_OUTPUT
echo "first_run=true" >> $GITHUB_OUTPUT
echo "⚠ No cached version (first run)"
exit 0
fi
changed=false
for f in $PATTERN_FILES; do
if [ ! -f ".cache/$f" ]; then
echo "✗ $f has no cached version"
changed=true
elif ! git diff --no-index --quiet ".cache/$f" "$f"; then
echo "✗ Changes detected in $f"
changed=true
fi
done
echo "changed=$changed" >> $GITHUB_OUTPUT
echo "first_run=false" >> $GITHUB_OUTPUT
if [ "$changed" = "false" ]; then
echo "✓ No changes detected"
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)
# A checked assignment: invalid JSON must fail the step before it is cached
if [ -f hyphen.json ]; then
HYPHEN_COUNT=$(jq 'length' hyphen.json)
fi
# 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"
if [ -f hyphen.json ]; then
echo "- **Hyphenation map:** $HYPHEN_COUNT names" >> "$GITHUB_STEP_SUMMARY"
fi
echo "- **Cache key:** tinytex-patterns" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "No issue created (first run - baseline established)." >> "$GITHUB_STEP_SUMMARY"
# Prepare cache directory
mkdir -p .cache
for f in $PATTERN_FILES; do
cp "$f" ".cache/$f"
done
echo "✓ Baseline established - cache will be saved"
- name: Exit if unchanged
if: steps.compare.outputs.changed == 'false' && steps.compare.outputs.first_run == 'false' && steps.compare.outputs.skipped != 'true'
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 versions of each file for a readable diff
: > readable-diff.txt
for f in $PATTERN_FILES; do
if [ -f ".cache/$f" ]; then
jq --sort-keys . ".cache/$f" > "old-formatted-$f"
else
old="/dev/null"
fi
jq --sort-keys . "$f" > "new-formatted-$f"
git diff --no-index "${old:-old-formatted-$f}" "new-formatted-$f" >> readable-diff.txt || true
unset old
done
- 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
for f in $PATTERN_FILES; do
cp "$f" ".cache/$f"
done
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-patterns || 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
key: tinytex-patterns
- name: Summary
if: always()
run: |
if [ "${{ steps.compare.outputs.skipped }}" == "true" ]; then
echo "⚠ Download failed - comparison skipped"
elif [ "${{ 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