Skip to content

Commit 810d622

Browse files
fix: add GitHub token support to install script for authenticated API requests
1 parent 45d397c commit 810d622

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

.github/workflows/install-script-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525

2626
- name: Run install script
2727
shell: bash
28-
run: bash install-cli.sh --debug
28+
run: bash install-cli.sh --debug --token ${{ secrets.GITHUB_TOKEN }}
2929

3030
- name: Verify installation
3131
shell: bash

install-cli.sh

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ ARCH="unknown"
1010
VERSION=""
1111
FILE_NAME="kosli"
1212
DEBUG=false
13+
GITHUB_TOKEN=""
1314

1415
# --- Debug function ---
1516
debug_print() {
@@ -26,6 +27,16 @@ while [ $# -gt 0 ]; do
2627
debug_print "Debug mode enabled"
2728
shift
2829
;;
30+
--token)
31+
if [ -n "${2:-}" ]; then
32+
GITHUB_TOKEN="$2"
33+
debug_print "GitHub token provided"
34+
shift 2
35+
else
36+
echo "Error: --token requires a value"
37+
exit 1
38+
fi
39+
;;
2940
*)
3041
VERSION=$1
3142
debug_print "Version specified: $VERSION"
@@ -46,7 +57,13 @@ else
4657
RETRY_COUNT=0
4758
MAX_RETRIES=5
4859
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
49-
METADATA=$(curl -s "https://api.github.com/repos/kosli-dev/cli/releases/latest")
60+
if [ -n "$GITHUB_TOKEN" ]; then
61+
debug_print "Using GitHub token for API request"
62+
METADATA=$(curl -s -H "Authorization: token $GITHUB_TOKEN" "https://api.github.com/repos/kosli-dev/cli/releases/latest")
63+
else
64+
debug_print "Using unauthenticated API request"
65+
METADATA=$(curl -s "https://api.github.com/repos/kosli-dev/cli/releases/latest")
66+
fi
5067
debug_print "GitHub API response: $METADATA"
5168

5269
# Check if the response contains the expected tag_name

0 commit comments

Comments
 (0)