diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml index f7978bb..5eb01d3 100644 --- a/.gitea/workflows/test.yml +++ b/.gitea/workflows/test.yml @@ -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' diff --git a/README.md b/README.md index 6f11699..4c424d6 100644 --- a/README.md +++ b/README.md @@ -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: + `~` 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 Application name (optional, for output messages) -f, --file-name Asset file name or regex pattern (prefixed with ~) -b, --binary-name Binary name (supports source:destination form) - -t, --file-type archive|package|zip|gzip|gz|tar|tar.gz|tgz|deb|pkg|rpm + -t, --file-type Known: archive|package|linux|macos|targz + Or custom: ~ (end-of-string match) or extension (e.g. zip, .tar.gz) -p, --install-path Custom installation directory -o, --output-directory 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`. + - `~` 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. diff --git a/action.yml b/action.yml index 140e67e..9680a62 100644 --- a/action.yml +++ b/action.yml @@ -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: ~ 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.' diff --git a/dist/index.js b/dist/index.js index 96bbce0..98ae7a7 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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);