Skip to content
Closed
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
19 changes: 19 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Test action

on:
push:

jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 5
container:
image: ubuntu:20.04
steps:
- uses: actions/checkout@v4
- run: apt update && apt install -y curl jq
- uses: ./
with:
name: cli/cli
tool: gh
- run: gh --version
20 changes: 15 additions & 5 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ info() {
}

# Check for required commands
command -v gh >/dev/null 2>&1 || error "GitHub CLI (gh) is required but not installed"
command -v curl >/dev/null 2>&1 || error "curl is required but not installed"
command -v jq >/dev/null 2>&1 || error "jq is required but not installed"

# Get inputs
Expand Down Expand Up @@ -53,13 +53,21 @@ case "${ARCH}" in
;;
esac

invoke_curl() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
invoke_curl() {
v3_api_call() {

curl -sfL \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GH_TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/$1"
}

# Get release information using GitHub CLI
if [ "${VERSION}" = "latest" ]; then
RELEASE_DATA=$(gh api "repos/${OWNER}/${REPO}/releases/latest")
if [[ "${VERSION}" = "latest" ]]; then
RELEASE_DATA=$(invoke_curl "repos/${OWNER}/${REPO}/releases/latest")
VERSION=$(jq -r '.tag_name' <<< "${RELEASE_DATA}")
info "Resolved latest version: ${VERSION}"
else
RELEASE_DATA=$(gh api "repos/${OWNER}/${REPO}/releases/tags/${VERSION}")
RELEASE_DATA=$(invoke_curl "repos/${OWNER}/${REPO}/releases/tags/${VERSION}")
fi

# Create cache directory
Expand Down Expand Up @@ -90,7 +98,9 @@ else

# Download and extract asset using gh cli
info "Fetching ${ASSET_NAME} from ${OWNER}/${REPO}#${VERSION}"
gh release download "${VERSION}" -R "${OWNER}/${REPO}" -p "${ASSET_NAME}"
DOWNLOAD_URL=$(jq -r --arg asset "${ASSET_NAME}" '.assets[] | select(.name == $asset) | .browser_download_url' <<< "${RELEASE_DATA}")
echo "Download URL: ${DOWNLOAD_URL}"
curl -sSL -H "Authorization: token ${GH_TOKEN}" -o "${ASSET_NAME}" "${DOWNLOAD_URL}"

if [[ "${ASSET_NAME}" == *.zip ]]; then
info "Extracting ${ASSET_NAME}"
Expand Down