From 4aff3a8f4d1e626647b2118a77b52364322eb07c Mon Sep 17 00:00:00 2001 From: Scott Motte Date: Thu, 30 May 2024 15:24:11 -0700 Subject: [PATCH 01/14] wip --- .shellspec | 12 ++++++ README.md | 1 + installer2.sh | 70 +++++++++++++++++++++++++++++++++++ spec/installer2_spec.sh | 82 +++++++++++++++++++++++++++++++++++++++++ spec/spec_helper.sh | 24 ++++++++++++ tmp/.gitkeep | 0 6 files changed, 189 insertions(+) create mode 100644 .shellspec create mode 100755 installer2.sh create mode 100644 spec/installer2_spec.sh create mode 100644 spec/spec_helper.sh create mode 100644 tmp/.gitkeep diff --git a/.shellspec b/.shellspec new file mode 100644 index 0000000..d567ecf --- /dev/null +++ b/.shellspec @@ -0,0 +1,12 @@ +--require spec_helper + +## Default kcov (coverage) options +# --kcov-options "--include-path=. --path-strip-level=1" +# --kcov-options "--include-pattern=.sh" +# --kcov-options "--exclude-pattern=/.shellspec,/spec/,/coverage/,/report/" + +## Example: Include script "myprog" with no extension +# --kcov-options "--include-pattern=.sh,myprog" + +## Example: Only specified files/directories +# --kcov-options "--include-pattern=myprog,/lib/" diff --git a/README.md b/README.md index 400526b..8a8100e 100644 --- a/README.md +++ b/README.md @@ -15,3 +15,4 @@ curl -fsS https://dotenvx.sh/ | sh * alternatively, install with wget `wget -qO- https://dotenvx.sh/ | sh` * make sure you are using `https`, not `http`. We do not redirect for trust reasons. * deployed to heroku using dotenvx buildpack `heroku buildpacks:add https://github.com/dotenvx/heroku-buildpack-dotenvx` +* run specs with [`shellspec`](https://github.com/shellspec/shellspec) diff --git a/installer2.sh b/installer2.sh new file mode 100755 index 0000000..cca5beb --- /dev/null +++ b/installer2.sh @@ -0,0 +1,70 @@ +#!/bin/sh + +set -e + +# default values +VERSION="0.44.1" +INSTALLATION_DIRECTORY="/usr/local/bin" + +usage() { + echo "Usage: $0 [options] [command]" + echo "" + echo "install dotenvx – a better dotenv" + echo "" + echo "Options:" + echo " --path set the installation directory, default is /usr/local/bin" + echo " --version set the version of dotenvx to install, for example: --version=0.44.1" + echo "" + echo "Commands:" + echo " install install dotenvx" + echo " help display help" +} + +installation_directory() { + local dir=$INSTALLATION_DIRECTORY + + case "$dir" in + ~*/*) + dir="$HOME/${dir#\~/}" + ;; + ~*) + dir="$HOME/${dir#\~}" + ;; + esac + + echo "${dir}" + return 0 +} + +is_installation_directory_writable() { + # check installation directory is writable + if [ ! -w "$(installation_directory)" ] && [ "$(id -u)" -ne 0 ]; then + echo "[INSTALLATION_FAILED] the installation directory [$(installation_directory)] is not writable by the current user" + echo "? run as root [sudo $0] or choose a writable directory like your current directory [$0 path=.]" + + return 1 + fi + + return 0 +} + +# parse arguments +for arg in "$@"; do + case $arg in + path=* | --path=*) + INSTALLATION_DIRECTORY="${arg#*=}" + ;; + help | --help) + usage + exit 0 + ;; + *) + # Unknown option + echo "Unknown option: $arg" + usage + exit 1 + ;; + esac +done + +echo "success" diff --git a/spec/installer2_spec.sh b/spec/installer2_spec.sh new file mode 100644 index 0000000..c5b7639 --- /dev/null +++ b/spec/installer2_spec.sh @@ -0,0 +1,82 @@ +Describe 'installer2.sh' + Include installer2.sh + + setup() { + VERSION="0.44.1" + INSTALLATION_DIRECTORY="/usr/local/bin" + } + + mock_home() { + HOME="/home/testuser" + INSTALLATION_DIRECTORY="~/testdir" + } + + mock_writable_directory() { + INSTALLATION_DIRECTORY="$(pwd)/tmp/" + } + + BeforeEach 'setup' + + Describe 'default values' + It 'checks default VERSION' + When call echo "$VERSION" + The output should equal "0.44.1" + End + + It 'checks default INSTALLATION_DIRECTORY' + When call echo "$INSTALLATION_DIRECTORY" + The output should equal "/usr/local/bin" + End + End + + Describe 'installation_directory()' + It 'smartly returns installation_directory as default INSTALL_DIR' + When call installation_directory + The output should equal "/usr/local/bin" + End + + Describe 'when home directory' + Before 'mock_home' + + It 'expands ~ to home directory' + When call installation_directory + The output should equal "/home/testuser/testdir" + End + End + End + + Describe 'is_installation_directory_writable()' + It 'is false (1) to /usr/local/bin (typical case that /usr/local/bin is not writable)' + When call is_installation_directory_writable + The status should equal 1 + The output should equal "[INSTALLATION_FAILED] the installation directory [/usr/local/bin] is not writable by the current user +? run as root [sudo /bin/sh] or choose a writable directory like your current directory [/bin/sh path=.]" + End + + Describe 'when writable directory' + Before 'mock_writable_directory' + + It 'is true (0)' + When call is_installation_directory_writable + The status should equal 0 + End + End + End + + Describe 'usage()' + It 'displays usage' + When call usage + The output should equal "Usage: /bin/sh [options] [command] + +install dotenvx – a better dotenv + +Options: + --path set the installation directory, default is /usr/local/bin + --version set the version of dotenvx to install, for example: --version=0.44.1 + +Commands: + install install dotenvx + help display help" + End + End +End diff --git a/spec/spec_helper.sh b/spec/spec_helper.sh new file mode 100644 index 0000000..93f1908 --- /dev/null +++ b/spec/spec_helper.sh @@ -0,0 +1,24 @@ +# shellcheck shell=sh + +# Defining variables and functions here will affect all specfiles. +# Change shell options inside a function may cause different behavior, +# so it is better to set them here. +# set -eu + +# This callback function will be invoked only once before loading specfiles. +spec_helper_precheck() { + # Available functions: info, warn, error, abort, setenv, unsetenv + # Available variables: VERSION, SHELL_TYPE, SHELL_VERSION + : minimum_version "0.28.1" +} + +# This callback function will be invoked after a specfile has been loaded. +spec_helper_loaded() { + : +} + +# This callback function will be invoked after core modules has been loaded. +spec_helper_configure() { + # Available functions: import, before_each, after_each, before_all, after_all + : import 'support/custom_matcher' +} diff --git a/tmp/.gitkeep b/tmp/.gitkeep new file mode 100644 index 0000000..e69de29 From d3edbf173101550d19287270fcd0e877dac41454 Mon Sep 17 00:00:00 2001 From: Scott Motte Date: Sat, 1 Jun 2024 09:24:47 +0200 Subject: [PATCH 02/14] add installer2 spec --- installer2.sh | 94 ++++++++++++++++++++++++++---- spec/installer2_spec.sh | 114 +++++++++++++++++++++++++------------ {tmp => spec/tmp}/.gitkeep | 0 3 files changed, 161 insertions(+), 47 deletions(-) rename {tmp => spec/tmp}/.gitkeep (100%) diff --git a/installer2.sh b/installer2.sh index cca5beb..75373f2 100755 --- a/installer2.sh +++ b/installer2.sh @@ -4,7 +4,7 @@ set -e # default values VERSION="0.44.1" -INSTALLATION_DIRECTORY="/usr/local/bin" +DIRECTORY="/usr/local/bin" usage() { echo "Usage: $0 [options] [command]" @@ -12,16 +12,16 @@ usage() { echo "install dotenvx – a better dotenv" echo "" echo "Options:" - echo " --path set the installation directory, default is /usr/local/bin" - echo " --version set the version of dotenvx to install, for example: --version=0.44.1" + echo " --directory directory to install dotenvx to (default: \"/usr/local/bin\")" + echo " --version version of dotenvx to install (default: \"$VERSION\")" echo "" echo "Commands:" echo " install install dotenvx" echo " help display help" } -installation_directory() { - local dir=$INSTALLATION_DIRECTORY +directory() { + local dir=$DIRECTORY case "$dir" in ~*/*) @@ -36,11 +36,11 @@ installation_directory() { return 0 } -is_installation_directory_writable() { +is_directory_writable() { # check installation directory is writable - if [ ! -w "$(installation_directory)" ] && [ "$(id -u)" -ne 0 ]; then - echo "[INSTALLATION_FAILED] the installation directory [$(installation_directory)] is not writable by the current user" - echo "? run as root [sudo $0] or choose a writable directory like your current directory [$0 path=.]" + if [ ! -w "$(directory)" ] && [ "$(id -u)" -ne 0 ]; then + echo "[INSTALLATION_FAILED] the installation directory [$(directory)] is not writable by the current user" + echo "? run as root [sudo $0] or choose a writable directory like your current directory [$0 directory=.]" return 1 fi @@ -48,11 +48,76 @@ is_installation_directory_writable() { return 0 } +is_curl_installed() { + if ! command -v curl >/dev/null 2>&1; then + echo "[INSTALLATION_FAILED] curl is required and appears to not be installed" + echo "? install curl and try again" + + exit 1 + fi + + return 0 +} + +os() { + echo "$(uname -s | tr '[:upper:]' '[:lower:]')" + + return 0 +} + +arch() { + echo "$(uname -m | tr '[:upper:]' '[:lower:]')" + + return 0 +} + +is_os_supported() { + local os="$(os)" + + case "$os" in + linux) os="linux" ;; + darwin) os="darwin" ;; + *) + echo "[INSTALLATION_FAILED] your operating system ${os} is currently unsupported" + echo "? request support by opening an issue at [https://github.com/dotenvx/dotenvx.sh/issues]" + + return 1 + ;; + esac + + return 0 +} + +is_arch_supported() { + local arch="$(arch)" + + case "$arch" in + x86_64) arch="x86_64" ;; + amd64) arch="amd64" ;; + arm64) arch="arm64" ;; + aarch64) arch="aarch64" ;; + *) + echo "[INSTALLATION_FAILED] your architecture ${arch} is currently unsupported - must be x86_64, amd64, arm64, or aarch64" + echo "? request support by opening an issue at [https://github.com/dotenvx/dotenvx.sh/issues]" + + return 1 + ;; + esac + + return 0 +} + +os_arch() { + echo "$(os)-$(arch)" + + return 0 +} + # parse arguments for arg in "$@"; do case $arg in - path=* | --path=*) - INSTALLATION_DIRECTORY="${arg#*=}" + directory=* | --directory=*) + DIRECTORY="${arg#*=}" ;; help | --help) usage @@ -67,4 +132,9 @@ for arg in "$@"; do esac done -echo "success" +is_directory_writable +is_curl_installed +is_os_supported +is_arch_supported + +echo "os: $(os) arch: $(arch)" diff --git a/spec/installer2_spec.sh b/spec/installer2_spec.sh index c5b7639..b867098 100644 --- a/spec/installer2_spec.sh +++ b/spec/installer2_spec.sh @@ -1,18 +1,17 @@ Describe 'installer2.sh' - Include installer2.sh + Include installer2.sh directory=./spec/tmp setup() { VERSION="0.44.1" - INSTALLATION_DIRECTORY="/usr/local/bin" } mock_home() { HOME="/home/testuser" - INSTALLATION_DIRECTORY="~/testdir" + DIRECTORY="~/testdir" } - mock_writable_directory() { - INSTALLATION_DIRECTORY="$(pwd)/tmp/" + mock_unwritable_directory() { + DIRECTORY="/usr/local/bin" # requires root/sudo } BeforeEach 'setup' @@ -23,60 +22,105 @@ Describe 'installer2.sh' The output should equal "0.44.1" End - It 'checks default INSTALLATION_DIRECTORY' - When call echo "$INSTALLATION_DIRECTORY" - The output should equal "/usr/local/bin" + It 'checks default DIRECTORY' + When call echo "$DIRECTORY" + The output should equal "./spec/tmp" End End - Describe 'installation_directory()' - It 'smartly returns installation_directory as default INSTALL_DIR' - When call installation_directory - The output should equal "/usr/local/bin" + Describe 'usage()' + It 'displays usage' + When call usage + The output should equal "Usage: /bin/sh [options] [command] + +install dotenvx – a better dotenv + +Options: + --directory directory to install dotenvx to (default: \"/usr/local/bin\") + --version version of dotenvx to install (default: \"0.44.1\") + +Commands: + install install dotenvx + help display help" + End + End + + Describe 'directory()' + It 'smartly returns directory as default INSTALL_DIR' + When call directory + The output should equal "./spec/tmp" End Describe 'when home directory' Before 'mock_home' It 'expands ~ to home directory' - When call installation_directory + When call directory The output should equal "/home/testuser/testdir" End End End - Describe 'is_installation_directory_writable()' - It 'is false (1) to /usr/local/bin (typical case that /usr/local/bin is not writable)' - When call is_installation_directory_writable - The status should equal 1 - The output should equal "[INSTALLATION_FAILED] the installation directory [/usr/local/bin] is not writable by the current user -? run as root [sudo /bin/sh] or choose a writable directory like your current directory [/bin/sh path=.]" + Describe 'is_directory_writable()' + It 'is true (0)' + When call is_directory_writable + The status should equal 0 End - Describe 'when writable directory' - Before 'mock_writable_directory' + Describe 'when unwritable directory' + Before 'mock_unwritable_directory' - It 'is true (0)' - When call is_installation_directory_writable - The status should equal 0 + It 'is false (1) to /usr/local/bin (typical case that /usr/local/bin is not writable)' + When call is_directory_writable + The status should equal 1 + The output should equal "[INSTALLATION_FAILED] the installation directory [/usr/local/bin] is not writable by the current user +? run as root [sudo /bin/sh] or choose a writable directory like your current directory [/bin/sh directory=.]" End End End - Describe 'usage()' - It 'displays usage' - When call usage - The output should equal "Usage: /bin/sh [options] [command] + Describe 'is_curl_installed()' + It 'is true (0) (typical case that /usr/bin/curl is installed)' + When call is_curl_installed + The status should equal 0 + End + End -install dotenvx – a better dotenv + Describe 'os()' + It 'returns current os lowercased' + When call os + The status should equal 0 + The output should equal "$(uname -s | tr '[:upper:]' '[:lower:]')" + End + End -Options: - --path set the installation directory, default is /usr/local/bin - --version set the version of dotenvx to install, for example: --version=0.44.1 + Describe 'arch()' + It 'returns current arch lowercased' + When call arch + The status should equal 0 + The output should equal "$(uname -m | tr '[:upper:]' '[:lower:]')" + End + End -Commands: - install install dotenvx - help display help" + Describe 'is_os_supported()' + It 'returns true' + When call is_os_supported + The status should equal 0 + End + End + + Describe 'is_arch_supported()' + It 'returns true' + When call is_arch_supported + The status should equal 0 + End + End + + Describe 'os_arch()' + It 'returns the combined values' + When call os_arch + The status should equal 0 + The output should equal "$(uname -s | tr '[:upper:]' '[:lower:]')-$(uname -m | tr '[:upper:]' '[:lower:]')" End End End diff --git a/tmp/.gitkeep b/spec/tmp/.gitkeep similarity index 100% rename from tmp/.gitkeep rename to spec/tmp/.gitkeep From 9b0c71a78b4823ac951f685d2aa88aa47d3db93d Mon Sep 17 00:00:00 2001 From: Scott Motte Date: Sat, 1 Jun 2024 09:41:11 +0200 Subject: [PATCH 03/14] add github action --- .github/workflows/ci.yml | 17 +++++++++++++++++ index.js | 40 ---------------------------------------- package.json | 3 ++- 3 files changed, 19 insertions(+), 41 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..cdf0a09 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,17 @@ +name: ci + +on: push + +jobs: + test: + runs-on: ubuntu-latest + strategy: + fail-fast: true + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 16.x + - run: npm install + - run: npm run standard + - run: npm run test diff --git a/index.js b/index.js index a2cdb05..8e5d0b6 100644 --- a/index.js +++ b/index.js @@ -6,10 +6,6 @@ const app = express() const PORT = process.env.PORT || 3000 const GITHUB_TOKEN = process.env.GITHUB_TOKEN -const UMAMI_ROOT_URL = 'https://dotenv-umami-fd0ec6de187e.herokuapp.com' -const UMAMI_WEBSITE_ID = process.env.UMAMI_WEBSITE_ID -const UMAMI_SEND_URL = `${UMAMI_ROOT_URL}/api/send` -const SPOOFED_USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36' // Read the installer script once at the start const installerScriptPath = path.join(__dirname, 'installer.sh') @@ -22,42 +18,6 @@ fs.readFile(installerScriptPath, 'utf8', (err, data) => { installerScript = data }) -const umamiVisitMiddleware = (req, res, next) => { - const payload = { - website: UMAMI_WEBSITE_ID, - hostname: req.get('host'), - screen: '1920x1080', - language: 'en-US', - title: req.originalUrl, - url: req.originalUrl, - referrer: req.get('referrer') || '', - } - - const postData = { - type: 'event', - payload: payload, - userIp: req.ip - } - - const options = { - headers: { - 'User-Agent': SPOOFED_USER_AGENT // otherwise, umami ignores https://github.com/umami-software/umami/blob/7fb74feeaf399b89866e8b368a5bfbe91349f848/src/pages/api/send.ts#L77 - } - } - - try { - axios.post(UMAMI_SEND_URL, postData, options) - } catch (error) { - console.error('Error sending page visit to Umami:', error) - console.error('postData', postData) - } - - next() // Continue to the next middleware/route handler -} - -// umami visits -// app.use(umamiVisitMiddleware) - app.get('/', (req, res) => { // Check User-Agent to determine the response const userAgent = req.headers['user-agent'] || '' diff --git a/package.json b/package.json index da99897..4a2033b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,8 @@ { "scripts": { "standard": "standard", - "standard:fix": "standard --fix" + "standard:fix": "standard --fix", + "test": "shellspec" }, "dependencies": { "axios": "^1.6.2", From 0ac3604edc8b478e990c26268f5f38dc47933186 Mon Sep 17 00:00:00 2001 From: Scott Motte Date: Sat, 1 Jun 2024 09:43:53 +0200 Subject: [PATCH 04/14] install shellspec --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cdf0a09..3a85144 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,6 +12,7 @@ jobs: - uses: actions/setup-node@v4 with: node-version: 16.x + - run: curl -fsSL https://git.io/shellspec | sh - run: npm install - run: npm run standard - run: npm run test From 600548f3581df5725852e5698fce3c3071c916a0 Mon Sep 17 00:00:00 2001 From: Scott Motte Date: Sat, 1 Jun 2024 09:48:00 +0200 Subject: [PATCH 05/14] try sending to /dev/null --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3a85144..5efaf03 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ jobs: - uses: actions/setup-node@v4 with: node-version: 16.x - - run: curl -fsSL https://git.io/shellspec | sh + - run: curl -fsSL https://git.io/shellspec | sh > /dev/null - run: npm install - run: npm run standard - run: npm run test From 87f03f67548f2495926a95af4e6d0fe4def59b80 Mon Sep 17 00:00:00 2001 From: Scott Motte Date: Sat, 1 Jun 2024 09:59:23 +0200 Subject: [PATCH 06/14] ci --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5efaf03..a233a86 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,9 @@ jobs: - uses: actions/setup-node@v4 with: node-version: 16.x - - run: curl -fsSL https://git.io/shellspec | sh > /dev/null + - run: | + git clone https://github.com/shellspec/shellspec.git + cd shellspec && sudo make install - run: npm install - run: npm run standard - run: npm run test From 4682c44350678790465e4f5c3e5db6be244fcbb4 Mon Sep 17 00:00:00 2001 From: Scott Motte Date: Sat, 1 Jun 2024 10:10:38 +0200 Subject: [PATCH 07/14] try moving it --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a233a86..f3430ab 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,8 +13,9 @@ jobs: with: node-version: 16.x - run: | - git clone https://github.com/shellspec/shellspec.git + git clone https://github.com/shellspec/shellspec.git shellspec cd shellspec && sudo make install + sudo cp shellspec/shellspec /usr/bin/shellspec - run: npm install - run: npm run standard - run: npm run test From a08304b78e0dcdd0555ee92768c52c657e2b18ef Mon Sep 17 00:00:00 2001 From: Scott Motte Date: Sat, 1 Jun 2024 10:12:23 +0200 Subject: [PATCH 08/14] move the binary --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f3430ab..b0f4988 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ jobs: - run: | git clone https://github.com/shellspec/shellspec.git shellspec cd shellspec && sudo make install - sudo cp shellspec/shellspec /usr/bin/shellspec + sudo cp shellspec /usr/bin/shellspec - run: npm install - run: npm run standard - run: npm run test From bc60ea4b49f29ae76adb65d71fdb0681a0222dc9 Mon Sep 17 00:00:00 2001 From: Scott Motte Date: Sun, 2 Jun 2024 08:08:35 +0200 Subject: [PATCH 09/14] update workflows --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b0f4988..b7050f9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,6 +16,7 @@ jobs: git clone https://github.com/shellspec/shellspec.git shellspec cd shellspec && sudo make install sudo cp shellspec /usr/bin/shellspec + cd .. - run: npm install - run: npm run standard - run: npm run test From 5c516d2af1221c9ee4ecdca28cda20d5a62c329f Mon Sep 17 00:00:00 2001 From: Scott Motte Date: Sun, 2 Jun 2024 08:11:59 +0200 Subject: [PATCH 10/14] adjust .sh file --- installer2.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/installer2.sh b/installer2.sh index 75373f2..7e5aea2 100755 --- a/installer2.sh +++ b/installer2.sh @@ -132,9 +132,9 @@ for arg in "$@"; do esac done -is_directory_writable -is_curl_installed -is_os_supported -is_arch_supported - -echo "os: $(os) arch: $(arch)" +# is_directory_writable +# is_curl_installed +# is_os_supported +# is_arch_supported +# echo "os: $(os) arch: $(arch)" +echo "hello" From 344eae9487eef62b63f5f0943c6376c6417720d1 Mon Sep 17 00:00:00 2001 From: Scott Motte Date: Sun, 2 Jun 2024 17:38:26 +0200 Subject: [PATCH 11/14] check if installed --- .github/workflows/ci.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b7050f9..d3beb64 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,11 +12,8 @@ jobs: - uses: actions/setup-node@v4 with: node-version: 16.x - - run: | - git clone https://github.com/shellspec/shellspec.git shellspec - cd shellspec && sudo make install - sudo cp shellspec /usr/bin/shellspec - cd .. + - run: curl -fsSL https://git.io/shellspec | sh --yes + - run: which shellspec - run: npm install - run: npm run standard - run: npm run test From 1229501da962a3a4b326e1af1e2ed1d4c1f3f961 Mon Sep 17 00:00:00 2001 From: Scott Motte Date: Sun, 2 Jun 2024 17:44:17 +0200 Subject: [PATCH 12/14] try again try listing all items try again run without npm test adjust test try changing to sh try subbing out to sh adjust spec run bash shellspec adjust specs to work locally and on github actions ci --- .github/workflows/ci.yml | 5 +++-- package.json | 2 +- spec/installer2_spec.sh | 10 +++++----- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d3beb64..bf50b6e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,8 +12,9 @@ jobs: - uses: actions/setup-node@v4 with: node-version: 16.x - - run: curl -fsSL https://git.io/shellspec | sh --yes + - name: install shellspec + run: curl -fsSL https://git.io/shellspec | sh -s 0.28.1 --yes - run: which shellspec - run: npm install - run: npm run standard - - run: npm run test + - run: bash shellspec diff --git a/package.json b/package.json index 4a2033b..f713853 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "scripts": { "standard": "standard", "standard:fix": "standard --fix", - "test": "shellspec" + "test": "bash shellspec" }, "dependencies": { "axios": "^1.6.2", diff --git a/spec/installer2_spec.sh b/spec/installer2_spec.sh index b867098..a002436 100644 --- a/spec/installer2_spec.sh +++ b/spec/installer2_spec.sh @@ -11,7 +11,7 @@ Describe 'installer2.sh' } mock_unwritable_directory() { - DIRECTORY="/usr/local/bin" # requires root/sudo + DIRECTORY="/usr/local/testing-installer" # requires root/sudo } BeforeEach 'setup' @@ -31,7 +31,7 @@ Describe 'installer2.sh' Describe 'usage()' It 'displays usage' When call usage - The output should equal "Usage: /bin/sh [options] [command] + The output should equal "Usage: $0 [options] [command] install dotenvx – a better dotenv @@ -70,11 +70,11 @@ Commands: Describe 'when unwritable directory' Before 'mock_unwritable_directory' - It 'is false (1) to /usr/local/bin (typical case that /usr/local/bin is not writable)' + It 'is false (1) to /usr/local/testing-installer (typical case that /usr/local/testing-installer is not writable)' When call is_directory_writable The status should equal 1 - The output should equal "[INSTALLATION_FAILED] the installation directory [/usr/local/bin] is not writable by the current user -? run as root [sudo /bin/sh] or choose a writable directory like your current directory [/bin/sh directory=.]" + The output should equal "[INSTALLATION_FAILED] the installation directory [/usr/local/testing-installer] is not writable by the current user +? run as root [sudo $0] or choose a writable directory like your current directory [$0 directory=.]" End End End From bdb46d53c6dd146998f63c89baa768dfdbeea146 Mon Sep 17 00:00:00 2001 From: Scott Motte Date: Mon, 3 Jun 2024 14:52:10 +0200 Subject: [PATCH 13/14] rename to `npm test` --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bf50b6e..4d61a3a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,4 +17,4 @@ jobs: - run: which shellspec - run: npm install - run: npm run standard - - run: bash shellspec + - run: npm test From c4de3496fa465107a0c2420300a9dde0f7915ff5 Mon Sep 17 00:00:00 2001 From: Scott Motte Date: Mon, 3 Jun 2024 14:59:39 +0200 Subject: [PATCH 14/14] move to `install.sh` --- installer2.sh => install.sh | 0 spec/{installer2_spec.sh => install_spec.sh} | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) rename installer2.sh => install.sh (100%) rename spec/{installer2_spec.sh => install_spec.sh} (97%) diff --git a/installer2.sh b/install.sh similarity index 100% rename from installer2.sh rename to install.sh diff --git a/spec/installer2_spec.sh b/spec/install_spec.sh similarity index 97% rename from spec/installer2_spec.sh rename to spec/install_spec.sh index a002436..db7e952 100644 --- a/spec/installer2_spec.sh +++ b/spec/install_spec.sh @@ -1,5 +1,5 @@ -Describe 'installer2.sh' - Include installer2.sh directory=./spec/tmp +Describe 'install.sh' + Include install.sh directory=./spec/tmp setup() { VERSION="0.44.1"