-
Notifications
You must be signed in to change notification settings - Fork 86
upstream_merge: Extract pipeline tool installation #366
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
base: nilrt/master/scarthgap
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| : "${TOOLS_DIR:?TOOLS_DIR environment variable is not set}" | ||
|
|
||
| required_cmds=(jq curl tar sha256sum perl mktemp grep) | ||
| for cmd in "${required_cmds[@]}"; do | ||
| if ! command -v "$cmd" >/dev/null; then | ||
| echo "Required command '$cmd' is missing on the agent." >&2 | ||
| exit 1 | ||
| fi | ||
| done | ||
|
|
||
| cwd="$(pwd -P)" | ||
| parent="${cwd%/*}" | ||
| [[ -z "$parent" ]] && parent="/" | ||
|
|
||
| mkdir -p -- "$TOOLS_DIR" | ||
| TOOLS_DIR="$(cd -P -- "$TOOLS_DIR" && pwd -P)" | ||
|
|
||
| if [[ "$TOOLS_DIR" == "/" || "$TOOLS_DIR" == "$cwd" || "$TOOLS_DIR" == "$parent" ]]; then | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this check happen before the dir is even created in line 19? |
||
| echo "Refusing to use unsafe TOOLS_DIR: $TOOLS_DIR" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| rm -rf -- "$TOOLS_DIR" | ||
| mkdir -p -- "$TOOLS_DIR" | ||
|
|
||
| export PATH="$TOOLS_DIR:$PATH" | ||
|
|
||
| echo "Installing git-send-email..." | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not just use a docker image with all required tools installed? I assume this is run in a pipeline in which case docker will be available. |
||
|
|
||
| GIT_SEND_EMAIL_SHA256=15094e3fc8cfbe7931a9aceac99bdc82537d42d3be67ee90518b2371fc7869bf | ||
|
|
||
| curl \ | ||
| --fail \ | ||
| --location \ | ||
| --show-error \ | ||
| --connect-timeout 30 \ | ||
| --max-time 300 \ | ||
| https://raw.githubusercontent.com/git/git/v2.44.0/git-send-email.perl \ | ||
| -o "$TOOLS_DIR/git-send-email" | ||
|
|
||
| echo "${GIT_SEND_EMAIL_SHA256} ${TOOLS_DIR}/git-send-email" \ | ||
| | sha256sum -c - | ||
|
|
||
| chmod +x "$TOOLS_DIR/git-send-email" | ||
|
Shreejit-03 marked this conversation as resolved.
|
||
|
|
||
| echo "Installing GitHub CLI..." | ||
|
|
||
| ARCH=$(uname -m) | ||
|
|
||
| case "$ARCH" in | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really need this check? Are we expecting this script to be run on any other machine than x86/64? If not, let's remove; no need to complicate the script. |
||
| x86_64) | ||
| GH_ARCH=amd64 | ||
| ;; | ||
| aarch64|arm64) | ||
| GH_ARCH=arm64 | ||
| ;; | ||
| *) | ||
| echo "Unsupported architecture: $ARCH" >&2 | ||
| exit 1 | ||
| ;; | ||
| esac | ||
|
|
||
| readonly GH_VERSION="2.47.0" | ||
|
|
||
| workdir="$(mktemp -d)" | ||
| cleanup() { | ||
| rm -rf -- "$workdir" | ||
| } | ||
| trap cleanup EXIT | ||
|
|
||
| cd -- "$workdir" | ||
|
|
||
| curl \ | ||
| --fail \ | ||
| --location \ | ||
| --show-error \ | ||
| --connect-timeout 30 \ | ||
| --max-time 300 \ | ||
| -o gh.tar.gz \ | ||
| "https://github.com/cli/cli/releases/download/v${GH_VERSION}/gh_${GH_VERSION}_linux_${GH_ARCH}.tar.gz" | ||
|
|
||
| curl \ | ||
| --fail \ | ||
| --location \ | ||
| --show-error \ | ||
| --connect-timeout 30 \ | ||
| --max-time 300 \ | ||
| -o checksums.txt \ | ||
| "https://github.com/cli/cli/releases/download/v${GH_VERSION}/gh_${GH_VERSION}_checksums.txt" | ||
|
|
||
| grep -F "gh_${GH_VERSION}_linux_${GH_ARCH}.tar.gz" checksums.txt \ | ||
| | sha256sum -c - | ||
|
|
||
| tar -xzf gh.tar.gz | ||
|
|
||
| cp \ | ||
| "gh_${GH_VERSION}_linux_${GH_ARCH}/bin/gh" \ | ||
| "$TOOLS_DIR/gh" | ||
|
|
||
| chmod +x "$TOOLS_DIR/gh" | ||
|
|
||
| command -v git-send-email >/dev/null | ||
| command -v gh >/dev/null | ||
|
|
||
| gh --version | ||
|
|
||
| echo "All required tools are ready." | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason we've to use a user provided TOOLS_DIR? Can't we just create a temp dir using
mktemp -d? If we do that we can get rid of most of sanity checks below.