diff --git a/.github/workflows/test-cache.yml b/.github/workflows/test-cache.yml index 93dcb69..a6c9ada 100644 --- a/.github/workflows/test-cache.yml +++ b/.github/workflows/test-cache.yml @@ -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 diff --git a/__tests__/fixtures/old-python-constraint-project/README.md b/__tests__/fixtures/old-python-constraint-project/README.md new file mode 100644 index 0000000..e69de29 diff --git a/__tests__/fixtures/old-python-constraint-project/pyproject.toml b/__tests__/fixtures/old-python-constraint-project/pyproject.toml new file mode 100644 index 0000000..0d381bb --- /dev/null +++ b/__tests__/fixtures/old-python-constraint-project/pyproject.toml @@ -0,0 +1,13 @@ +[project] +name = "old-python-constraint-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" diff --git a/__tests__/fixtures/old-python-constraint-project/src/old_python_constraint_project/__init__.py b/__tests__/fixtures/old-python-constraint-project/src/old_python_constraint_project/__init__.py new file mode 100644 index 0000000..94ebc9c --- /dev/null +++ b/__tests__/fixtures/old-python-constraint-project/src/old_python_constraint_project/__init__.py @@ -0,0 +1,2 @@ +def hello() -> str: + return "Hello from uv-project!" diff --git a/__tests__/fixtures/old-python-constraint-project/uv.lock b/__tests__/fixtures/old-python-constraint-project/uv.lock new file mode 100644 index 0000000..3838f8c --- /dev/null +++ b/__tests__/fixtures/old-python-constraint-project/uv.lock @@ -0,0 +1,38 @@ +version = 1 +requires-python = ">=3.12" + +[[package]] +name = "ruff" +version = "0.6.2" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/23/f4/279d044f66b79261fd37df76bf72b64471afab5d3b7906a01499c4451910/ruff-0.6.2.tar.gz", hash = "sha256:239ee6beb9e91feb8e0ec384204a763f36cb53fb895a1a364618c6abb076b3be", size = 2460281 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/72/4b/47dd7a69287afb4069fa42c198e899463605460a58120196711bfcf0446b/ruff-0.6.2-py3-none-linux_armv6l.whl", hash = "sha256:5c8cbc6252deb3ea840ad6a20b0f8583caab0c5ef4f9cca21adc5a92b8f79f3c", size = 9695871 }, + { url = "https://files.pythonhosted.org/packages/ae/c3/8aac62ac4638c14a740ee76a755a925f2d0d04580ab790a9887accb729f6/ruff-0.6.2-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:17002fe241e76544448a8e1e6118abecbe8cd10cf68fde635dad480dba594570", size = 9459354 }, + { url = "https://files.pythonhosted.org/packages/2f/cf/77fbd8d4617b9b9c503f9bffb8552c4e3ea1a58dc36975e7a9104ffb0f85/ruff-0.6.2-py3-none-macosx_11_0_arm64.whl", hash = "sha256:3dbeac76ed13456f8158b8f4fe087bf87882e645c8e8b606dd17b0b66c2c1158", size = 9163871 }, + { url = "https://files.pythonhosted.org/packages/05/1c/765192bab32b79efbb498b06f0b9dcb3629112b53b8777ae1d19b8209e09/ruff-0.6.2-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:094600ee88cda325988d3f54e3588c46de5c18dae09d683ace278b11f9d4d534", size = 10096250 }, + { url = "https://files.pythonhosted.org/packages/08/d0/86f3cb0f6934c99f759c232984a5204d67a26745cad2d9edff6248adf7d2/ruff-0.6.2-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:316d418fe258c036ba05fbf7dfc1f7d3d4096db63431546163b472285668132b", size = 9475376 }, + { url = "https://files.pythonhosted.org/packages/cd/cc/4c8d0e225b559a3fae6092ec310d7150d3b02b4669e9223f783ef64d82c0/ruff-0.6.2-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:d72b8b3abf8a2d51b7b9944a41307d2f442558ccb3859bbd87e6ae9be1694a5d", size = 10295634 }, + { url = "https://files.pythonhosted.org/packages/db/96/d2699cfb1bb5a01c68122af43454c76c31331e1c8a9bd97d653d7c82524b/ruff-0.6.2-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:2aed7e243be68487aa8982e91c6e260982d00da3f38955873aecd5a9204b1d66", size = 11024941 }, + { url = "https://files.pythonhosted.org/packages/8b/a9/6ecd66af8929e0f2a1ed308a4137f3521789f28f0eb97d32c2ca3aa7000c/ruff-0.6.2-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:d371f7fc9cec83497fe7cf5eaf5b76e22a8efce463de5f775a1826197feb9df8", size = 10606894 }, + { url = "https://files.pythonhosted.org/packages/e4/73/2ee4cd19f44992fedac1cc6db9e3d825966072f6dcbd4032f21cbd063170/ruff-0.6.2-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:a8f310d63af08f583363dfb844ba8f9417b558199c58a5999215082036d795a1", size = 11552886 }, + { url = "https://files.pythonhosted.org/packages/60/4c/c0f1cd35ce4a93c54a6bb1ee6934a3a205fa02198dd076678193853ceea1/ruff-0.6.2-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7db6880c53c56addb8638fe444818183385ec85eeada1d48fc5abe045301b2f1", size = 10264945 }, + { url = "https://files.pythonhosted.org/packages/c4/89/e45c9359b9cdd4245512ea2b9f2bb128a997feaa5f726fc9e8c7a66afadf/ruff-0.6.2-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:1175d39faadd9a50718f478d23bfc1d4da5743f1ab56af81a2b6caf0a2394f23", size = 10100007 }, + { url = "https://files.pythonhosted.org/packages/06/74/0bd4e0a7ed5f6908df87892f9bf60a2356c0fd74102d8097298bd9b4f346/ruff-0.6.2-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:5b939f9c86d51635fe486585389f54582f0d65b8238e08c327c1534844b3bb9a", size = 9559267 }, + { url = "https://files.pythonhosted.org/packages/54/03/3dc6dc9419f276f05805bf888c279e3e0b631284abd548d9e87cebb93aec/ruff-0.6.2-py3-none-musllinux_1_2_i686.whl", hash = "sha256:d0d62ca91219f906caf9b187dea50d17353f15ec9bb15aae4a606cd697b49b4c", size = 9905304 }, + { url = "https://files.pythonhosted.org/packages/5c/5b/d6a72a6a6bbf097c09de468326ef5fa1c9e7aa5e6e45979bc0d984b0dbe7/ruff-0.6.2-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:7438a7288f9d67ed3c8ce4d059e67f7ed65e9fe3aa2ab6f5b4b3610e57e3cb56", size = 10341480 }, + { url = "https://files.pythonhosted.org/packages/79/a9/0f2f21fe15ba537c46598f96aa9ae4a3d4b9ec64926664617ca6a8c772f4/ruff-0.6.2-py3-none-win32.whl", hash = "sha256:279d5f7d86696df5f9549b56b9b6a7f6c72961b619022b5b7999b15db392a4da", size = 7961901 }, + { url = "https://files.pythonhosted.org/packages/b0/80/fff12ffe11853d9f4ea3e5221e6dd2e93640a161c05c9579833e09ad40a7/ruff-0.6.2-py3-none-win_amd64.whl", hash = "sha256:d9f3469c7dd43cd22eb1c3fc16926fb8258d50cb1b216658a07be95dd117b0f2", size = 8783320 }, + { url = "https://files.pythonhosted.org/packages/56/91/577cdd64cce5e74d3f8b5ecb93f29566def569c741eb008aed4f331ef821/ruff-0.6.2-py3-none-win_arm64.whl", hash = "sha256:f28fcd2cd0e02bdf739297516d5643a945cc7caf09bd9bcb4d932540a5ea4fa9", size = 8225886 }, +] + +[[package]] +name = "uv-project" +version = "0.1.0" +source = { editable = "." } +dependencies = [ + { name = "ruff" }, +] + +[package.metadata] +requires-dist = [{ name = "ruff" }] diff --git a/dist/save-cache/index.js b/dist/save-cache/index.js index 5bae647..93af54d 100644 --- a/dist/save-cache/index.js +++ b/dist/save-cache/index.js @@ -91461,6 +91461,7 @@ const core = __importStar(__nccwpck_require__(7484)); const inputs_1 = __nccwpck_require__(9612); const platforms_1 = __nccwpck_require__(8361); const hash_files_1 = __nccwpck_require__(9660); +const exec = __importStar(__nccwpck_require__(5236)); exports.STATE_CACHE_KEY = "cache-key"; exports.STATE_CACHE_MATCHED_KEY = "cache-matched-key"; const CACHE_VERSION = "1"; @@ -91496,7 +91497,30 @@ function computeKeys(version) { cacheDependencyPathHash += "no-dependency-glob"; } const suffix = inputs_1.cacheSuffix ? `-${inputs_1.cacheSuffix}` : ""; - return `setup-uv-${CACHE_VERSION}-${(0, platforms_1.getArch)()}-${(0, platforms_1.getPlatform)()}-${version}${cacheDependencyPathHash}${suffix}`; + const pythonVersion = yield getPythonVersion(); + return `setup-uv-${CACHE_VERSION}-${(0, platforms_1.getArch)()}-${(0, platforms_1.getPlatform)()}-${version}-${pythonVersion}${cacheDependencyPathHash}${suffix}`; + }); +} +function getPythonVersion() { + return __awaiter(this, void 0, void 0, function* () { + if (inputs_1.pythonVersion !== "") { + return inputs_1.pythonVersion; + } + const options = { + silent: !core.isDebug(), + }; + const execArgs = ["python", "find"]; + let output = ""; + options.listeners = { + stdout: (data) => { + output += data.toString(); + }, + }; + yield exec.exec("uv", execArgs, options); + const pythonPath = output.trim(); + output = ""; + yield exec.exec(pythonPath, ["--version"], options); + return output.trim(); }); } function handleMatchResult(matchedKey, primaryKey) { diff --git a/dist/setup/index.js b/dist/setup/index.js index 0452816..d4d3f9d 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -96544,6 +96544,7 @@ const core = __importStar(__nccwpck_require__(7484)); const inputs_1 = __nccwpck_require__(9612); const platforms_1 = __nccwpck_require__(8361); const hash_files_1 = __nccwpck_require__(9660); +const exec = __importStar(__nccwpck_require__(5236)); exports.STATE_CACHE_KEY = "cache-key"; exports.STATE_CACHE_MATCHED_KEY = "cache-matched-key"; const CACHE_VERSION = "1"; @@ -96579,7 +96580,30 @@ function computeKeys(version) { cacheDependencyPathHash += "no-dependency-glob"; } const suffix = inputs_1.cacheSuffix ? `-${inputs_1.cacheSuffix}` : ""; - return `setup-uv-${CACHE_VERSION}-${(0, platforms_1.getArch)()}-${(0, platforms_1.getPlatform)()}-${version}${cacheDependencyPathHash}${suffix}`; + const pythonVersion = yield getPythonVersion(); + return `setup-uv-${CACHE_VERSION}-${(0, platforms_1.getArch)()}-${(0, platforms_1.getPlatform)()}-${version}-${pythonVersion}${cacheDependencyPathHash}${suffix}`; + }); +} +function getPythonVersion() { + return __awaiter(this, void 0, void 0, function* () { + if (inputs_1.pythonVersion !== "") { + return inputs_1.pythonVersion; + } + const options = { + silent: !core.isDebug(), + }; + const execArgs = ["python", "find"]; + let output = ""; + options.listeners = { + stdout: (data) => { + output += data.toString(); + }, + }; + yield exec.exec("uv", execArgs, options); + const pythonPath = output.trim(); + output = ""; + yield exec.exec(pythonPath, ["--version"], options); + return output.trim(); }); } function handleMatchResult(matchedKey, primaryKey) { diff --git a/src/cache/restore-cache.ts b/src/cache/restore-cache.ts index 134b98b..20288d1 100644 --- a/src/cache/restore-cache.ts +++ b/src/cache/restore-cache.ts @@ -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"; @@ -49,7 +51,31 @@ async function computeKeys(version: string): Promise { 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 { + 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); + const pythonPath = output.trim(); + output = ""; + await exec.exec(pythonPath, ["--version"], options); + return output.trim(); } function handleMatchResult(