Skip to content

Commit 8dded38

Browse files
committed
Support gh cli installation without sudo
1 parent 46b279a commit 8dded38

6 files changed

Lines changed: 118 additions & 4 deletions

File tree

script/README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# MLCommons Automation Scripts
22

3-
*Last updated: 2026-06-05 03:03:14*
3+
*Last updated: 2026-06-14 16:16:11*
44

55
This directory contains automation scripts for MLPerf benchmarks, AI/ML workflows, and development operations.
66

@@ -34,6 +34,7 @@ This directory contains automation scripts for MLPerf benchmarks, AI/ML workflow
3434
- [ROCm automation](#rocm-automation)
3535
- [Remote automation](#remote-automation)
3636
- [Reproducibility and artifact evaluation](#reproducibility-and-artifact-evaluation)
37+
- [SPEC Utils](#spec-utils)
3738
- [Testing](#testing)
3839
- [Tests](#tests)
3940
- [TinyML automation](#tinyml-automation)
@@ -1060,6 +1061,12 @@ This directory contains automation scripts for MLPerf benchmarks, AI/ML workflow
10601061
- get-ipol-src
10611062
- Tags: `get`, `ipol`, `journal`, `src`, `ipol-src`
10621063

1064+
## SPEC Utils
1065+
1066+
- **[run-spec-cpu](run-spec-cpu/)**
1067+
- run-spec-cpu
1068+
- Tags: `cpu`, `run`, `spec`
1069+
10631070
## Testing
10641071

10651072
- **[validate-mlc-json](validate-mlc-json/)**
@@ -1244,8 +1251,8 @@ This directory contains automation scripts for MLPerf benchmarks, AI/ML workflow
12441251

12451252
## Statistics
12461253

1247-
- **Total Scripts**: 365
1248-
- **Categories**: 34
1254+
- **Total Scripts**: 366
1255+
- **Categories**: 35
12491256

12501257
## Usage
12511258

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from mlc import utils
2+
from utils import is_true
23
import os
4+
import subprocess
35

46

57
def preprocess(i):
@@ -8,7 +10,35 @@ def preprocess(i):
810

911
env = i['env']
1012

11-
env['MLC_TMP_PATH'] = os.path.join(os.getcwd(), 'install', 'bin')
13+
# Support custom install path via MLC_GH_INSTALL_PATH
14+
custom_path = env.get('MLC_GH_INSTALL_PATH', '')
15+
if custom_path:
16+
install_dir = os.path.abspath(custom_path)
17+
else:
18+
install_dir = os.path.join(os.getcwd(), 'install')
19+
20+
bin_dir = os.path.join(install_dir, 'bin')
21+
22+
env['MLC_TMP_PATH'] = bin_dir
1223
env['MLC_TMP_FAIL_IF_NOT_FOUND'] = 'yes'
24+
env['MLC_GH_INSTALL_DIR'] = install_dir
25+
26+
sudo = env.get('MLC_SUDO', '')
27+
28+
# Allow user to explicitly disable sudo via MLC_SUDO=no
29+
if sudo == 'no':
30+
sudo = ''
31+
env['MLC_SUDO'] = ''
32+
33+
if sudo:
34+
# Check if sudo is actually available
35+
try:
36+
subprocess.run(['sudo', '-n', 'true'], capture_output=True, timeout=5)
37+
except (FileNotFoundError, subprocess.TimeoutExpired):
38+
sudo = ''
39+
env['MLC_SUDO'] = ''
40+
41+
if not sudo:
42+
env['MLC_GH_INSTALL_WITHOUT_SUDO'] = 'yes'
1343

1444
return {'return': 0}

script/install-github-cli/meta.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ tags:
1616
cache: true
1717
clean_files: []
1818

19+
# Environment
20+
default_env:
21+
MLC_SUDO: sudo
22+
1923
# Dependencies
2024
deps:
2125
- tags: detect,os
26+
27+
# Tests
28+
tests:
29+
run_inputs:
30+
- env: {}
31+
- env:
32+
MLC_SUDO: 'no'
33+
- env:
34+
MLC_SUDO: 'no'
35+
MLC_GH_INSTALL_PATH: /tmp/gh-cli-test
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/bash
2+
3+
# Install GitHub CLI without sudo by downloading pre-built binary
4+
5+
INSTALL_DIR="${MLC_GH_INSTALL_DIR:-$(pwd)/install}"
6+
mkdir -p "${INSTALL_DIR}"
7+
8+
# Detect architecture
9+
ARCH=$(uname -m)
10+
case "${ARCH}" in
11+
x86_64) GH_ARCH="amd64" ;;
12+
aarch64) GH_ARCH="arm64" ;;
13+
armv7l) GH_ARCH="armv6" ;;
14+
*)
15+
echo "Unsupported architecture: ${ARCH}"
16+
exit 1
17+
;;
18+
esac
19+
20+
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
21+
22+
# Get latest version from GitHub API
23+
GH_VERSION=$(curl -sL https://api.github.com/repos/cli/cli/releases/latest | grep '"tag_name"' | sed -E 's/.*"v([^"]+)".*/\1/')
24+
if [ -z "${GH_VERSION}" ]; then
25+
echo "Failed to determine latest gh version"
26+
exit 1
27+
fi
28+
29+
echo "Downloading gh CLI v${GH_VERSION} for ${OS}_${GH_ARCH}..."
30+
31+
TARBALL="gh_${GH_VERSION}_${OS}_${GH_ARCH}.tar.gz"
32+
DOWNLOAD_URL="https://github.com/cli/cli/releases/download/v${GH_VERSION}/${TARBALL}"
33+
34+
curl -sL "${DOWNLOAD_URL}" -o "${INSTALL_DIR}/${TARBALL}"
35+
test $? -eq 0 || exit 1
36+
37+
# Extract and place binary
38+
tar -xzf "${INSTALL_DIR}/${TARBALL}" -C "${INSTALL_DIR}" --strip-components=1
39+
test $? -eq 0 || exit 1
40+
41+
# Clean up tarball
42+
rm -f "${INSTALL_DIR}/${TARBALL}"
43+
44+
# Verify
45+
if [ -x "${INSTALL_DIR}/bin/gh" ]; then
46+
echo "gh CLI installed to ${INSTALL_DIR}/bin/gh"
47+
else
48+
echo "Installation failed: gh binary not found"
49+
exit 1
50+
fi
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
#!/bin/bash
2+
3+
if [ "${MLC_GH_INSTALL_WITHOUT_SUDO}" == "yes" ]; then
4+
bash ${MLC_SOURCE}/run-nosudo.sh
5+
exit $?
6+
fi
7+
18
sudo dnf install -y 'dnf-command(config-manager)'
29
sudo dnf config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo
310
sudo dnf install -y gh

script/install-github-cli/run.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
#!/bin/bash
2+
3+
if [ "${MLC_GH_INSTALL_WITHOUT_SUDO}" == "yes" ]; then
4+
bash ${MLC_SOURCE}/run-nosudo.sh
5+
exit $?
6+
fi
7+
28
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
39
&& sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
410
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \

0 commit comments

Comments
 (0)