mirror of
https://github.com/astral-sh/setup-uv.git
synced 2025-12-19 11:04:08 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
887a942a15 | ||
|
|
d174a24c07 | ||
|
|
12c852e6ba |
@@ -334,10 +334,11 @@ by name (`uv`).
|
|||||||
|
|
||||||
### Do I still need `actions/setup-python` alongside `setup-uv`?
|
### Do I still need `actions/setup-python` alongside `setup-uv`?
|
||||||
|
|
||||||
No. This action is modelled as a drop-in replacement for `actions/setup-python` when using uv. With
|
With `setup-uv`, you can install a specific version of Python using `uv python install` rather than
|
||||||
`setup-uv`, you can install a specific version of Python using `uv python install` rather than
|
|
||||||
relying on `actions/setup-python`.
|
relying on `actions/setup-python`.
|
||||||
|
|
||||||
|
Using `actions/setup-python` can be faster, because GitHub caches the Python versions alongside the runner.
|
||||||
|
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
@@ -348,7 +349,7 @@ For example:
|
|||||||
with:
|
with:
|
||||||
enable-cache: true
|
enable-cache: true
|
||||||
- name: Test
|
- name: Test
|
||||||
run: uv run --frozen pytest
|
run: uv run --frozen pytest # Uses the Python version automatically installed by uv
|
||||||
```
|
```
|
||||||
|
|
||||||
To install a specific version of Python, use
|
To install a specific version of Python, use
|
||||||
|
|||||||
8
dist/save-cache/index.js
generated
vendored
8
dist/save-cache/index.js
generated
vendored
@@ -91465,9 +91465,9 @@ const exec = __importStar(__nccwpck_require__(5236));
|
|||||||
exports.STATE_CACHE_KEY = "cache-key";
|
exports.STATE_CACHE_KEY = "cache-key";
|
||||||
exports.STATE_CACHE_MATCHED_KEY = "cache-matched-key";
|
exports.STATE_CACHE_MATCHED_KEY = "cache-matched-key";
|
||||||
const CACHE_VERSION = "1";
|
const CACHE_VERSION = "1";
|
||||||
function restoreCache(version) {
|
function restoreCache() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const cacheKey = yield computeKeys(version);
|
const cacheKey = yield computeKeys();
|
||||||
let matchedKey;
|
let matchedKey;
|
||||||
core.info(`Trying to restore uv cache from GitHub Actions cache with key: ${cacheKey}`);
|
core.info(`Trying to restore uv cache from GitHub Actions cache with key: ${cacheKey}`);
|
||||||
try {
|
try {
|
||||||
@@ -91483,7 +91483,7 @@ function restoreCache(version) {
|
|||||||
handleMatchResult(matchedKey, cacheKey);
|
handleMatchResult(matchedKey, cacheKey);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function computeKeys(version) {
|
function computeKeys() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
let cacheDependencyPathHash = "-";
|
let cacheDependencyPathHash = "-";
|
||||||
if (inputs_1.cacheDependencyGlob !== "") {
|
if (inputs_1.cacheDependencyGlob !== "") {
|
||||||
@@ -91498,7 +91498,7 @@ function computeKeys(version) {
|
|||||||
}
|
}
|
||||||
const suffix = inputs_1.cacheSuffix ? `-${inputs_1.cacheSuffix}` : "";
|
const suffix = inputs_1.cacheSuffix ? `-${inputs_1.cacheSuffix}` : "";
|
||||||
const pythonVersion = yield getPythonVersion();
|
const pythonVersion = yield getPythonVersion();
|
||||||
return `setup-uv-${CACHE_VERSION}-${(0, platforms_1.getArch)()}-${(0, platforms_1.getPlatform)()}-${version}-${pythonVersion}${cacheDependencyPathHash}${suffix}`;
|
return `setup-uv-${CACHE_VERSION}-${(0, platforms_1.getArch)()}-${(0, platforms_1.getPlatform)()}-${pythonVersion}${cacheDependencyPathHash}${suffix}`;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function getPythonVersion() {
|
function getPythonVersion() {
|
||||||
|
|||||||
12
dist/setup/index.js
generated
vendored
12
dist/setup/index.js
generated
vendored
@@ -96548,9 +96548,9 @@ const exec = __importStar(__nccwpck_require__(5236));
|
|||||||
exports.STATE_CACHE_KEY = "cache-key";
|
exports.STATE_CACHE_KEY = "cache-key";
|
||||||
exports.STATE_CACHE_MATCHED_KEY = "cache-matched-key";
|
exports.STATE_CACHE_MATCHED_KEY = "cache-matched-key";
|
||||||
const CACHE_VERSION = "1";
|
const CACHE_VERSION = "1";
|
||||||
function restoreCache(version) {
|
function restoreCache() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const cacheKey = yield computeKeys(version);
|
const cacheKey = yield computeKeys();
|
||||||
let matchedKey;
|
let matchedKey;
|
||||||
core.info(`Trying to restore uv cache from GitHub Actions cache with key: ${cacheKey}`);
|
core.info(`Trying to restore uv cache from GitHub Actions cache with key: ${cacheKey}`);
|
||||||
try {
|
try {
|
||||||
@@ -96566,7 +96566,7 @@ function restoreCache(version) {
|
|||||||
handleMatchResult(matchedKey, cacheKey);
|
handleMatchResult(matchedKey, cacheKey);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function computeKeys(version) {
|
function computeKeys() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
let cacheDependencyPathHash = "-";
|
let cacheDependencyPathHash = "-";
|
||||||
if (inputs_1.cacheDependencyGlob !== "") {
|
if (inputs_1.cacheDependencyGlob !== "") {
|
||||||
@@ -96581,7 +96581,7 @@ function computeKeys(version) {
|
|||||||
}
|
}
|
||||||
const suffix = inputs_1.cacheSuffix ? `-${inputs_1.cacheSuffix}` : "";
|
const suffix = inputs_1.cacheSuffix ? `-${inputs_1.cacheSuffix}` : "";
|
||||||
const pythonVersion = yield getPythonVersion();
|
const pythonVersion = yield getPythonVersion();
|
||||||
return `setup-uv-${CACHE_VERSION}-${(0, platforms_1.getArch)()}-${(0, platforms_1.getPlatform)()}-${version}-${pythonVersion}${cacheDependencyPathHash}${suffix}`;
|
return `setup-uv-${CACHE_VERSION}-${(0, platforms_1.getArch)()}-${(0, platforms_1.getPlatform)()}-${pythonVersion}${cacheDependencyPathHash}${suffix}`;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function getPythonVersion() {
|
function getPythonVersion() {
|
||||||
@@ -99274,7 +99274,7 @@ function run() {
|
|||||||
core.setOutput("uv-version", setupResult.version);
|
core.setOutput("uv-version", setupResult.version);
|
||||||
core.info(`Successfully installed uv version ${setupResult.version}`);
|
core.info(`Successfully installed uv version ${setupResult.version}`);
|
||||||
if (inputs_1.enableCache) {
|
if (inputs_1.enableCache) {
|
||||||
yield (0, restore_cache_1.restoreCache)(setupResult.version);
|
yield (0, restore_cache_1.restoreCache)();
|
||||||
}
|
}
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
@@ -99349,7 +99349,7 @@ function setupPython() {
|
|||||||
venvBinPath = ".venv/Scripts";
|
venvBinPath = ".venv/Scripts";
|
||||||
}
|
}
|
||||||
core.addPath(venvBinPath);
|
core.addPath(venvBinPath);
|
||||||
core.exportVariable("VIRTUAL_ENV", venvBinPath);
|
core.exportVariable("VIRTUAL_ENV", ".venv");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
8
src/cache/restore-cache.ts
vendored
8
src/cache/restore-cache.ts
vendored
@@ -14,8 +14,8 @@ export const STATE_CACHE_KEY = "cache-key";
|
|||||||
export const STATE_CACHE_MATCHED_KEY = "cache-matched-key";
|
export const STATE_CACHE_MATCHED_KEY = "cache-matched-key";
|
||||||
const CACHE_VERSION = "1";
|
const CACHE_VERSION = "1";
|
||||||
|
|
||||||
export async function restoreCache(version: string): Promise<void> {
|
export async function restoreCache(): Promise<void> {
|
||||||
const cacheKey = await computeKeys(version);
|
const cacheKey = await computeKeys();
|
||||||
|
|
||||||
let matchedKey: string | undefined;
|
let matchedKey: string | undefined;
|
||||||
core.info(
|
core.info(
|
||||||
@@ -35,7 +35,7 @@ export async function restoreCache(version: string): Promise<void> {
|
|||||||
handleMatchResult(matchedKey, cacheKey);
|
handleMatchResult(matchedKey, cacheKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function computeKeys(version: string): Promise<string> {
|
async function computeKeys(): Promise<string> {
|
||||||
let cacheDependencyPathHash = "-";
|
let cacheDependencyPathHash = "-";
|
||||||
if (cacheDependencyGlob !== "") {
|
if (cacheDependencyGlob !== "") {
|
||||||
core.info(
|
core.info(
|
||||||
@@ -53,7 +53,7 @@ async function computeKeys(version: string): Promise<string> {
|
|||||||
}
|
}
|
||||||
const suffix = cacheSuffix ? `-${cacheSuffix}` : "";
|
const suffix = cacheSuffix ? `-${cacheSuffix}` : "";
|
||||||
const pythonVersion = await getPythonVersion();
|
const pythonVersion = await getPythonVersion();
|
||||||
return `setup-uv-${CACHE_VERSION}-${getArch()}-${getPlatform()}-${version}-${pythonVersion}${cacheDependencyPathHash}${suffix}`;
|
return `setup-uv-${CACHE_VERSION}-${getArch()}-${getPlatform()}-${pythonVersion}${cacheDependencyPathHash}${suffix}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getPythonVersion(): Promise<string> {
|
async function getPythonVersion(): Promise<string> {
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ async function run(): Promise<void> {
|
|||||||
core.info(`Successfully installed uv version ${setupResult.version}`);
|
core.info(`Successfully installed uv version ${setupResult.version}`);
|
||||||
|
|
||||||
if (enableCache) {
|
if (enableCache) {
|
||||||
await restoreCache(setupResult.version);
|
await restoreCache();
|
||||||
}
|
}
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -143,7 +143,7 @@ async function setupPython(): Promise<void> {
|
|||||||
venvBinPath = ".venv/Scripts";
|
venvBinPath = ".venv/Scripts";
|
||||||
}
|
}
|
||||||
core.addPath(venvBinPath);
|
core.addPath(venvBinPath);
|
||||||
core.exportVariable("VIRTUAL_ENV", venvBinPath);
|
core.exportVariable("VIRTUAL_ENV", ".venv");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user