Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: Test action

on:
push:
pull_request:

jobs:
test:
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ The `isometry/setup-generic-tool` action is designed to make the use of generic

**Optional** Override tool name, if it doesn't match the repo name

### `asset` input

**Optional** Override asset name, if it doesn't match the tool name

### `version` input

**Optional** Version of tool to install (default: `latest`; example: `v1.2.3`)
Expand Down
7 changes: 6 additions & 1 deletion action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ inputs:
description: Override tool name, if it doesn't match the repo name
required: false
default: ""
asset:
description: Override asset name, if it doesn't match the tool name
required: false
default: ""
version:
description: Version of tool to install
required: false
Expand All @@ -31,5 +35,6 @@ runs:
NAME: ${{ inputs.name }}
VERSION: ${{ inputs.version }}
TOOL: ${{ inputs.tool }}
ASSET: ${{ inputs.asset }}
run: |
"${GITHUB_ACTION_PATH}/setup.sh" "${NAME}" "${VERSION}" "${TOOL}"
"${GITHUB_ACTION_PATH}/setup.sh" "${NAME}" "${VERSION}" "${TOOL}" "${ASSET}"
10 changes: 9 additions & 1 deletion setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,21 @@ IFS='/' read -r OWNER REPO <<< "${REPO_NAME}"
# Set tool name if not provided as third argument
TOOL_NAME="${3:-${REPO}}"

ASSET_NAME_INPUT="${4:-${TOOL_NAME}}"

# Validate tool name
[[ ! "${TOOL_NAME}" =~ ^[-A-Za-z0-9]+$ ]] && error "Invalid tool name"

# Determine platform and architecture
PLATFORM=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)

if [[ ${PLATFORM} == "darwin" ]]; then
PLATFORM_PATTERN="(darwin|macos)"
else
PLATFORM_PATTERN="(${PLATFORM})"
fi

# Convert architecture to common formats
case "${ARCH}" in
"aarch64"|"arm64")
Expand Down Expand Up @@ -87,7 +95,7 @@ if [[ -d "${TOOL_CACHE_DIR}" ]]; then
info "Found ${TOOL_NAME} ${VERSION} in ${TOOL_CACHE_DIR}"
else
info "Searching for ${TOOL_NAME} ${VERSION} for ${PLATFORM}/${ARCH}"
ASSET_PATTERN="^${TOOL_NAME}.+${PLATFORM}.+${ARCH_PATTERN}([.](tar[.]gz|zip))?\$"
ASSET_PATTERN="^${ASSET_NAME_INPUT}.+${PLATFORM_PATTERN}.+${ARCH_PATTERN}([.](tar[.]gz|zip))?\$"
mapfile -t ASSETS < <(jq -r --arg pattern "${ASSET_PATTERN}" '.assets[] | select(.name | test($pattern; "i")) | .name' <<< "${RELEASE_DATA}")

: "${ASSETS:?No matching release asset found}"
Expand Down