Skip to content
34 changes: 31 additions & 3 deletions create-and-cache/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ inputs:
default: |
pixi.toml
pyproject.toml
manifest-path:
required: false
description: >-
Path to the manifest file (i.e., `pixi.toml`) to use for the pixi CLI. Defaults to `pixi.toml`, falling back to `pyproject.toml`.

outputs:
pixi-version:
Expand All @@ -35,11 +39,32 @@ runs:
key="pixi-lock_${PIXI_VERSION}_${HASH_FILES}_${today}"
echo "key=${key}" >> "$GITHUB_OUTPUT"

- name: Find manifest and lock paths path
id: meta
shell: bash
env:
MANIFEST_PATH: ${{ inputs.manifest-path }}
run: |
lock_path="pixi.lock"
if [[ -n "$MANIFEST_PATH" ]]; then
manifest_path="$MANIFEST_PATH"
lock_path="$(dirname ${manifest_path})/pixi.lock"
elif [[ -f "pixi.toml" ]]; then
manifest_path="pixi.toml"
elif [[ -f "pyproject.toml" ]]; then
manifest_path="pyproject.toml"
else
echo "Error: no manifest file found (pixi.toml or pyproject.toml)" >&2
exit 1
fi
echo "manifest-path=${manifest_path}" >> "$GITHUB_OUTPUT"
echo "lock-path=${lock_path}" >> "$GITHUB_OUTPUT"

- name: Restore pixi.lock from cache
uses: actions/cache/restore@8b402f58fbc84540c8b491a91e594a4576fec3d7 # v5.0.2
id: restore
with:
path: pixi.lock
path: ${{ steps.meta.outputs.lock-path }}
key: ${{ steps.cache-key.outputs.key }}
enableCrossOsArchive: true

Expand All @@ -49,16 +74,19 @@ runs:
with:
pixi-version: ${{ inputs.pixi-version }}
run-install: false
manifest-path: ${{ steps.meta.outputs.manifest-path }}

- name: Run pixi lock
if: ${{ !steps.restore.outputs.cache-hit }}
shell: bash
run: pixi lock
env:
MANIFEST_PATH: ${{ steps.meta.outputs.manifest-path }}
run: pixi lock --manifest-path=$MANIFEST_PATH

- name: Save pixi.lock to cache
uses: actions/cache/save@8b402f58fbc84540c8b491a91e594a4576fec3d7 # v5.0.2
if: ${{ !steps.restore.outputs.cache-hit }}
with:
path: pixi.lock
path: ${{ steps.meta.outputs.lock-path }}
key: ${{ steps.cache-key.outputs.key }}
enableCrossOsArchive: true
21 changes: 20 additions & 1 deletion restore/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ inputs:
cache-key:
description: "The cache key from create-and-cache"
required: true
manifest-path:
required: false
description: >-
Path to the manifest file (i.e., `pixi.toml`) to use for the pixi CLI. Defaults to `pixi.toml`, falling back to `pyproject.toml`.

runs:
using: "composite"
Expand Down Expand Up @@ -33,11 +37,26 @@ runs:
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')
echo "key=${base}_${yesterday}" >> "$GITHUB_OUTPUT"

- name: Calculate the lock file path
id: lock-path
shell: bash
env:
MANIFEST_PATH: ${{ inputs.manifest-path }}
run: |
if [[ -z "$MANIFEST_PATH" ]]; then
lock_path=pixi.lock
else
base=$(dirname $MANIFEST_PATH)
lock_path="$base/pixi.lock"
fi

echo "lock-path=${lock_path}" >> "$GITHUB_OUTPUT"

- name: Restore pixi.lock from cache
uses: actions/cache/restore@8b402f58fbc84540c8b491a91e594a4576fec3d7 # v5.0.2
id: restore
with:
path: pixi.lock
path: ${{ steps.lock-path.outputs.lock-path }}
key: ${{ inputs.cache-key }}
enableCrossOsArchive: true
restore-keys: |
Expand Down
Loading