Skip to content

Commit fa7dbc3

Browse files
committed
feat(ci): fail loud on bad download, add PATH + version outputs
install.sh now exits non-zero (and leaves no bogus binary) when a release cannot be downloaded, via 'curl -fL' plus a post-download file check, instead of silently printing success. Regression test added. The action gains an 'add-to-path' input (default true) that appends the install dir to $GITHUB_PATH so consumers run bare 'bashunit', and a 'version' output exposing the installed version.
1 parent 14307d1 commit fa7dbc3

6 files changed

Lines changed: 49 additions & 6 deletions

File tree

.github/workflows/test-action.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ jobs:
3939
- name: Verify the binary is installed and runnable
4040
env:
4141
BASHUNIT_PATH: ${{ steps.bashunit.outputs.path }}
42+
BASHUNIT_INSTALLED_VERSION: ${{ steps.bashunit.outputs.version }}
4243
run: |
4344
set -euo pipefail
4445
test -x "$BASHUNIT_PATH"
45-
"$BASHUNIT_PATH" --version
46+
test -n "$BASHUNIT_INSTALLED_VERSION"
47+
# add-to-path defaults to true, so "bashunit" resolves on PATH
48+
bashunit --version

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
### Fixed
99
- `install.sh` creates nested target directories (`mkdir -p`), so non-existing parent folders no longer fail the install
10+
- `install.sh` now fails loudly (non-zero exit, no bogus binary) when a version cannot be downloaded, instead of silently reporting success
1011

1112
## [0.37.0](https://github.com/TypedDevs/bashunit/compare/0.36.0...0.37.0) - 2026-06-03
1213

action.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,18 @@ inputs:
1515
description: 'Directory, relative to the workspace, where the bashunit binary is installed.'
1616
required: false
1717
default: lib
18+
add-to-path:
19+
description: 'Add the install directory to $GITHUB_PATH so you can run "bashunit" directly.'
20+
required: false
21+
default: 'true'
1822

1923
outputs:
2024
path:
2125
description: Path to the installed bashunit binary, relative to the workspace.
2226
value: ${{ steps.install.outputs.path }}
27+
version:
28+
description: The installed bashunit version (e.g. "0.37.0").
29+
value: ${{ steps.install.outputs.version }}
2330

2431
runs:
2532
using: composite
@@ -29,6 +36,7 @@ runs:
2936
env:
3037
BASHUNIT_VERSION: ${{ inputs.version }}
3138
BASHUNIT_DIRECTORY: ${{ inputs.directory }}
39+
BASHUNIT_ADD_TO_PATH: ${{ inputs.add-to-path }}
3240
BASHUNIT_ACTION_PATH: ${{ github.action_path }}
3341
run: |
3442
set -euo pipefail
@@ -42,3 +50,10 @@ runs:
4250
"$BASHUNIT_ACTION_PATH/install.sh" "$target_dir" "$BASHUNIT_VERSION"
4351
4452
echo "path=$BASHUNIT_DIRECTORY/bashunit" >> "$GITHUB_OUTPUT"
53+
54+
version="$(NO_COLOR=1 "$target_dir/bashunit" --version | awk 'NR==1{print $NF}')"
55+
echo "version=$version" >> "$GITHUB_OUTPUT"
56+
57+
if [ "$BASHUNIT_ADD_TO_PATH" = "true" ]; then
58+
echo "$target_dir" >> "$GITHUB_PATH"
59+
fi

docs/installation.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,16 @@ jobs:
239239
# Pin to a commit SHA; the comment tracks the human-readable tag.
240240
- uses: TypedDevs/bashunit@<commit-sha> # {{ pkg.version }}
241241
with:
242-
version: '{{ pkg.version }}' # or "latest"
242+
version: '{{ pkg.version }}' # or "latest" (default)
243243
directory: lib # optional, "lib" by default
244-
- run: ./lib/bashunit tests
244+
add-to-path: 'true' # optional, "true" by default
245+
# add-to-path puts the binary on $PATH, so just call "bashunit":
246+
- run: bashunit tests
245247
```
246248

249+
**Inputs:** `version` (default `latest`), `directory` (default `lib`), `add-to-path` (default `true`).
250+
**Outputs:** `path` (binary path relative to the workspace), `version` (installed version).
251+
247252
```yaml [via install.sh]
248253
# .github/workflows/bashunit-tests.yml
249254
name: Tests

install.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,19 @@ function install() {
4444
echo "> Downloading the latest version: '$TAG'"
4545
fi
4646

47+
local url="$BASHUNIT_GIT_REPO/releases/download/$TAG/bashunit"
4748
if command -v curl >/dev/null 2>&1; then
48-
curl -L -O -J "$BASHUNIT_GIT_REPO/releases/download/$TAG/bashunit" 2>/dev/null
49+
curl -fL -O -J "$url" 2>/dev/null
4950
elif command -v wget >/dev/null 2>&1; then
50-
wget "$BASHUNIT_GIT_REPO/releases/download/$TAG/bashunit" 2>/dev/null
51+
wget "$url" 2>/dev/null
5152
else
52-
echo "Cannot download bashunit: curl or wget not found."
53+
echo "Cannot download bashunit: curl or wget not found." >&2
54+
exit 1
55+
fi
56+
57+
if [ ! -f "bashunit" ]; then
58+
echo "Error: failed to download bashunit '$TAG' from $url" >&2
59+
exit 1
5360
fi
5461
chmod u+x "bashunit"
5562
}

tests/acceptance/install_test.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ function test_install_downloads_in_nested_folder() {
109109
assert_file_exists "$installed_bashunit"
110110
}
111111

112+
function test_install_fails_loudly_on_unknown_version() {
113+
if [[ "$ACTIVE_INTERNET" -eq 1 ]]; then
114+
bashunit::skip "no internet connection" && return
115+
fi
116+
if [[ "$HAS_DOWNLOADER" -eq 0 ]]; then
117+
bashunit::skip "curl or wget not installed" && return
118+
fi
119+
120+
assert_general_error "$(./install.sh tmp_install 99.99.99 2>&1)"
121+
assert_file_not_exists "./tmp_install/bashunit"
122+
}
123+
112124
function test_install_downloads_the_given_version() {
113125
if [[ "$ACTIVE_INTERNET" -eq 1 ]]; then
114126
bashunit::skip "no internet connection" && return

0 commit comments

Comments
 (0)