From 36e5887fa0ccef8a16408210726b8030faa2e322 Mon Sep 17 00:00:00 2001 From: Chemaclass Date: Sun, 7 Jun 2026 18:21:30 +0200 Subject: [PATCH] feat(ci): optional args input to run bashunit after install The action gains an 'args' input: when non-empty it runs 'bashunit ' after installing, so a workflow can install and run the suite in one step (e.g. args: 'tests/ --strict'). Empty keeps install-only behavior. A failing suite propagates a non-zero exit and fails the step. Adds a dogfood CI job covering both the passing and failing args paths, plus docs and an 'install + run' example. Also fixes the GitHub Actions code-group that had been split into a malformed second group. --- .github/workflows/test-action.yml | 36 +++++++++++++++++++++++++++++++ CHANGELOG.md | 3 +++ action.yml | 12 +++++++++++ docs/installation.md | 28 ++++++++++++++++++------ 4 files changed, 73 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test-action.yml b/.github/workflows/test-action.yml index b8eb0d5b..dd96bb52 100644 --- a/.github/workflows/test-action.yml +++ b/.github/workflows/test-action.yml @@ -46,3 +46,39 @@ jobs: test -n "$BASHUNIT_INSTALLED_VERSION" # add-to-path defaults to true, so "bashunit" resolves on PATH bashunit --version + + run-via-args: + name: "Run via args input" + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@v4 + + - name: Write a passing and a failing sample test + run: | + mkdir -p sample_tests + printf 'function test_passes() { assert_same "1" "1"; }\n' > sample_tests/pass_test.sh + printf 'function test_fails() { assert_same "1" "2"; }\n' > sample_tests/fail_test.sh + + - name: Run only the passing test via args (step should pass) + uses: ./ + with: + directory: vendor/bashunit + args: sample_tests/pass_test.sh + + - name: Run the failing test via args (expected to fail the step) + id: failing + continue-on-error: true + uses: ./ + with: + directory: vendor/bashunit + add-to-path: 'false' + args: sample_tests/fail_test.sh + + - name: Assert the failing run actually executed and failed + env: + OUTCOME: ${{ steps.failing.outcome }} + run: | + set -euo pipefail + # If args were ignored (install-only), the step would have succeeded. + test "$OUTCOME" = "failure" diff --git a/CHANGELOG.md b/CHANGELOG.md index 52cfce94..07bbed89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## Unreleased +### Added +- GitHub Action `args` input: when set, runs `bashunit ` after installing, so a workflow can install and run the suite in a single step + ## [0.38.0](https://github.com/TypedDevs/bashunit/compare/0.37.0...0.38.0) - 2026-06-07 ### Added diff --git a/action.yml b/action.yml index 0068fd34..3a5bb631 100644 --- a/action.yml +++ b/action.yml @@ -23,6 +23,10 @@ inputs: description: 'Verify the downloaded binary against the release sha256 checksum asset.' required: false default: 'true' + args: + description: 'If set, run "bashunit " after installing (e.g. "tests/ --strict"). Empty = install only.' + required: false + default: '' outputs: path: @@ -42,6 +46,7 @@ runs: BASHUNIT_DIRECTORY: ${{ inputs.directory }} BASHUNIT_ADD_TO_PATH: ${{ inputs.add-to-path }} BASHUNIT_VERIFY_CHECKSUM: ${{ inputs.verify-checksum }} + BASHUNIT_ARGS: ${{ inputs.args }} BASHUNIT_ACTION_PATH: ${{ github.action_path }} run: | set -euo pipefail @@ -62,3 +67,10 @@ runs: if [ "$BASHUNIT_ADD_TO_PATH" = "true" ]; then echo "$target_dir" >> "$GITHUB_PATH" fi + + # Optionally run the suite. Word-splitting of $BASHUNIT_ARGS is intentional + # so callers can pass multiple CLI arguments as a single string. + if [ -n "$BASHUNIT_ARGS" ]; then + # shellcheck disable=SC2086 + "$target_dir/bashunit" $BASHUNIT_ARGS + fi diff --git a/docs/installation.md b/docs/installation.md index 6946419e..413eb743 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -247,12 +247,21 @@ jobs: - run: bashunit tests ``` -**Inputs:** `version` (default `latest`), `directory` (default `lib`), `add-to-path` (default `true`), `verify-checksum` (default `true`). -**Outputs:** `path` (binary path relative to the workspace), `version` (installed version). - -`verify-checksum` validates the downloaded binary against the release `checksum` -asset (sha256) and fails the install on any mismatch. Set it to `false` only when -pinning a release published before checksum assets existed. +```yaml-vue [install + run] +# .github/workflows/bashunit-tests.yml +name: Tests +on: [pull_request, push] +jobs: + tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + # Install and run the suite in a single step via the `args` input. + - uses: TypedDevs/bashunit@ # {{ pkg.version }} + with: + version: '{{ pkg.version }}' + args: tests/ --strict +``` ```yaml [via install.sh] # .github/workflows/bashunit-tests.yml @@ -283,6 +292,13 @@ jobs: ``` ::: +**Inputs:** `version` (default `latest`), `directory` (default `lib`), `add-to-path` (default `true`), `verify-checksum` (default `true`), `args` (default empty — when set, runs `bashunit ` after installing). +**Outputs:** `path` (binary path relative to the workspace), `version` (installed version). + +`verify-checksum` validates the downloaded binary against the release `checksum` +asset (sha256) and fails the install on any mismatch. Set it to `false` only when +pinning a release published before checksum assets existed. + ::: tip See bashunit's own pipeline for a real example: https://github.com/TypedDevs/bashunit/blob/main/.github/workflows/tests.yml :::