Fix: Correct file-type input for asset selection and enhance regex filtering debugging with dry run support
Test Action / test (push) Failing after 7s

This commit is contained in:
2026-04-07 07:02:42 +02:00
parent e7e7ee53f6
commit 26ef54930a
4 changed files with 33 additions and 20 deletions
+1
View File
@@ -35,6 +35,7 @@ jobs:
with:
repository: 'gohugoio/hugo'
file-name: '~hugo_extended_[^a-z]'
file-type: 'archive'
token: ${{ secrets.GH_TOKEN }}
update-cache: 'always'
+11 -11
View File
@@ -117,15 +117,10 @@ The following inputs are available for the GitHub Action, and as options for the
- `binary-name` (optional): The name or regex pattern (prefixed with `~`) of the binary to search for within the downloaded asset. Defaults to the repository name.
- `file-type` (optional): Asset type selector.
- `archive`: matches `.zip`, `.tar.gz`, `.tgz`.
- `package`: matches `.deb`, `.pkg`, `.rpm`.
- short forms: `zip`, `gzip`, `gz`, `tar`, `tar.gz`, `tgz`, `deb`, `pkg`, `rpm`.
If not provided, selection defaults to OS-aware combined package/archive patterns:
- Linux: `.deb`, `.rpm`, `.zip`, `.tar.gz`, `.tgz`
- macOS: `.pkg`, `.zip`, `.tar.gz`, `.tgz`
- other: `.zip`, `.tar.gz`, `.tgz`
- known values: `archive`, `package`, `linux`, `macos`, `targz`.
- custom values:
`~<regex>` for regular expression matching (anchored to the end of file name), or
extension form such as `zip` or `.tar.gz`.
- `install-path` (optional, CLI only): Custom installation directory for the CLI tool.
- `update-cache` (optional, default: 'false', Action only): When set to 'false', the action will use the cached version of the tool if it is already available. If set to 'true', the action will check the latest release and update the cache if a newer version is found. If set to 'always', it will always download and install, updating the cache regardless.
@@ -151,7 +146,8 @@ Options:
-a, --app-name <name> Application name (optional, for output messages)
-f, --file-name <name> Asset file name or regex pattern (prefixed with ~)
-b, --binary-name <name> Binary name (supports source:destination form)
-t, --file-type <type> archive|package|zip|gzip|gz|tar|tar.gz|tgz|deb|pkg|rpm
-t, --file-type <type> Known: archive|package|linux|macos|targz
Or custom: ~<regex> (end-of-string match) or extension (e.g. zip, .tar.gz)
-p, --install-path <path> Custom installation directory
-o, --output-directory <path>
Only download selected asset to the specified directory
@@ -210,7 +206,11 @@ The list of assets from the latest release is filtered based on the following ru
- If it already ends with `$` or includes all three placeholders, the tool uses it as-is to match the asset name using regex.
- If only `{{SYSTEM}}` and `{{ARCH}}` placeholders are included, the tool appends `.*{{EXT_PATTERN}}$`.
4. If `file-type` is provided, supported values are: `archive`, `package`, `zip`, `gzip`, `gz`, `tar`, `tar.gz`, `tgz`, `deb`, `pkg`, `rpm`.
4. If `file-type` is provided:
- known values are: `archive`, `package`, `linux`, `macos`, `targz`.
- `~<regex>` is treated as a regex and matched at the end of the file name.
- any other value is treated as an extension selector (for example `zip` or `.tar.gz`).
5. The tool applies the constructed regex pattern to filter the assets from the latest release.
+1 -1
View File
@@ -12,7 +12,7 @@ inputs:
description: 'The name or regex pattern (prefixed with ~) of the binary to search for within the asset. Defaults to the repository name.'
required: false
file-type:
description: 'Asset type selector: archive, package, zip, gzip, gz, tar, tar.gz, tgz, deb, pkg, rpm.'
description: 'Asset type selector. Known values: archive, package, linux, macos, targz. Custom values: ~<regex> or extension (e.g. zip, .tar.gz).'
required: false
update-cache:
description: 'How to handle the tool cache (false, true, or always). Defaults to false.'
+20 -8
View File
@@ -21768,8 +21768,8 @@ var systemPatterns = {
win32: "(windows|win)"
};
var archPatterns = {
x64: "(x86_64|x64|amd64)",
arm64: "(aarch64|arm64)"
x64: "(x86_64|x64|amd64|universal)",
arm64: "(aarch64|arm64|universal)"
};
function getPlatformInfo(overrides) {
const system = (overrides?.system || os.platform()).toLowerCase();
@@ -23592,14 +23592,26 @@ var knownFileTypes = {
macos: "*.pkg",
targz: "*.{tgz,tar.gz}"
};
function filterByRegex(assets, pattern) {
function debugAssetList(label, assets) {
console.debug(label);
for (const asset of assets) {
console.debug(`- ${asset.name}`);
}
}
function filterByRegex(assets, pattern, dryRun) {
const regex = new RegExp(pattern, "i");
return assets.filter((asset) => regex.test(asset.name));
const filtered = assets.filter((asset) => regex.test(asset.name));
if (dryRun) {
console.debug(`Filtering assets with regex: ${pattern}`);
debugAssetList("Assets:", assets);
debugAssetList("Matched assets:", filtered);
}
return filtered;
}
function replacePlatformPlaceholders(pattern, platform2) {
return pattern.replace(/{{SYSTEM}}/g, platform2.systemPattern).replace(/{{ARCH}}/g, platform2.archPattern);
}
function getMatchingAsset(assets, platform2, fileName, fileType) {
function getMatchingAsset(assets, platform2, fileName, fileType, dryRun) {
if (fileName && !fileName.startsWith("~")) {
const exactMatches = assets.filter((asset) => asset.name === fileName);
if (exactMatches.length !== 1) {
@@ -23614,7 +23626,7 @@ function getMatchingAsset(assets, platform2, fileName, fileType) {
fileTypeFilteredAssets = assets.filter((asset) => minimatch(asset.name, fileTypeGlob, { nocase: true }));
} else if (fileType.startsWith("~")) {
const fileTypeRegex = `${fileType.substring(1)}$`;
fileTypeFilteredAssets = filterByRegex(assets, fileTypeRegex);
fileTypeFilteredAssets = filterByRegex(assets, fileTypeRegex, dryRun);
} else {
const extension = fileType.replace(/^\./, "");
const fileTypeGlob = `*.${extension}`;
@@ -23623,14 +23635,14 @@ function getMatchingAsset(assets, platform2, fileName, fileType) {
}
if (fileName && fileName.startsWith("~")) {
const fileNamePattern = replacePlatformPlaceholders(fileName.substring(1), platform2);
const fileNameFilteredAssets = filterByRegex(fileTypeFilteredAssets, fileNamePattern);
const fileNameFilteredAssets = filterByRegex(fileTypeFilteredAssets, fileNamePattern, dryRun);
if (fileNameFilteredAssets.length !== 1) {
throw new Error(`Expected exactly one asset to match the filename regex, matched: ${fileNameFilteredAssets.length}`);
}
return fileNameFilteredAssets[0];
}
const defaultPattern = replacePlatformPlaceholders("{{SYSTEM}}[_-]{{ARCH}}", platform2);
const defaultFilteredAssets = filterByRegex(fileTypeFilteredAssets, defaultPattern);
const defaultFilteredAssets = filterByRegex(fileTypeFilteredAssets, defaultPattern, dryRun);
if (defaultFilteredAssets.length !== 1) {
const errorMessage = defaultFilteredAssets.length === 0 ? `No assets matched the default criteria: ${defaultPattern}` : `Multiple assets matched the default criteria: ${defaultFilteredAssets.map((asset) => asset.name).join(", ")}`;
throw new Error(errorMessage);