Skip to content

Commit 366c730

Browse files
committed
🚧 install script tests
1 parent aad69b9 commit 366c730

18 files changed

Lines changed: 411 additions & 116 deletions

File tree

.github/workflows/self-test.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,14 @@ jobs:
4242
./valet self test -c
4343
4444
# Runs tests with bash 5
45-
- name: Run valet self test on bash5
45+
- name: Run valet self test on bash5.0
4646
run: |
4747
chmod +x valet
4848
docker run --rm \
4949
-v $PWD:/app \
5050
-w /app \
51-
noyacode/minideb-bash5.0 \
52-
bash --version; VALET_CONFIG_ENABLE_COLORS=true VALET_CONFIG_DISABLE_PROGRESS=true ./valet self test -c
51+
-e VALET_CONFIG_ENABLE_COLORS=true \
52+
-e VALET_CONFIG_DISABLE_PROGRESS=true \
53+
--entrypoint /usr/local/bin/bash-5.0 \
54+
noyacode/valet-tests-slimdeb:latest \
55+
bash --version; ./valet self test -c

commands.d/self-setup.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ shortDescription: The command run after the installation of Valet to setup the t
2020
description: |-
2121
The command run after the installation of Valet to setup the tool.
2222
23+
copy the showcase
2324
Create a shim/proxy script in `~/.local/bin` that points to `~/.local/lib/valet/valet` (the valet entry point).
2425
Make the valet script readable and executable, either by adding a shim
2526
in a bin directory already present in your PATH, or by adding the Valet
@@ -107,3 +108,23 @@ function selfSetup_setupForWindows() {
107108
log::info "Adding ⌜${windowsInstallationPath}⌝ to the user windows PATH."
108109
windows::addToPath "${windowsInstallationPath}"
109110
}
111+
112+
# Copy the showcase to the user directory.
113+
function copyShowcase() {
114+
local \
115+
installationDirectory="${1}" \
116+
extensionsDirectory="${2}"
117+
118+
testCommand "mkdir"
119+
testCommand "cp"
120+
121+
mkdir -p "${extensionsDirectory}" || core::fail "Could not create the extensions directory ⌜${extensionsDirectory}⌝."
122+
123+
if [[ -d "${extensionsDirectory}/showcase.d" ]]; then
124+
rm -Rf "${extensionsDirectory}/showcase.d" &>/dev/null || core::fail "Could not remove the existing showcase (command examples) in ⌜${extensionsDirectory}⌝."
125+
fi
126+
127+
cp -R "${installationDirectory}/showcase.d" "${extensionsDirectory}" || core::fail "Could not copy the showcase (command examples) to ⌜${extensionsDirectory}⌝."
128+
129+
log::success "The showcase has been copied to ⌜${extensionsDirectory}/showcase.d⌝."
130+
}

commands.d/self-uninstall.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@ function selfUninstall() {
4040
local configurationDirectory="${REPLY}"
4141
core::getUserDataDirectory
4242
local userDataDirectory="${REPLY}"
43-
core::getExtensionsDirectory
44-
local extensionsDirectory="${REPLY}"
4543
core::getUserCacheDirectory
4644
local userCacheDirectory="${REPLY}"
45+
core::getUserStateDirectory
46+
local userStateDirectory="${REPLY}"
47+
core::getExtensionsDirectory
48+
local extensionsDirectory="${REPLY}"
4749

4850
# shellcheck disable=SC2016
4951
echo '#!/usr/bin/env bash
@@ -55,12 +57,16 @@ rm -Rf "'"${configurationDirectory}"'"
5557
rm -Rf "'"${userDataDirectory}"'"
5658
# remove the user cache
5759
rm -Rf "'"${userCacheDirectory}"'"
60+
# remove the user state
61+
rm -Rf "'"${userStateDirectory}"'"
5862
# remove the user extensions directory
5963
rm -Rf "'"${extensionsDirectory}"'"
6064
# remove a possible symlink
61-
rm -f "'"$(which valet)"'" 2>/dev/null || :
62-
echo "Valet has been uninstalled."
6365
'
66+
if which valet &>/dev/null; then
67+
echo 'rm -f "'"$(which valet)"'" 2>/dev/null || :'$'\n'
68+
fi
69+
echo 'echo "Valet has been uninstalled."'$'\n'
6470
else
6571
log::warning "To uninstall Valet, you can run the following commands:"$'\n'"bash -c 'eval \"\$(valet self uninstall --script 2>/dev/null)\"'"
6672
fi

docs/content/docs/800.roadmap/_index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ url: /docs/roadmap
88

99
This page lists the features that I would like to implement in Valet. They come in addition to new features described in the [issues][valet-issues].
1010

11+
- make version a command instead of an option, and add a `valet version` command that shows the current version and the latest release. Also show the extension versions ?
1112
- implement fs::normalizePath
1213
- Modify self install: at the moment we count on the fact that some functions will still exist in valet after an update. The simplest is to redownload the self install script and run it again.
1314
- Implement tests that are only run with -e flag and where we test system specific stuff, like the windows library and fs::createLink, absolute path with real path etc...

install.sh

Lines changed: 52 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -20,39 +20,43 @@
2020
#
2121
# This script will:
2222
#
23-
# - 1. Download the given tar.gz release from GitHub (latest by default).
23+
# - 1. Download the tar.gz release from GitHub (latest by default).
2424
# - 2. Copy it in the Valet installation directory, which defaults to: `~/.local/lib/valet`
25-
# - 3. Copy the showcase (command examples) in the valet extensions directory ~/.valet.d.
26-
# - 4. Run `valet self setup` command to finish the installation.
25+
# - 3. Run `valet self setup` command to finish the installation.
2726
#
2827
# ########################
2928
# OPTIONS
3029
# ########################
3130
#
32-
# All options can also be set using environment variables, starting with `VALET_`, in uppercase and with underscores
33-
# instead of dashes (e.g. `VALET_INSTALLATION_DIRECTORY` for `--installation-directory`).
34-
#
3531
# - `--unattended`:
3632
# Set to true to install without user interaction/prompt (useful for automated installation).
33+
# Can be set using the environment variable `VALET_UNATTENDED=true`.
3734
# Defaults to false.
3835
# Note: If you use the unattended mode, you can specify options for the `valet self setup` command using
3936
# environment variables. Please check the command documentation for available options:
4037
# <https://jcaillon.github.io/valet/docs/valet-commands/#-valet-self-setup>.
4138
# - `--installation-directory <path>`:
4239
# The directory where Valet will be installed.
40+
# Can be set using the environment variable `VALET_INSTALLATION_DIRECTORY=<path>`.
4341
# Defaults to `~/.local/lib/valet`.
44-
# - `--extensions-directory <path>`:
45-
# The directory in which to store the user extensions and commands. The showcase extension will be copied there.
46-
# Defaults to `~/.valet.d`.
47-
# - `--without-showcase`:
48-
# Set to true to to not copy the showcase extension (a set of example commands) to the valet extensions directory (~/.valet.d).
49-
# If you do not set this option, newer versions of the showcase will override the existing ones.
5042
# - `--from-branch <branch_name>`:
5143
# Download Valet from a given branch tarball instead of a release.
44+
# Can be set using the environment variable `VALET_FROM_BRANCH=<branch_name>`.
5245
# Defaults to empty, which means to download the latest release.
53-
#
54-
# Additionally, you can set the environment variable `VALET_VERBOSE` to `true` to get more verbose output during the installation.
55-
#
46+
# - `--skip-setup`:
47+
# Set to true to skip the execution of the `valet self setup` command after the installation.
48+
# You can then run `valet self setup` manually to finish the installation or add valet to your PATH by yourself.
49+
# Can be set using the environment variable `VALET_SKIP_SETUP=true`.
50+
# Defaults to false.
51+
# - `--verbose`:
52+
# Set to true to get more verbose output during the installation.
53+
# Can be set using the environment variable `VALET_VERBOSE=true`.
54+
# Defaults to false.
55+
# - `--version <version>`:
56+
# Install a specific version of Valet instead of the version corresponding to this script version
57+
# (i.e. latest version by default).
58+
# Can be set using the environment variable `VALET_VERSION=<version>`.
59+
# This option is ignored if `--from-branch` is specified.
5660
#
5761

5862
# check the bash version (and that we are running in bash), make it POSIX compliant
@@ -72,9 +76,10 @@ function main() {
7276
local \
7377
unattended="${VALET_UNATTENDED:-"false"}" \
7478
installationDirectory="${VALET_INSTALLATION_DIRECTORY:-"${HOME}/.local/lib/valet"}" \
75-
extensionsDirectory="${VALET_EXTENSIONS_DIRECTORY:-"${HOME}/.valet.d"}" \
76-
withoutShowcase="${VALET_WITHOUT_SHOWCASE:-"false"}" \
77-
fromBranch="${VALET_FROM_BRANCH:-}"
79+
fromBranch="${VALET_FROM_BRANCH:-}" \
80+
skipSetup="${VALET_SKIP_SETUP:-"false"}" \
81+
verbose="${VALET_VERBOSE:-"false"}" \
82+
version="${VALET_VERSION:-"${VALET_RELEASED_VERSION}"}"
7883

7984
log::debug "Parsing arguments: ⌜${*}⌝."
8085
while (($# > 0)); do
@@ -87,48 +92,45 @@ function main() {
8792
[[ $# -eq 0 ]] && core::fail "Missing value for 'the installation directory' after the option --installation-directory."
8893
installationDirectory="${1}"
8994
;;
90-
--extensions-directory)
91-
shift
92-
[[ $# -eq 0 ]] && core::fail "Missing value for 'the extensions directory' after the option --extensions-directory."
93-
extensionsDirectory="${1}"
94-
;;
95-
--without-showcase)
96-
withoutShowcase="true"
97-
;;
9895
--from-branch)
9996
shift
10097
[[ $# -eq 0 ]] && core::fail "Missing value for 'the branch name' after the option --from-branch."
10198
fromBranch="${1}"
10299
;;
100+
--skip-setup)
101+
skipSetup="true"
102+
;;
103+
--verbose)
104+
verbose="true"
105+
;;
106+
--version)
107+
shift
108+
[[ $# -eq 0 ]] && core::fail "Missing value for 'the version' after the option --version."
109+
version="${1}"
110+
;;
103111
-*) core::fail "Unknown option ⌜${1}⌝." ;;
104112
*) core::fail "This command takes no arguments, did not understand ⌜${1}⌝." ;;
105113
esac
106114
shift
107115
done
108116

109117
installationDirectory="${installationDirectory%/}"
110-
extensionsDirectory="${extensionsDirectory%/}"
118+
VALET_VERBOSE="${verbose}"
111119

112120
# compute the release URL
113121
local releaseUrl version
114122
if [[ -n ${fromBranch} ]]; then
115-
releaseUrl="https://github.com/jcaillon/valet/archive/${fromBranch}.tar.gz"
116123
version="branch ${fromBranch}"
124+
releaseUrl="https://github.com/jcaillon/valet/archive/${fromBranch}.tar.gz"
117125
else
118-
releaseUrl="https://github.com/jcaillon/valet/releases/download/v${VALET_RELEASED_VERSION}/valet.tar.gz"
119-
version="${VALET_RELEASED_VERSION}"
126+
releaseUrl="https://github.com/jcaillon/valet/releases/download/v${version}/valet.tar.gz"
120127
fi
121128

122129
# display a recap to the user
123130
printf '\n %s\n\n' "${STYLE_COLOR_PRIMARY}Valet installation recap:${STYLE_COLOR_DEFAULT}"
124131
printRecapLine "Version to install:" "${version}"
125132
printRecapLine "Download URL:" "${releaseUrl}"
126133
printRecapLine "Installation dir:" "${installationDirectory}"
127-
if [[ ${withoutShowcase} != "true" ]]; then
128-
printRecapLine "Copy showcase to:" "${extensionsDirectory}"
129-
else
130-
printRecapLine "Install without showcase:" "true"
131-
fi
132134
printf '\n'
133135

134136
# ask for confirmation
@@ -139,19 +141,18 @@ function main() {
139141
# download and install valet
140142
install "${releaseUrl}" "${fromBranch}" "${installationDirectory}"
141143

142-
# copy the showcase if needed
143-
if [[ ${withoutShowcase} != "true" ]]; then
144-
copyShowcase "${installationDirectory}" "${extensionsDirectory}"
145-
fi
146-
147144
log::success "Valet version ⌜${version}⌝ has been installed in ⌜${installationDirectory}⌝."
148145

149146
# remove the user commands to rebuild them
150147
command::deleteCommandsIndex
151148

152-
# run the setup command
153-
log::info "Running the self setup command."
154-
"${installationDirectory}/valet" self setup
149+
if [[ ${skipSetup} == "true" ]]; then
150+
log::warning "Skipping the valet self setup command as --skip-setup has been passed."$'\n'"You can now run ⌜valet self setup⌝ manually to finish setting up valet."$'\n'"Or add ${installationDirectory} to your PATH."
151+
else
152+
# run the setup command
153+
log::info "Running the self setup command."
154+
VALET_VERBOSE="${VALET_VERBOSE}" VALET_UNATTENDED="${unattended}" "${installationDirectory}/valet" self setup
155+
fi
155156
}
156157

157158
function printRecapLine() {
@@ -220,26 +221,6 @@ function install() {
220221
log::success "Valet has been downloaded in ⌜${installationDirectory}⌝."
221222
}
222223

223-
# Copy the showcase to the user directory.
224-
function copyShowcase() {
225-
local \
226-
installationDirectory="${1}" \
227-
extensionsDirectory="${2}"
228-
229-
testCommand "mkdir"
230-
testCommand "cp"
231-
232-
mkdir -p "${extensionsDirectory}" || core::fail "Could not create the extensions directory ⌜${extensionsDirectory}⌝."
233-
234-
if [[ -d "${extensionsDirectory}/showcase.d" ]]; then
235-
rm -Rf "${extensionsDirectory}/showcase.d" &>/dev/null || core::fail "Could not remove the existing showcase (command examples) in ⌜${extensionsDirectory}⌝."
236-
fi
237-
238-
cp -R "${installationDirectory}/showcase.d" "${extensionsDirectory}" || core::fail "Could not copy the showcase (command examples) to ⌜${extensionsDirectory}⌝."
239-
240-
log::success "The showcase has been copied to ⌜${extensionsDirectory}/showcase.d⌝."
241-
}
242-
243224
# Downloads a file to a specific location.
244225
function downloadTarBall() {
245226
local url="${1}"
@@ -269,6 +250,12 @@ function log::info() {
269250
printf "${STYLE_COLOR_FADED}%(%H:%M:%S)T${STYLE_COLOR_DEFAULT} ${STYLE_COLOR_INFO}%-7s${STYLE_COLOR_DEFAULT} %s\n" "${GLOBAL_MOCK_EPOCHSECONDS:-${EPOCHSECONDS}}" "INFO" "${message///${STYLE_COLOR_DEFAULT}}"
270251
}
271252

253+
# log warning message
254+
function log::warning() {
255+
local message="${1///${STYLE_COLOR_ACCENT}⌜}"
256+
printf "${STYLE_COLOR_FADED}%(%H:%M:%S)T${STYLE_COLOR_DEFAULT} ${STYLE_COLOR_WARNING}%-7s${STYLE_COLOR_DEFAULT} %s\n" "${GLOBAL_MOCK_EPOCHSECONDS:-${EPOCHSECONDS}}" "WARNING" "${message///${STYLE_COLOR_DEFAULT}}"
257+
}
258+
272259
# log success message
273260
function log::success() {
274261
local message="${1///${STYLE_COLOR_ACCENT}⌜}"
@@ -347,6 +334,7 @@ function command::deleteCommandsIndex() {
347334
STYLE_COLOR_FADED=$'\e[90m'
348335
STYLE_COLOR_DEBUG=$'\e[90m'
349336
STYLE_COLOR_INFO=$'\e[36m'
337+
STYLE_COLOR_WARNING=$'\e[33m'
350338
STYLE_COLOR_SUCCESS=$'\e[32m'
351339
STYLE_COLOR_ERROR=$'\e[31m'
352340
else
@@ -356,6 +344,7 @@ function command::deleteCommandsIndex() {
356344
STYLE_COLOR_FADED=''
357345
STYLE_COLOR_DEBUG=''
358346
STYLE_COLOR_INFO=''
347+
STYLE_COLOR_WARNING=''
359348
STYLE_COLOR_SUCCESS=''
360349
STYLE_COLOR_ERROR=''
361350
fi

tests.d/install/01.install.sh

Lines changed: 0 additions & 15 deletions
This file was deleted.

tests.d/install/results.approved.md

Lines changed: 0 additions & 4 deletions
This file was deleted.

tests.d/install/valet-tests-slimdeb/build.sh

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
3+
# shellcheck source=../../libraries.d/lib-fs
4+
source fs
5+
6+
# cancel the test suite if not running on windows
7+
if ! command -v docker &>/dev/null; then
8+
test::skipTestSuite "This test suite is only runnable on systems with Docker installed, skipping it."
9+
fi
10+
11+
function main() {
12+
test::title "✅ Testing valet installation"
13+
docker run \
14+
--rm \
15+
-i \
16+
--entrypoint /usr/local/bin/bash-5.0 \
17+
--volume ../../install.sh:/home/me/install.sh \
18+
--volume ./test-script:/home/me/test-script \
19+
noyacode/valet-tests-slimdeb:latest \
20+
-c "source /home/me/test-script 2>&1"
21+
22+
test::flush
23+
}
24+
25+
main

0 commit comments

Comments
 (0)