Warn when the workdir is empty (#322)

Closes: #306
This commit is contained in:
Kevin Stillhammer 2025-03-16 22:15:17 +01:00 committed by GitHub
parent 0e855c90d0
commit a05a582c56
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG key ID: B5690EEEBB952194
6 changed files with 57 additions and 2 deletions

View file

@ -279,6 +279,20 @@ If you want to ignore this, set the `ignore-nothing-to-cache` input to `true`.
ignore-nothing-to-cache: true ignore-nothing-to-cache: true
``` ```
### Ignore empty workdir
By default, the action will warn if the workdir is empty, because this is usually the case when
`actions/checkout` is configured to run after `setup-uv`, which is not supported.
If you want to ignore this, set the `ignore-empty-workdir` input to `true`.
```yaml
- name: Ignore empty workdir
uses: astral-sh/setup-uv@v5
with:
ignore-empty-workdir: true
```
### GitHub authentication token ### GitHub authentication token
This action uses the GitHub API to fetch the uv release artifacts. To avoid hitting the GitHub API This action uses the GitHub API to fetch the uv release artifacts. To avoid hitting the GitHub API
@ -447,6 +461,13 @@ The reason for the warning is, that we have to way to know if this is the first
cache key or the user accidentally misconfigured the [cache-dependency-glob](#cache-dependency-glob) cache key or the user accidentally misconfigured the [cache-dependency-glob](#cache-dependency-glob)
or [cache-suffix](#enable-caching) and the cache never gets used. or [cache-suffix](#enable-caching) and the cache never gets used.
### Do I have to run `actions/checkout` before or after `setup-uv`?
Some workflows need uv but do not need to access the repository content.
But **if** you need to access the repository content, you have run `actions/checkout` before running `setup-uv`.
Running `actions/checkout` after `setup-uv` **is not supported**.
## Acknowledgements ## Acknowledgements
`setup-uv` was initially written and published by [Kevin Stillhammer](https://github.com/eifinger) `setup-uv` was initially written and published by [Kevin Stillhammer](https://github.com/eifinger)

View file

@ -45,6 +45,9 @@ inputs:
ignore-nothing-to-cache: ignore-nothing-to-cache:
description: "Ignore when nothing is found to cache." description: "Ignore when nothing is found to cache."
default: "false" default: "false"
ignore-empty-workdir:
description: "Ignore when the working directory is empty."
default: "false"
tool-dir: tool-dir:
description: "Custom path to set UV_TOOL_DIR to." description: "Custom path to set UV_TOOL_DIR to."
required: false required: false

3
dist/save-cache/index.js generated vendored
View file

@ -88914,7 +88914,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod }; return (mod && mod.__esModule) ? mod : { "default": mod };
}; };
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.githubToken = exports.toolDir = exports.toolBinDir = exports.ignoreNothingToCache = exports.pruneCache = exports.cacheDependencyGlob = exports.cacheLocalPath = exports.cacheSuffix = exports.enableCache = exports.checkSum = exports.pythonVersion = exports.uvFile = exports.pyProjectFile = exports.version = void 0; exports.githubToken = exports.toolDir = exports.toolBinDir = exports.ignoreEmptyWorkdir = exports.ignoreNothingToCache = exports.pruneCache = exports.cacheDependencyGlob = exports.cacheLocalPath = exports.cacheSuffix = exports.enableCache = exports.checkSum = exports.pythonVersion = exports.uvFile = exports.pyProjectFile = exports.version = void 0;
const core = __importStar(__nccwpck_require__(7484)); const core = __importStar(__nccwpck_require__(7484));
const node_path_1 = __importDefault(__nccwpck_require__(6760)); const node_path_1 = __importDefault(__nccwpck_require__(6760));
exports.version = core.getInput("version"); exports.version = core.getInput("version");
@ -88928,6 +88928,7 @@ exports.cacheLocalPath = getCacheLocalPath();
exports.cacheDependencyGlob = core.getInput("cache-dependency-glob"); exports.cacheDependencyGlob = core.getInput("cache-dependency-glob");
exports.pruneCache = core.getInput("prune-cache") === "true"; exports.pruneCache = core.getInput("prune-cache") === "true";
exports.ignoreNothingToCache = core.getInput("ignore-nothing-to-cache") === "true"; exports.ignoreNothingToCache = core.getInput("ignore-nothing-to-cache") === "true";
exports.ignoreEmptyWorkdir = core.getInput("ignore-empty-workdir") === "true";
exports.toolBinDir = getToolBinDir(); exports.toolBinDir = getToolBinDir();
exports.toolDir = getToolDir(); exports.toolDir = getToolDir();
exports.githubToken = core.getInput("github-token"); exports.githubToken = core.getInput("github-token");

14
dist/setup/index.js generated vendored
View file

@ -119746,6 +119746,7 @@ const exec = __importStar(__nccwpck_require__(5236));
const node_fs_1 = __importDefault(__nccwpck_require__(3024)); const node_fs_1 = __importDefault(__nccwpck_require__(3024));
const pyproject_1 = __nccwpck_require__(3929); const pyproject_1 = __nccwpck_require__(3929);
async function run() { async function run() {
detectEmptyWorkdir();
const platform = await (0, platforms_1.getPlatform)(); const platform = await (0, platforms_1.getPlatform)();
const arch = (0, platforms_1.getArch)(); const arch = (0, platforms_1.getArch)();
try { try {
@ -119773,6 +119774,16 @@ async function run() {
core.setFailed(err.message); core.setFailed(err.message);
} }
} }
function detectEmptyWorkdir() {
if (node_fs_1.default.readdirSync(".").length === 0) {
if (inputs_1.ignoreEmptyWorkdir) {
core.info("Empty workdir detected. Ignoring because ignore-empty-workdir is enabled");
}
else {
core.warning("Empty workdir detected. This may cause unexpected behavior. You can enable ignore-empty-workdir to mute this warning.");
}
}
}
async function setupUv(platform, arch, checkSum, githubToken) { async function setupUv(platform, arch, checkSum, githubToken) {
const resolvedVersion = await determineVersion(); const resolvedVersion = await determineVersion();
const toolCacheResult = (0, download_version_1.tryGetFromToolCache)(arch, resolvedVersion); const toolCacheResult = (0, download_version_1.tryGetFromToolCache)(arch, resolvedVersion);
@ -119927,7 +119938,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod }; return (mod && mod.__esModule) ? mod : { "default": mod };
}; };
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.githubToken = exports.toolDir = exports.toolBinDir = exports.ignoreNothingToCache = exports.pruneCache = exports.cacheDependencyGlob = exports.cacheLocalPath = exports.cacheSuffix = exports.enableCache = exports.checkSum = exports.pythonVersion = exports.uvFile = exports.pyProjectFile = exports.version = void 0; exports.githubToken = exports.toolDir = exports.toolBinDir = exports.ignoreEmptyWorkdir = exports.ignoreNothingToCache = exports.pruneCache = exports.cacheDependencyGlob = exports.cacheLocalPath = exports.cacheSuffix = exports.enableCache = exports.checkSum = exports.pythonVersion = exports.uvFile = exports.pyProjectFile = exports.version = void 0;
const core = __importStar(__nccwpck_require__(7484)); const core = __importStar(__nccwpck_require__(7484));
const node_path_1 = __importDefault(__nccwpck_require__(6760)); const node_path_1 = __importDefault(__nccwpck_require__(6760));
exports.version = core.getInput("version"); exports.version = core.getInput("version");
@ -119941,6 +119952,7 @@ exports.cacheLocalPath = getCacheLocalPath();
exports.cacheDependencyGlob = core.getInput("cache-dependency-glob"); exports.cacheDependencyGlob = core.getInput("cache-dependency-glob");
exports.pruneCache = core.getInput("prune-cache") === "true"; exports.pruneCache = core.getInput("prune-cache") === "true";
exports.ignoreNothingToCache = core.getInput("ignore-nothing-to-cache") === "true"; exports.ignoreNothingToCache = core.getInput("ignore-nothing-to-cache") === "true";
exports.ignoreEmptyWorkdir = core.getInput("ignore-empty-workdir") === "true";
exports.toolBinDir = getToolBinDir(); exports.toolBinDir = getToolBinDir();
exports.toolDir = getToolDir(); exports.toolDir = getToolDir();
exports.githubToken = core.getInput("github-token"); exports.githubToken = core.getInput("github-token");

View file

@ -16,6 +16,7 @@ import {
import { import {
cacheLocalPath, cacheLocalPath,
checkSum, checkSum,
ignoreEmptyWorkdir,
enableCache, enableCache,
githubToken, githubToken,
pyProjectFile, pyProjectFile,
@ -30,6 +31,7 @@ import fs from "node:fs";
import { getUvVersionFromConfigFile } from "./utils/pyproject"; import { getUvVersionFromConfigFile } from "./utils/pyproject";
async function run(): Promise<void> { async function run(): Promise<void> {
detectEmptyWorkdir();
const platform = await getPlatform(); const platform = await getPlatform();
const arch = getArch(); const arch = getArch();
@ -61,6 +63,20 @@ async function run(): Promise<void> {
} }
} }
function detectEmptyWorkdir(): void {
if (fs.readdirSync(".").length === 0) {
if (ignoreEmptyWorkdir) {
core.info(
"Empty workdir detected. Ignoring because ignore-empty-workdir is enabled",
);
} else {
core.warning(
"Empty workdir detected. This may cause unexpected behavior. You can enable ignore-empty-workdir to mute this warning.",
);
}
}
}
async function setupUv( async function setupUv(
platform: Platform, platform: Platform,
arch: Architecture, arch: Architecture,

View file

@ -13,6 +13,8 @@ export const cacheDependencyGlob = core.getInput("cache-dependency-glob");
export const pruneCache = core.getInput("prune-cache") === "true"; export const pruneCache = core.getInput("prune-cache") === "true";
export const ignoreNothingToCache = export const ignoreNothingToCache =
core.getInput("ignore-nothing-to-cache") === "true"; core.getInput("ignore-nothing-to-cache") === "true";
export const ignoreEmptyWorkdir =
core.getInput("ignore-empty-workdir") === "true";
export const toolBinDir = getToolBinDir(); export const toolBinDir = getToolBinDir();
export const toolDir = getToolDir(); export const toolDir = getToolDir();
export const githubToken = core.getInput("github-token"); export const githubToken = core.getInput("github-token");