Skip to content

Commit 9e70dd8

Browse files
committed
Calculate fallback key
1 parent bf7fcb1 commit 9e70dd8

4 files changed

Lines changed: 16 additions & 18 deletions

File tree

.github/workflows/test.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ jobs:
1818
runs-on: ubuntu-latest
1919
outputs:
2020
cache-key: ${{ steps.create-and-cache.outputs.cache-key }}
21-
fallback-key: ${{ steps.create-and-cache.outputs.fallback-key }}
2221
pixi-version: ${{ steps.create-and-cache.outputs.pixi-version }}
2322
steps:
2423
- name: Checkout repository
@@ -67,7 +66,6 @@ jobs:
6766
uses: ./pixi-lock/restore
6867
with:
6968
cache-key: ${{ needs.cache-pixi-lock.outputs.cache-key }}
70-
fallback-key: ${{ needs.cache-pixi-lock.outputs.fallback-key }}
7169

7270
- name: Verify pixi.lock exists
7371
shell: bash

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ jobs:
1919
runs-on: ubuntu-latest
2020
outputs:
2121
cache-key: ${{ steps.pixi-lock.outputs.cache-key }}
22-
fallback-key: ${{ steps.pixi-lock.outputs.fallback-key }}
2322
pixi-version: ${{ steps.pixi-lock.outputs.pixi-version }}
2423
steps:
2524
- uses: actions/checkout@v4
@@ -39,7 +38,6 @@ jobs:
3938
- uses: Parcels-code/pixi-lock/restore@v1
4039
with:
4140
cache-key: ${{ needs.cache-pixi-lock.outputs.cache-key }}
42-
fallback-key: ${{ needs.cache-pixi-lock.outputs.fallback-key }}
4341
- uses: prefix-dev/setup-pixi@v0.9.3
4442
with:
4543
pixi-version: ${{ needs.cache-pixi-lock.outputs.pixi-version }}
@@ -58,18 +56,16 @@ jobs:
5856
|--------|-------------|
5957
| `pixi-version` | The pixi version used |
6058
| `cache-key` | The cache key (includes today's date) |
61-
| `fallback-key` | The fallback cache key (yesterday's date) |
6259

6360
#### `restore`
6461

6562
| Input | Description | Required |
6663
|-------|-------------|----------|
6764
| `cache-key` | The cache key from `create-and-cache` | Yes |
68-
| `fallback-key` | The fallback cache key from `create-and-cache` | Yes |
6965

7066
> [!NOTE]
7167
> The cache key includes the current date, so the lock file is regenerated daily.
72-
> The fallback key handles edge cases where the restore job runs just after midnight.
68+
> The fallback key (yesterday's date) is calculated automatically to handle edge cases where the restore job runs just after midnight.
7369
7470
## Why not commit the lock file?
7571

create-and-cache/action.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ outputs:
1414
cache-key:
1515
description: "The cache key used"
1616
value: ${{ steps.cache-key.outputs.key }}
17-
fallback-key:
18-
description: "The fallback cache key (yesterday's date)"
19-
value: ${{ steps.cache-key.outputs.fallback-key }}
2017

2118
runs:
2219
using: "composite"
@@ -26,10 +23,8 @@ runs:
2623
shell: bash
2724
run: |
2825
today=$(date +'%Y-%m-%d')
29-
yesterday=$(date -d 'yesterday' +'%Y-%m-%d' 2>/dev/null || date -v-1d +'%Y-%m-%d')
30-
base="pixi-lock_${{ inputs.pixi-version }}_${{ hashFiles('pixi.toml') }}"
31-
echo "key=${base}_${today}" >> "$GITHUB_OUTPUT"
32-
echo "fallback-key=${base}_${yesterday}" >> "$GITHUB_OUTPUT"
26+
key="pixi-lock_${{ inputs.pixi-version }}_${{ hashFiles('pixi.toml') }}_${today}"
27+
echo "key=${key}" >> "$GITHUB_OUTPUT"
3328
3429
- name: Restore pixi.lock from cache
3530
uses: actions/cache/restore@v5

restore/action.yml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,28 @@ inputs:
55
cache-key:
66
description: "The cache key from create-and-cache"
77
required: true
8-
fallback-key:
9-
description: "The fallback cache key from create-and-cache (for midnight edge cases)"
10-
required: true
118

129
runs:
1310
using: "composite"
1411
steps:
12+
- name: Calculate fallback key
13+
id: fallback
14+
shell: bash
15+
run: |
16+
cache_key="${{ inputs.cache-key }}"
17+
# Extract base (everything before the last _) and date (after the last _)
18+
base="${cache_key%_*}"
19+
current_date="${cache_key##*_}"
20+
# Calculate yesterday's date
21+
yesterday=$(date -d "${current_date} - 1 day" +'%Y-%m-%d' 2>/dev/null || date -j -f '%Y-%m-%d' -v-1d "${current_date}" +'%Y-%m-%d')
22+
echo "key=${base}_${yesterday}" >> "$GITHUB_OUTPUT"
23+
1524
- name: Restore pixi.lock from cache
1625
uses: actions/cache/restore@v5
1726
id: restore
1827
with:
1928
path: pixi.lock
2029
key: ${{ inputs.cache-key }}
2130
restore-keys: |
22-
${{ inputs.fallback-key }}
31+
${{ steps.fallback.outputs.key }}
2332
fail-on-cache-miss: true

0 commit comments

Comments
 (0)