这是indexloc提供的服务,不要输入任何密码
Skip to content

fix: improve installation script by using a temporary directory for downloads #354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

prasad89
Copy link
Contributor

@prasad89 prasad89 commented Jun 17, 2025

Previously, the install.sh script extracted the tarball into the current working directory, leaving behind files like LICENSE, README, and the binary. This PR fixes that by using a temporary directory for all downloads and extraction, ensuring no leftover files clutter the user’s workspace.

@tuannvm
Copy link
Contributor

tuannvm commented Jun 17, 2025

@prasad89 I just ran and I see this error as well, is it something you could also have a look at? Thanks!

curl -sSL https://raw.githubusercontent.com/GoogleCloudPlatform/kubectl-ai/main/install.sh | bash
Failed to fetch latest release tag.

@prasad89
Copy link
Contributor Author

@prasad89 I just ran and I see this error as well, is it something you could also have a look at? Thanks!

curl -sSL https://raw.githubusercontent.com/GoogleCloudPlatform/kubectl-ai/main/install.sh | bash
Failed to fetch latest release tag.

Sure will take a look

@prasad89
Copy link
Contributor Author

@tuannvm do you see this error all the time or just saw once?
seems like this could be due to rate limit on api.github.

@tuannvm
Copy link
Contributor

tuannvm commented Jun 18, 2025

@prasad89 you are right. Now I ran again and I don't see it anymore. Looks like we need to handle the rate limit better. Any idea?

@mikebz mikebz requested a review from Copilot June 18, 2025 17:29
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves the installation script by using a temporary directory to download and extract the release tarball.

  • Creates a temporary directory with a cleanup trap
  • Downloads the tarball to the temporary directory and extracts it there
  • Installs the binary from the temporary directory

@@ -64,16 +64,17 @@ fi
TARBALL="kubectl-ai_${OS}_${ARCH}.tar.gz"
URL="https://github.com/$REPO/releases/download/$LATEST_TAG/$TARBALL"

# Create temp dir and clean up on exit
tmpdir="$(mktemp -d)"
trap "rm -rf '$tmpdir'" EXIT
Copy link
Preview

Copilot AI Jun 18, 2025

Choose a reason for hiding this comment

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

The trap command encloses $tmpdir in single quotes, which prevents variable expansion at the time the trap is executed, causing the temporary directory not to be cleaned up. Consider changing the command to: trap "rm -rf "$tmpdir"" EXIT.

Suggested change
trap "rm -rf '$tmpdir'" EXIT
trap "rm -rf \"$tmpdir\"" EXIT

Copilot uses AI. Check for mistakes.

@prasad89
Copy link
Contributor Author

prasad89 commented Jun 18, 2025

@tuannvm don't have any as of now, but thinking clear error message would be better something like:

echo "❌ Failed to fetch latest release tag. You may have hit GitHub's rate limit."
echo "Try setting a GitHub token: export GITHUB_TOKEN=TOKEN"

what are your thoughts on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants