Skip to content

Commit 3976801

Browse files
Add hash-files argument to create-and-cache action (#15)
1 parent 9a2866f commit 3976801

7 files changed

Lines changed: 130 additions & 42 deletions

File tree

.github/workflows/test.yml

Lines changed: 65 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ concurrency:
1010
group: ${{ github.workflow }}-${{ github.ref }}
1111
cancel-in-progress: true
1212

13-
env:
14-
PIXI_VERSION: "v0.63.0"
15-
1613
jobs:
1714
clear-cache:
1815
runs-on: ubuntu-slim
@@ -44,12 +41,48 @@ jobs:
4441
fi
4542
echo "Cache cleared"
4643
47-
cache-pixi-lock:
44+
test-cache-restore-install:
4845
needs: clear-cache
49-
runs-on: ubuntu-slim
50-
outputs:
51-
cache-key: ${{ steps.create-and-cache.outputs.cache-key }}
52-
pixi-version: ${{ steps.create-and-cache.outputs.pixi-version }}
46+
runs-on: ${{ matrix.os }}
47+
strategy:
48+
fail-fast: false
49+
matrix:
50+
include:
51+
# Test OS values with fixed test-folder and pixi-version
52+
- os: ubuntu-latest
53+
test-folder: just-pixi-toml
54+
expected-hash: "pixi-lock__69110db0bf39d7ce64fd774c7078ccd56ebf8542d9a1e86f84e63011634dc43f_2026-02-24"
55+
pixi-version: ""
56+
- os: macos-latest
57+
test-folder: just-pixi-toml
58+
expected-hash: "pixi-lock__69110db0bf39d7ce64fd774c7078ccd56ebf8542d9a1e86f84e63011634dc43f_2026-02-24"
59+
pixi-version: ""
60+
- os: windows-latest
61+
test-folder: just-pixi-toml
62+
expected-hash: "pixi-lock__adbacdefe20c62f204989acf366ef09911f3af89f066088613341b946be131e8_2026-02-24"
63+
pixi-version: ""
64+
# Test test-folder values with fixed OS and pixi-version
65+
- os: ubuntu-latest
66+
test-folder: just-pixi-toml
67+
expected-hash: "pixi-lock__69110db0bf39d7ce64fd774c7078ccd56ebf8542d9a1e86f84e63011634dc43f_2026-02-24"
68+
pixi-version: ""
69+
- os: ubuntu-latest
70+
test-folder: just-pyproject-toml
71+
expected-hash: "pixi-lock__4a057faded2062ff018955c0be1db1b9e1d2fb8d1fe4303d8b778af7fd9e411d_2026-02-24"
72+
pixi-version: ""
73+
- os: ubuntu-latest
74+
test-folder: pyproject-and-pixi-toml
75+
expected-hash: "pixi-lock__b5bae43771086cb1dd79c43dc06881f8b0e006ad8c54e7269dad1a4f8ce96522_2026-02-24"
76+
pixi-version: ""
77+
# Test pixi-version values with fixed OS and test-folder
78+
- os: ubuntu-latest
79+
test-folder: just-pixi-toml
80+
expected-hash: "pixi-lock__69110db0bf39d7ce64fd774c7078ccd56ebf8542d9a1e86f84e63011634dc43f_2026-02-24"
81+
pixi-version: ""
82+
- os: ubuntu-latest
83+
test-folder: just-pixi-toml
84+
expected-hash: "pixi-lock_v0.63.2_69110db0bf39d7ce64fd774c7078ccd56ebf8542d9a1e86f84e63011634dc43f_2026-02-24"
85+
pixi-version: "v0.63.2"
5386
steps:
5487
- name: Checkout repository
5588
uses: actions/checkout@v6
@@ -58,13 +91,27 @@ jobs:
5891

5992
- name: Copy test files to working directory
6093
shell: bash
61-
run: cp -r pixi-lock/ci/test/* .
94+
run: cp -r pixi-lock/ci/test/${{ matrix.test-folder }}/* .
6295

6396
- name: Run create-and-cache action
6497
id: create-and-cache
6598
uses: ./pixi-lock/create-and-cache
6699
with:
67-
pixi-version: ${{ env.PIXI_VERSION }}
100+
pixi-version: ${{ matrix.pixi-version }}
101+
102+
- name: Verify cache key hash matches expected
103+
shell: bash
104+
run: |
105+
actual_hash="${{ steps.create-and-cache.outputs.cache-key }}"
106+
expected_hash="${{ matrix.expected-hash }}"
107+
echo "Expected hash: $expected_hash"
108+
echo "Actual hash: $actual_hash"
109+
if [ "$actual_hash" != "$expected_hash" ]; then
110+
echo "ERROR: Hash mismatch!"
111+
echo "Please update the expected-hash in the workflow matrix to: $actual_hash"
112+
exit 1
113+
fi
114+
echo "Hash matches expected value"
68115
69116
- name: Verify pixi.lock exists
70117
shell: bash
@@ -76,29 +123,20 @@ jobs:
76123
exit 1
77124
fi
78125
79-
restore-and-install:
80-
needs: cache-pixi-lock
81-
runs-on: ${{ matrix.os }}
82-
strategy:
83-
fail-fast: false
84-
matrix:
85-
os: [ubuntu-slim, macos-latest, windows-latest]
86-
steps:
87-
- name: Checkout repository
88-
uses: actions/checkout@v6
89-
with:
90-
path: pixi-lock
126+
- name: Cleanup pixi.lock
127+
shell: bash
128+
run: rm pixi.lock
91129

92-
- name: Copy test files to working directory
130+
- name: Cleanup pixi install
93131
shell: bash
94-
run: cp -r pixi-lock/ci/test/* .
132+
run: rm -rf ~/.pixi
95133

96134
- name: Restore pixi.lock from cache
97135
uses: ./pixi-lock/restore
98136
with:
99-
cache-key: ${{ needs.cache-pixi-lock.outputs.cache-key }}
137+
cache-key: ${{ steps.create-and-cache.outputs.cache-key }}
100138

101-
- name: Verify pixi.lock exists
139+
- name: Verify pixi.lock exists after restore
102140
shell: bash
103141
run: |
104142
if [ -f "pixi.lock" ]; then
@@ -111,7 +149,7 @@ jobs:
111149
- name: Setup pixi and install environment
112150
uses: prefix-dev/setup-pixi@v0.9.3
113151
with:
114-
pixi-version: ${{ needs.cache-pixi-lock.outputs.pixi-version }}
152+
pixi-version: ${{ matrix.pixi-version }}
115153

116154
- name: Verify environment installed
117155
shell: bash

README.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ This repo provides two GitHub Actions for generating and caching `pixi.lock` fil
1010

1111
This two-action pattern is so that the lockfile can be omitted from the git
1212
history, but still be generated in a performant manner (i.e., regenerated
13-
and cached with a key that depends on `pixi.toml` and the date -
13+
and cached with a key that depends on `pixi.toml` and the date -
1414
then shared across jobs).
1515

16-
1716
## Usage
1817

1918
```yaml
@@ -25,7 +24,7 @@ jobs:
2524
pixi-version: ${{ steps.pixi-lock.outputs.pixi-version }}
2625
steps:
2726
- uses: actions/checkout@v4
28-
- uses: Parcels-code/pixi-lock/create-and-cache@... # TODO: Copy the hash for the rev you want to install from
27+
- uses: Parcels-code/pixi-lock/create-and-cache@... # TODO: Copy the hash for the rev you want to install from
2928
id: pixi-lock
3029
with:
3130
pixi-version: ... # TODO: update with your selected pixi version
@@ -45,7 +44,7 @@ jobs:
4544
- uses: Parcels-code/pixi-lock/restore@ # TODO: Copy the hash for the rev you want to install from (same as above)
4645
with:
4746
cache-key: ${{ needs.cache-pixi-lock.outputs.cache-key }}
48-
- uses: prefix-dev/setup-pixi@v... # TODO: update with your selected setup-pixi version
47+
- uses: prefix-dev/setup-pixi@v... # TODO: update with your selected setup-pixi version
4948
with:
5049
pixi-version: ${{ needs.cache-pixi-lock.outputs.pixi-version }}
5150
# ... your CI steps
@@ -55,20 +54,21 @@ jobs:
5554

5655
#### `create-and-cache`
5756

58-
| Input | Description | Required | Default |
59-
|-------|-------------|----------|---------|
60-
| `pixi-version` | Version of pixi to use for generating the lock file | No | `latest` |
57+
| Input | Description | Required | Default |
58+
| -------------- | ------------------------------------------------------- | -------- | -------------------------------- |
59+
| `pixi-version` | Version of pixi to use for generating the lock file | No | `latest` |
60+
| `hash-files` | Files to use to generate the hash key for the lock file | No | `pixi.toml` and `pyproject.toml` |
6161

62-
| Output | Description |
63-
|--------|-------------|
64-
| `pixi-version` | The pixi version used |
65-
| `cache-key` | The cache key (includes today's date) |
62+
| Output | Description |
63+
| -------------- | ------------------------------------- |
64+
| `pixi-version` | The pixi version used |
65+
| `cache-key` | The cache key (includes today's date) |
6666

6767
#### `restore`
6868

69-
| Input | Description | Required |
70-
|-------|-------------|----------|
71-
| `cache-key` | The cache key from `create-and-cache` | Yes |
69+
| Input | Description | Required |
70+
| ----------- | ------------------------------------- | -------- |
71+
| `cache-key` | The cache key from `create-and-cache` | Yes |
7272

7373
> [!NOTE]
7474
> The cache key includes the current date, so the lock file is regenerated daily.
@@ -83,6 +83,7 @@ When developing and testing _library_ code, we don't want our environments to st
8383
The _easiest_ way to test against the latest versions of packages - and avoid the noisy commit history (and additional overhead) of regularly updating a lock file in git - is instead to ignore the lock file and rely on developers and CI to generate their own lock files. This much simpler setup forgoes perfect reprodubility between developer machines, and with CI machines - which may be a worthwhile tradeoff for your project.
8484

8585
See the following threads for more detailed discussion:
86+
8687
- [prefix.dev Discord: Should you commit the lockfile](https://discord.com/channels/1082332781146800168/1462778624212996209)
8788
- [Scientific Python Discord: lock files for libraries](https://discord.com/channels/786703927705862175/1450619697224487083)
8889
- https://github.com/prefix-dev/pixi/issues/5325
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[project]
2+
name = "just-pyproject-toml"
3+
version = "0.1.0"
4+
description = "Add your description here"
5+
readme = "README.md"
6+
requires-python = ">=3.12"
7+
dependencies = []
8+
9+
[tool.pixi.workspace]
10+
authors = ["Vecko <36369090+VeckoTheGecko@users.noreply.github.com>"]
11+
channels = ["conda-forge"]
12+
name = "test"
13+
platforms = ["win-64", "linux-64", "osx-64", "osx-arm64", "linux-aarch64"]
14+
version = "0.1.0"
15+
16+
[tool.pixi.tasks]
17+
18+
[tool.pixi.dependencies]
19+
python = "*"
20+
numpy = "*"
21+
pandas = "*"
22+
xarray = "*"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[workspace]
2+
authors = ["Vecko <36369090+VeckoTheGecko@users.noreply.github.com>"]
3+
channels = ["conda-forge"]
4+
name = "test"
5+
platforms = ["win-64", "linux-64", "osx-64", "osx-arm64", "linux-aarch64"]
6+
version = "0.1.0"
7+
8+
[tasks]
9+
10+
[dependencies]
11+
python = "*"
12+
numpy = "*"
13+
pandas = "*"
14+
xarray = "*"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[project]
2+
name = "pyproject-and-pixi-toml"
3+
version = "0.1.0"
4+
description = "Add your description here"
5+
readme = "README.md"
6+
requires-python = ">=3.12"
7+
dependencies = []

create-and-cache/action.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ inputs:
66
description: "Version of pixi to use for generating the lock file"
77
required: false
88
default: "latest"
9+
hash-files:
10+
description: "Files to use to generate the hash key for the lock file."
11+
required: false
12+
default: |
13+
pixi.toml
14+
pyproject.toml
915
1016
outputs:
1117
pixi-version:
@@ -23,7 +29,7 @@ runs:
2329
shell: bash
2430
run: |
2531
today=$(date +'%Y-%m-%d')
26-
key="pixi-lock_${{ inputs.pixi-version }}_${{ hashFiles('pixi.toml') }}_${today}"
32+
key="pixi-lock_${{ inputs.pixi-version }}_${{ hashFiles(inputs.hash-files) }}_${today}"
2733
echo "key=${key}" >> "$GITHUB_OUTPUT"
2834
2935
- name: Restore pixi.lock from cache

0 commit comments

Comments
 (0)