Skip to content

Commit 9c913cb

Browse files
committed
Fix TiUP cache to save updates when versions change
- Add dynamic cache key that includes TiDB versions hash - Cache key now includes workflow hash, go.mod hash, and TiDB versions hash - This ensures cache updates are saved when TiDB versions change - Both prepare-dependencies and tests jobs use same cache key for sharing - Cache automatically cleans up after 7 days (no explicit cleanup needed) Previously, static cache key caused 'not saving cache' on cache hits, preventing updates from being saved. Now cache properly invalidates and saves when versions change.
1 parent 295391f commit 9c913cb

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

.github/workflows/main.yml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,21 @@ jobs:
7575
- name: Vendor Go dependencies
7676
run: go mod vendor
7777

78+
- name: Generate TiDB versions hash
79+
id: tidb-versions-hash
80+
run: |
81+
echo "hash=$(echo '${{ env.TIDB_VERSIONS }}' | sha256sum | cut -d' ' -f1 | cut -c1-8)" >> $GITHUB_OUTPUT
82+
7883
- name: Cache TiUP components
84+
id: cache-tiup
7985
uses: actions/cache@v4
8086
with:
8187
path: |
8288
~/.tiup
83-
key: ${{ runner.os }}-tiup-components
89+
# Include workflow hash and TiDB versions hash in cache key so cache updates when versions change
90+
key: ${{ runner.os }}-tiup-${{ hashFiles('.github/workflows/main.yml') }}-${{ hashFiles('**/go.mod') }}-${{ steps.tidb-versions-hash.outputs.hash }}
8491
restore-keys: |
92+
${{ runner.os }}-tiup-${{ hashFiles('.github/workflows/main.yml') }}-${{ hashFiles('**/go.mod') }}-
8593
${{ runner.os }}-tiup-
8694
8795
- name: Install TiUP
@@ -188,14 +196,23 @@ jobs:
188196
sudo apt-get update -qq
189197
sudo apt-get install -y --no-install-recommends mysql-client
190198
199+
- name: Generate TiDB versions hash
200+
id: tidb-versions-hash-test
201+
if: contains(matrix.target, 'tidb')
202+
run: |
203+
echo "hash=$(echo '${{ env.TIDB_VERSIONS }}' | sha256sum | cut -d' ' -f1 | cut -c1-8)" >> $GITHUB_OUTPUT
204+
191205
- name: Cache TiUP components
206+
id: cache-tiup-test
192207
if: contains(matrix.target, 'tidb')
193208
uses: actions/cache@v4
194209
with:
195210
path: |
196211
~/.tiup
197-
key: ${{ runner.os }}-tiup-components
212+
# Use same cache key as prepare-dependencies job to share cache
213+
key: ${{ runner.os }}-tiup-${{ hashFiles('.github/workflows/main.yml') }}-${{ hashFiles('**/go.mod') }}-${{ steps.tidb-versions-hash-test.outputs.hash }}
198214
restore-keys: |
215+
${{ runner.os }}-tiup-${{ hashFiles('.github/workflows/main.yml') }}-${{ hashFiles('**/go.mod') }}-
199216
${{ runner.os }}-tiup-
200217
201218
- name: Install TiUP (if not cached)

0 commit comments

Comments
 (0)