Skip to content

Commit

Permalink
Add python version to hash key
Browse files Browse the repository at this point in the history
  • Loading branch information
eifinger committed Dec 13, 2024
1 parent e3017a7 commit d1ca647
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 3 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/test-cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,14 @@ jobs:
- name: Remove cache dependency glob file
run: rm -f ~/uv-cache.glob
shell: bash

test-no-python-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup with cache
uses: ./
with:
enable-cache: true
- run: uv sync
working-directory: __tests__/fixtures/old-python-constraint-project
Empty file.
13 changes: 13 additions & 0 deletions __tests__/fixtures/old-python-constraint-project/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[project]
name = "old-python-constraints-project"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.8,<=3.9"
dependencies = [
"ruff>=0.6.2",
]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def hello() -> str:
return "Hello from uv-project!"
38 changes: 38 additions & 0 deletions __tests__/fixtures/old-python-constraint-project/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 22 additions & 1 deletion dist/save-cache/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 22 additions & 1 deletion dist/setup/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 24 additions & 1 deletion src/cache/restore-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import {
cacheDependencyGlob,
cacheLocalPath,
cacheSuffix,
pythonVersion as pythonVersionInput,
} from "../utils/inputs";
import { getArch, getPlatform } from "../utils/platforms";
import { hashFiles } from "../hash/hash-files";
import * as exec from "@actions/exec";

export const STATE_CACHE_KEY = "cache-key";
export const STATE_CACHE_MATCHED_KEY = "cache-matched-key";
Expand Down Expand Up @@ -49,7 +51,28 @@ async function computeKeys(version: string): Promise<string> {
cacheDependencyPathHash += "no-dependency-glob";
}
const suffix = cacheSuffix ? `-${cacheSuffix}` : "";
return `setup-uv-${CACHE_VERSION}-${getArch()}-${getPlatform()}-${version}${cacheDependencyPathHash}${suffix}`;
const pythonVersion = await getPythonVersion();
return `setup-uv-${CACHE_VERSION}-${getArch()}-${getPlatform()}-${version}-${pythonVersion}-${cacheDependencyPathHash}${suffix}`;
}

async function getPythonVersion(): Promise<string> {
if (pythonVersionInput !== "") {
return pythonVersionInput;
}

const options: exec.ExecOptions = {
silent: !core.isDebug(),
};
const execArgs = ["python", "find"];

let output = "";
options.listeners = {
stdout: (data: Buffer) => {
output += data.toString();
},
};
await exec.exec("uv", execArgs, options);
return output.trim();
}

function handleMatchResult(
Expand Down

0 comments on commit d1ca647

Please sign in to comment.