-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from delilahw/fix-install-script-and-tests
fix(keyring): Fix install script and add tests
- Loading branch information
Showing
10 changed files
with
158 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,67 @@ | ||
#!/bin/bash | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
WHEEL_URL='https://github.com/microsoft/codespace-features/releases/download/latest/codespaces_artifacts_helper_keyring-0.1.0-py3-none-any.whl' | ||
WHEEL_DEST_FILENAME='codespaces_artifacts_helper_keyring-0.1.0-py3-none-any.whl' | ||
|
||
cd /tmp | ||
wget https://github.com/microsoft/codespace-features/releases/download/latest/codespaces_artifacts_helper_keyring-0.1.0-py3-none-any.whl | ||
if python3 -m pip &> /dev/null; then | ||
python3 -m pip install codespaces_artifacts_helper_keyring-0.1.0-py3-none-any.whl | ||
elif command -v pip3 &> /dev/null; then | ||
pip3 install codespaces_artifacts_helper_keyring-0.1.0-py3-none-any.whl | ||
elif python -m pip &> /dev/null; then | ||
python -m pip install codespaces_artifacts_helper_keyring-0.1.0-py3-none-any.whl | ||
elif command -v pip &> /dev/null; then | ||
pip install codespaces_artifacts_helper_keyring-0.1.0-py3-none-any.whl | ||
|
||
while [[ "$#" -gt 0 ]]; do | ||
case $1 in | ||
-h | --help) | ||
echo "Usage: $(basename "$0") [(-u | --user) <user>] [-h | --help] | ||
Options: | ||
-h --help Show this screen. | ||
-u USER, --user USER Install for another user by specifying their name. | ||
Alternatively, set the USER environment variable. | ||
" | ||
exit | ||
;; | ||
|
||
-u | --user) | ||
USER="$2" | ||
shift | ||
;; | ||
|
||
*) | ||
echo "Unknown parameter passed: $1" | ||
exit 1 | ||
;; | ||
esac | ||
shift | ||
done | ||
|
||
# Find the path to the Python executable outside of sudo, to account for Python | ||
# not being present in the secure_path. | ||
if command -v python3 &>/dev/null; then | ||
PYTHON_SRC=$(which python3) | ||
elif command -v python &>/dev/null; then | ||
PYTHON_SRC=$(which python) | ||
else | ||
echo "pip installation not detected. Artifacts Helper keyring not installed." | ||
echo "Python not found. Artifacts Helper keyring not installed. whoami=$(whoami), PATH=$PATH" | ||
exit 1 | ||
fi | ||
|
||
sudo_if_user() { | ||
COMMAND="$*" | ||
if [[ $USER ]]; then | ||
if ! command -v sudo >/dev/null 2>&1; then | ||
echo "The --user option was specified, but sudo could not be found." | ||
exit 1 | ||
fi | ||
sudo -u "$USER" bash -c "$COMMAND" | ||
else | ||
$COMMAND | ||
fi | ||
} | ||
|
||
install_user_package() { | ||
sudo_if_user "${PYTHON_SRC}" -m pip install --user --upgrade --no-cache-dir "$1" | ||
} | ||
|
||
wget "$WHEEL_URL" -O "$WHEEL_DEST_FILENAME" | ||
chmod a=r "$WHEEL_DEST_FILENAME" # Usually not needed, but helpful just in case | ||
install_user_package "$WHEEL_DEST_FILENAME" | ||
rm "$WHEEL_DEST_FILENAME" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Import test library bundled with the devcontainer CLI | ||
source dev-container-features-test-lib || exit 1 | ||
|
||
# Confidence check for prerequisites | ||
check 'pip should be installed' python3 -m pip --version | ||
|
||
check 'keyring should be installed' python3 -m pip show keyring | ||
check 'codespaces_artifacts_helper_keyring should be installed' python3 -m pip show codespaces_artifacts_helper_keyring | ||
|
||
# Report results | ||
# If any of the checks above exited with a non-zero exit code, the test will fail. | ||
reportResults |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
./check_python_and_keyring.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
./check_python_and_keyring.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
./check_python_and_keyring.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Import test library bundled with the devcontainer CLI | ||
source dev-container-features-test-lib || exit 1 | ||
|
||
# Confidence check for prerequisites | ||
check 'pip should be installed' bash -c 'python3 -m pip --version' | ||
|
||
check 'codespaces_artifacts_helper_keyring should not be installed' bash -c '! python3 -m pip show codespaces_artifacts_helper_keyring' | ||
|
||
# Report results | ||
# If any of the checks above exited with a non-zero exit code, the test will fail. | ||
reportResults |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"python38_and_keyring_debian": { | ||
"image": "mcr.microsoft.com/devcontainers/base:debian", | ||
"features": { | ||
"ghcr.io/devcontainers/features/python:1": { | ||
"version": "3.8" | ||
}, | ||
"artifacts-helper": { | ||
"python": true | ||
} | ||
} | ||
}, | ||
"python38_and_keyring_ubuntu": { | ||
"image": "mcr.microsoft.com/devcontainers/base:ubuntu", | ||
"features": { | ||
"ghcr.io/devcontainers/features/python:1": { | ||
"version": "3.8" | ||
}, | ||
"artifacts-helper": { | ||
"python": true | ||
} | ||
} | ||
}, | ||
"python312_and_keyring_debian": { | ||
"image": "mcr.microsoft.com/devcontainers/base:debian", | ||
"features": { | ||
"ghcr.io/devcontainers/features/python:1": { | ||
"version": "3.12" | ||
}, | ||
"artifacts-helper": { | ||
"python": true | ||
} | ||
} | ||
}, | ||
"python_and_no_keyring": { | ||
"image": "mcr.microsoft.com/devcontainers/base:debian", | ||
"features": { | ||
"ghcr.io/devcontainers/features/python:1": { | ||
"version": "3.8" | ||
}, | ||
"artifacts-helper": { | ||
"python": false | ||
} | ||
} | ||
} | ||
} |