diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index f6aa5e5..6ed5a68 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -2,6 +2,7 @@ name: Test action on: push: + pull_request: jobs: test: diff --git a/README.md b/README.md index a5aa5b3..9e65714 100644 --- a/README.md +++ b/README.md @@ -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`) diff --git a/action.yaml b/action.yaml index 883dc91..d90b864 100644 --- a/action.yaml +++ b/action.yaml @@ -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 @@ -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}" diff --git a/setup.sh b/setup.sh index d5f5fc1..32e423c 100755 --- a/setup.sh +++ b/setup.sh @@ -31,6 +31,8 @@ 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" @@ -38,6 +40,12 @@ TOOL_NAME="${3:-${REPO}}" 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") @@ -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}"