Skip to content

Commit

Permalink
fix installing gitlab CLI v1.47.0+
Browse files Browse the repository at this point in the history
  • Loading branch information
trxcllnt committed Oct 2, 2024
1 parent c9f20c5 commit ebaf0a0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 29 deletions.
5 changes: 2 additions & 3 deletions features/src/gitlab-cli/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
{
"id": "gitlab-cli",
"version": "24.12.0",
"version": "24.12.1",
"name": "GitLab CLI",
"documentationURL": "https://github.com/rapidsai/devcontainers/features/tree/main/src/gitlab-cli",
"description": "Installs the GitLab CLI. Auto-detects latest version and installs needed dependencies.",
"options": {
"version": {
"type": "string",
"proposals": [
"latest",
"none"
"latest"
],
"default": "latest",
"description": "Select version of the GitLab CLI, if not latest."
Expand Down
66 changes: 40 additions & 26 deletions features/src/gitlab-cli/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,48 +13,62 @@ cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )";
# install global/common scripts
. ./common/install.sh;

gitlab_cli_file_name() {
local -;
set -euo pipefail;

local os="$(uname -s)";
local arch="${TARGETARCH:-}";

if [[ "${CLI_VERSION}" < "1.47.0" ]]; then
arch="${arch:-$(uname -m)}";
else
arch="${arch:-$(dpkg --print-architecture | awk -F'-' '{print $NF}')}";
os="${os,,}";
fi

echo "glab_${CLI_VERSION}_${os}_${arch}.deb";
}

download_gitlab_cli_deb() {
local -;
set -euo pipefail;
wget --no-hsts -q -O /tmp/gitlab-cli.deb \
"https://gitlab.com/gitlab-org/cli/-/releases/v${CLI_VERSION}/downloads/$(gitlab_cli_file_name)";
}

# Fall back on direct download if no apt package exists
# Fetches .deb file to be installed with dpkg
install_deb_using_gitlab() {
local -;
set -euo pipefail;

check_packages wget;
arch="${TARGETARCH:-$(dpkg --print-architecture | awk -F'-' '{print $NF}')}";
if [[ "$arch" == amd64 ]]; then
arch=x86_64;
fi

find_version_from_git_tags CLI_VERSION https://gitlab.com/gitlab-org/cli;
cli_filename="glab_${CLI_VERSION}_Linux_${arch}.deb";

mkdir -p /tmp/glabcli;
pushd /tmp/glabcli;
wget https://gitlab.com/gitlab-org/cli/-/releases/v${CLI_VERSION}/downloads/${cli_filename};
exit_code=$?;
set -e;
if [ "$exit_code" != "0" ]; then
# Handle situation where git tags are ahead of what was is available to actually download
echo "(!) gitlab-cli version ${CLI_VERSION} failed to download. Attempting to fall back one version to retry...";
find_prev_version_from_git_tags CLI_VERSION https://gitlab.com/gitlab-org/cli;
wget https://gitlab.com/gitlab-org/cli/-/releases/v${CLI_VERSION}/downloads/${cli_filename};
# Soft version matching
if test "${CLI_VERSION}" = latest || test "${CLI_VERSION}" = stable || test "${CLI_VERSION}" = lts; then
find_version_from_git_tags CLI_VERSION https://gitlab.com/gitlab-org/cli;
while ! download_gitlab_cli_deb; then
# Handle situation where git tags are ahead of what was is available to actually download
echo "(!) gitlab-cli version ${CLI_VERSION} failed to download. Attempting to fall back one version to retry...";
find_prev_version_from_git_tags CLI_VERSION https://gitlab.com/gitlab-org/cli;
done
else
download_gitlab_cli_deb;
fi

dpkg -i /tmp/glabcli/${cli_filename};
popd;
rm -rf /tmp/glabcli;
dpkg -i /tmp/gitlab-cli.deb;
rm /tmp/gitlab-cli.deb;
}

export DEBIAN_FRONTEND=noninteractive;

# Install curl, apt-transport-https, curl, or git if missing
# Install curl, ca-certificates, apt-transport-https, and git (if missing)
check_packages curl ca-certificates apt-transport-https;
if ! type git >/dev/null 2>&1; then
check_packages git;
fi

# Soft version matching
if [ "${CLI_VERSION}" != "latest" ] && [ "${CLI_VERSION}" != "lts" ] && [ "${CLI_VERSION}" != "stable" ]; then
find_version_from_git_tags CLI_VERSION "https://gitlab.com/gitlab-org/cli";
fi

# Install the GitHub CLI
echo "Downloading gitlab CLI...";

Expand Down

0 comments on commit ebaf0a0

Please sign in to comment.