Skip to content

Commit

Permalink
Windows support (#83)
Browse files Browse the repository at this point in the history
* Windows support

* Support Windows sort utility

* Additional executors
  • Loading branch information
bjohnso5 committed May 6, 2024
1 parent 637a5b8 commit c8f142c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 10 deletions.
21 changes: 17 additions & 4 deletions .circleci/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ jobs:
executor: gcp-cli/default
steps:
- checkout
- run: python --version
- gcp-cli/setup:
components: kubectl package-go-module # smallest not install gcloud components
- run: gcloud components list | grep package-go-module || exit 1
Expand All @@ -78,13 +79,25 @@ jobs:
executor: gcp-cli/default
steps:
- checkout
- run: python --version
- gcp-cli/setup:
use_oidc: true

executors:
alpine:
docker:
- image: python:3.7-alpine
- image: python:3.8-alpine
windows-2019:
machine:
resource_class: windows.medium
image: windows-server-2019-vs2019:current
windows-2022:
machine:
resource_class: windows.medium
image: windows-server-2022-gui:current
ubuntu-2204-edge:
machine:
image: ubuntu-2204:edge

workflows:
test-deploy:
Expand All @@ -93,8 +106,8 @@ workflows:
matrix:
alias: test-executor-versions
parameters:
executor: [gcp-cli/default, gcp-cli/machine]
version: [latest, 370.0.0, 410.0.0]
executor: [gcp-cli/default, gcp-cli/machine, ubuntu-2204-edge, windows-2019, windows-2022]
version: [latest, 456.0.0, 460.0.0]
context: orb-publisher
filters: *filters

Expand All @@ -110,7 +123,7 @@ workflows:
matrix:
alias: test-google-versions
parameters:
version: [latest, 370.0.0, 410.0.0]
version: [latest, 456.0.0, 410.0.0]
context: orb-publisher
filters: *filters

Expand Down
2 changes: 1 addition & 1 deletion src/executors/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: The default executor is the CircleCI Python Convenience Image.
parameters:
version:
type: string
default: "3.7"
default: "3.8"
description: |
Python version to use. Take into account the versions of Python available
from CircleCI (https://hub.docker.com/r/cimg/python/tags) as well as what
Expand Down
34 changes: 29 additions & 5 deletions src/scripts/install.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ install() {
download_with_retry "$install_dir/google-cloud-sdk.tar.gz" "$url_path_fixture" "$arg_version" "$install_dir" || exit 1
printf '%s\n' ". $install_dir/google-cloud-sdk/path.bash.inc" >> "$BASH_ENV"

# If the envinronment is Alpine, remind the user to source $BASH_ENV in every step.
# If the environment is Alpine, remind the user to source $BASH_ENV in every step.
if [ -f /etc/os-release ] && grep -q "Alpine" "/etc/os-release"; then
printf '%s\n' "Alpine detected. Please make sure to source \$BASH_ENV in every step."
printf '%s\n' "Otherwise gcloud won't be available."
Expand All @@ -54,14 +54,14 @@ install() {
}

uninstall() {
if ! command -v sudo > /dev/null 2>&1; then
if [ "${platform}" != "windows" ] && ! command -v sudo > /dev/null 2>&1; then
printf '%s\n' "sudo is required to uninstall the Google Cloud SDK."
printf '%s\n' "Please install it and try again."
return 1
fi

# Set sudo to work whether logged in as root user or non-root user.
if [ "$(id -u)" -eq 0 ]; then sudo=""; else sudo="sudo"; fi
if [ "$(id -u)" -eq 0 ] || [ "${platform}" = "windows" ]; then sudo=""; else sudo="sudo"; fi

local installation_directory
installation_directory="$(gcloud info --format='value(installation.sdk_root)')"
Expand Down Expand Up @@ -119,6 +119,30 @@ if ! command -v curl > /dev/null 2>&1; then
exit 1
fi

unameOut="$(uname -s)"
case "${unameOut}" in
Linux*) platform=linux;;
Darwin*) platform=mac;;
CYGWIN*) platform=windows;;
MINGW*) platform=windows;;
MSYS_NT*) platform=windows;;
*) platform="UNKNOWN:${unameOut}"
esac

printf "Detected platform: %s (%s)\n" "${platform}" "$(python --version)"

sort_versions () {
local installed_version="$1"
local version="$2"

if [ "$platform" = "windows" ]; then
# this leans on the knowledge that node is bundled in the machine images
printf "%s %s" "$installed_version" "$version" | xargs npx semver | head -n 1
else
printf '%s\n%s\n' "$installed_version" "$version" | sort -V | head -n 1
fi
}

# Figure out what is latest version available if "latest" is passed as an argument.
version="$ORB_VAL_VERSION"
[ "$version" = "latest" ] && fetch_latest_version
Expand All @@ -128,8 +152,8 @@ if command -v gcloud > /dev/null 2>&1; then

if [ "$installed_version" != "$version" ]; then
# Figure out which version is older between the installed version and the requested version.
older_version="$(printf '%s\n%s\n' "$installed_version" "$version" | sort -V | head -n 1)"
older_version="$(sort_versions "$installed_version" "$version")"

# If the version requested is "latest" and the installed version is newer than the latest version available, skip installation.
if [ "$ORB_VAL_VERSION" = "latest" ] && [ "$older_version" = "$version" ]; then
printf '%s\n' "The version installed ($installed_version) is newer than the latest version listed in the release notes ($version)."
Expand Down

0 comments on commit c8f142c

Please sign in to comment.