Skip to content

Commit

Permalink
improve busted version tests part 7
Browse files Browse the repository at this point in the history
  • Loading branch information
pirog committed Nov 22, 2024
1 parent 22cc1ad commit cc734ce
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr-windows-script-bad-versions-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
with:
fetch-depth: 0
- name: Setup Lando version ${{ matrix.bad-version }}
shell: powershell
shell: pwsh
run: |
try {
.\setup-lando.ps1 -Version ${{ matrix.bad-version }} -NoSetup
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/pr-windows-script-replacer-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ jobs:
with:
fetch-depth: 0
- name: Add tempbin to PATH
shell: powershell
shell: pwsh
run: Write-Output "PATH=$env:USERPROFILE\.lando\bin;$env:PATH" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
- name: Get older Lando version ${{ matrix.old-version }}
shell: powershell
shell: pwsh
run: |
$LandoBin = Join-Path -Path "$env:USERPROFILE" -ChildPath '.lando\bin'
New-Item -ItemType Directory -Force -Path "$env:RUNNER_TEMP\bin" | Out-Null
Expand All @@ -48,7 +48,7 @@ jobs:
lando plugin-add @lando/core@${{ matrix.old-version }}
lando shellenv --add
- name: Verify older situation
shell: powershell
shell: pwsh
run: |
if (-not (Get-Command lando | Select-Object -ExpandProperty Source | Select-String -Pattern "$env:USERPROFILE\.lando\bin\lando.cmd" -SimpleMatch)) {
throw "Error: lando is not where we expect it!"
Expand All @@ -59,10 +59,10 @@ jobs:
}
- name: Replace Lando with setup-script
shell: powershell
shell: pwsh
run: .\setup-lando.ps1 -Version ${{ matrix.version }} -NoSetup
- name: Verify new situation
shell: powershell
shell: pwsh
run: |
if (-not (Get-Command lando | Select-Object -ExpandProperty Source | Select-String -Pattern "$env:USERPROFILE\.lando\bin\lando.exe" -SimpleMatch)) {
throw "Error: lando is not where we expect it!"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-windows-script-versions-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
with:
fetch-depth: 0
- name: Setup Lando version ${{ matrix.version }}
shell: powershell # 5.1
shell: pwsh
run: |
# skip command
if ("${{ matrix.version }}" -eq "set-with-envvar") {
Expand Down
81 changes: 40 additions & 41 deletions setup-lando.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,6 @@ abort() {
exit 1
}

debug() {
if [[ -n "${DEBUG-}" ]]; then
printf "${tty_dim}debug${tty_reset} %s\n" "$(shell_join "$@")" >&2
fi
}

# Fail fast with a concise message when not using bash
# Single brackets are needed here for POSIX compatibility
# shellcheck disable=SC2292
Expand Down Expand Up @@ -161,47 +155,13 @@ get_installer_os() {
get_installer_arch
get_installer_os

# sudo access check
have_sudo_access() {
if [[ ! -x "/usr/bin/sudo" ]]; then
return 1
fi

local -a SUDO=("/usr/bin/sudo")
if [[ -n "${SUDO_ASKPASS-}" ]]; then
SUDO+=("-A")
fi

if [[ -z "${HAVE_SUDO_ACCESS-}" ]]; then
"${SUDO[@]}" -l -U "${USER}" &>/dev/null
HAVE_SUDO_ACCESS="$?"
if [[ "${HAVE_SUDO_ACCESS}" == 1 ]]; then
debug "${USER} does not appear to have sudo access!"
else
debug "${USER} has sudo access"
fi
fi

return "${HAVE_SUDO_ACCESS}"
}

shell_join() {
local arg
printf "%s" "${1:-}"
shift
for arg in "$@"; do
printf " "
printf "%s" "${arg// /\ }"
done
}

# set defaults but allow envvars to be used
#
# RUNNER_DEBUG is used here so we can get good debug output when toggled in GitHub Actions
# see https://github.blog/changelog/2022-05-24-github-actions-re-run-jobs-with-debug-logging/

# @TODO: no-sudo option
# @TODO: dest based on mv?
# @TODO: dest based on lmv
ARCH="${LANDO_INSTALLER_ARCH:-"$INSTALLER_ARCH"}"
DEBUG="${LANDO_INSTALLER_DEBUG:-${RUNNER_DEBUG:-}}"
DEST="${LANDO_INSTALLER_DEST:-/usr/local/bin}"
Expand Down Expand Up @@ -326,6 +286,12 @@ chomp() {
printf "%s" "${1/"$'\n'"/}"
}

debug() {
if [[ -n "${DEBUG-}" ]]; then
printf "${tty_dim}debug${tty_reset} %s\n" "$(shell_join "$@")" >&2
fi
}

debug_multi() {
if [[ -n "${DEBUG-}" ]]; then
while read -r line; do
Expand All @@ -338,6 +304,16 @@ log() {
printf "%s\n" "$(shell_join "$@")"
}

shell_join() {
local arg
printf "%s" "${1:-}"
shift
for arg in "$@"; do
printf " "
printf "%s" "${arg// /\ }"
done
}

warn() {
printf "${tty_yellow}warning${tty_reset}: %s\n" "$(chomp "$@")" >&2
}
Expand Down Expand Up @@ -407,6 +383,29 @@ find_first_existing_parent() {
echo "$dir"
}

have_sudo_access() {
if [[ ! -x "/usr/bin/sudo" ]]; then
return 1
fi

local -a SUDO=("/usr/bin/sudo")
if [[ -n "${SUDO_ASKPASS-}" ]]; then
SUDO+=("-A")
fi

if [[ -z "${HAVE_SUDO_ACCESS-}" ]]; then
"${SUDO[@]}" -l -U "${USER}" &>/dev/null
HAVE_SUDO_ACCESS="$?"
if [[ "${HAVE_SUDO_ACCESS}" == 1 ]]; then
debug "${USER} does not appear to have sudo access!"
else
debug "${USER} has sudo access"
fi
fi

return "${HAVE_SUDO_ACCESS}"
}

major() {
echo "$1" | cut -d '.' -f1
}
Expand Down

0 comments on commit cc734ce

Please sign in to comment.