Skip to content

Commit 4c4afcc

Browse files
authored
ci: cache rg/fd binaries with weekly rotation (#208)
## Summary - Adds `actions/cache@v4` for `.local/bin/rg` and `.local/bin/fd` with weekly-rotating keys (matches the nightly Neovim cache pattern at lines 161 of `pr-check.yml`) - Authenticates the `api.github.com/.../releases/latest` calls with `GITHUB_TOKEN` so we get the per-repo 1000/hr rate limit instead of the shared 60/hr per-IP unauthenticated limit (this was causing the v0.11.5 `tar: gzip: stdin: not in gzip format` failure on PR #207 when the unauth IP limit was hit and the API returned a JSON error in place of the asset URL) - Replaces `grep | cut | head` URL extraction with `jq` for cleaner JSON parsing and proper failure modes (`curl -sfL` now exits non-zero on HTTP errors instead of piping garbage into `tar`) - Adds `permissions: contents: read` at the workflow level for defense-in-depth
1 parent 7336e59 commit 4c4afcc

1 file changed

Lines changed: 45 additions & 17 deletions

File tree

.github/workflows/pr-check.yml

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ concurrency:
2828
group: ${{ github.workflow }}-${{ github.ref }}
2929
cancel-in-progress: true
3030

31+
permissions:
32+
contents: read
33+
3134
env:
3235
LUALS_VERSION: 3.16.2
3336
STYLUA_VERSION: 2.3.1
@@ -104,26 +107,51 @@ jobs:
104107
id: week
105108
run: echo "week=$(date +%Y-%W)" >> "$GITHUB_OUTPUT"
106109

107-
- name: Install system dependencies
108-
run: |
109-
# Install newer versions of rg and fd for unit tests
110-
curl -sL "$(curl -s https://api.github.com/repos/BurntSushi/ripgrep/releases/latest \
111-
| grep "browser_download_url.*x86_64-unknown-linux-musl.tar.gz" \
112-
| cut -d '"' -f 4 | head -n1)" \
113-
| tar -xz -C /usr/local/bin --strip-components=1 --wildcards '*/rg'
114-
chmod +x /usr/local/bin/rg
115-
116-
echo "[DEBUG] RG version: $(rg --version) from '$(which rg)' \n"
117-
118-
curl -sL "$(curl -s https://api.github.com/repos/sharkdp/fd/releases/latest | grep "browser_download_url.*fd-.*-x86_64-unknown-linux-gnu\.tar\.gz" | cut -d '"' -f 4)" \
119-
| tar -xz -C /usr/local/bin --strip-components=1 --wildcards '*/fd'
120-
chmod +x /usr/local/bin/fd
121-
122-
echo "[DEBUG] FD version: $(fd --version) from '$(which fd)' \n"
123-
124110
- name: Setup directories
125111
run: mkdir -p .local/nvim .local/bin
126112

113+
- name: Cache ripgrep
114+
id: cache-rg
115+
uses: actions/cache@v4
116+
with:
117+
path: .local/bin/rg
118+
# Weekly rotation - tracks `latest` upstream
119+
key: rg-${{ runner.os }}-${{ steps.week.outputs.week }}
120+
121+
- name: Install ripgrep
122+
if: steps.cache-rg.outputs.cache-hit != 'true'
123+
env:
124+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
125+
run: |
126+
url=$(curl -sfL \
127+
-H "Authorization: Bearer $GH_TOKEN" \
128+
-H "Accept: application/vnd.github+json" \
129+
https://api.github.com/repos/BurntSushi/ripgrep/releases/latest \
130+
| jq -r '[.assets[] | select(.name | endswith("x86_64-unknown-linux-musl.tar.gz")) | .browser_download_url] | .[0]')
131+
curl -sfL "$url" | tar -xz -C .local/bin --strip-components=1 --wildcards '*/rg'
132+
chmod +x .local/bin/rg
133+
134+
- name: Cache fd
135+
id: cache-fd
136+
uses: actions/cache@v4
137+
with:
138+
path: .local/bin/fd
139+
# Weekly rotation - tracks `latest` upstream
140+
key: fd-${{ runner.os }}-${{ steps.week.outputs.week }}
141+
142+
- name: Install fd
143+
if: steps.cache-fd.outputs.cache-hit != 'true'
144+
env:
145+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
146+
run: |
147+
url=$(curl -sfL \
148+
-H "Authorization: Bearer $GH_TOKEN" \
149+
-H "Accept: application/vnd.github+json" \
150+
https://api.github.com/repos/sharkdp/fd/releases/latest \
151+
| jq -r '[.assets[] | select(.name | endswith("x86_64-unknown-linux-gnu.tar.gz")) | .browser_download_url] | .[0]')
152+
curl -sfL "$url" | tar -xz -C .local/bin --strip-components=1 --wildcards '*/fd'
153+
chmod +x .local/bin/fd
154+
127155
- name: Cache Neovim
128156
id: cache-neovim
129157
uses: actions/cache@v4

0 commit comments

Comments
 (0)