Skip to content

Commit 2ba5715

Browse files
authored
feat(cli): scaffold a CI workflow in 'bashunit init' (#708)
1 parent 7003690 commit 2ba5715

4 files changed

Lines changed: 38 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Added
66
- GitHub Action `args` input: when set, runs `bashunit <args>` after installing, so a workflow can install and run the suite in a single step
77
- Floating major tag for the GitHub Action: the release process now force-moves `v0` to each release, so workflows can pin `TypedDevs/bashunit@v0` to track the latest release within a major (#700)
8+
- `bashunit init` now scaffolds a `.github/workflows/tests.yml` CI workflow using the official action (existing files are left untouched) (#702)
89

910
## [0.38.0](https://github.com/TypedDevs/bashunit/compare/0.37.0...0.38.0) - 2026-06-07
1011

src/console_header.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ Arguments:
209209
Creates:
210210
- bootstrap.sh Setup file for test configuration
211211
- example_test.sh Sample test file to get started
212+
- .github/workflows/tests.yml CI workflow using the official action
212213
213214
Examples:
214215
bashunit init Create tests/ directory

src/init.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,25 @@ SH
2828
echo "> Created $example_test"
2929
fi
3030

31+
local workflow_dir=".github/workflows"
32+
local workflow_file="$workflow_dir/tests.yml"
33+
if [ ! -f "$workflow_file" ]; then
34+
mkdir -p "$workflow_dir"
35+
cat >"$workflow_file" <<SH
36+
name: Tests
37+
on: [pull_request, push]
38+
jobs:
39+
tests:
40+
runs-on: ubuntu-latest
41+
steps:
42+
- uses: actions/checkout@v4
43+
- uses: TypedDevs/bashunit@v0
44+
with:
45+
args: $tests_dir
46+
SH
47+
echo "> Created $workflow_file"
48+
fi
49+
3150
local env_file=".env"
3251
local env_line="BASHUNIT_BOOTSTRAP=$bootstrap_file"
3352
if [ -f "$env_file" ]; then

tests/acceptance/bashunit_init_test.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,23 @@ function test_bashunit_init_custom_directory() {
3333
popd >/dev/null
3434
}
3535

36+
function test_bashunit_init_creates_github_workflow() {
37+
pushd "$TMP_DIR" >/dev/null
38+
"$BASHUNIT_PATH" init >/tmp/init.log
39+
assert_file_exists ".github/workflows/tests.yml"
40+
assert_file_contains ".github/workflows/tests.yml" "TypedDevs/bashunit@"
41+
popd >/dev/null
42+
}
43+
44+
function test_bashunit_init_does_not_overwrite_existing_workflow() {
45+
pushd "$TMP_DIR" >/dev/null
46+
mkdir -p ".github/workflows"
47+
echo "custom-workflow" >".github/workflows/tests.yml"
48+
"$BASHUNIT_PATH" init >/tmp/init.log
49+
assert_file_contains ".github/workflows/tests.yml" "custom-workflow"
50+
popd >/dev/null
51+
}
52+
3653
function test_bashunit_init_updates_env() {
3754
bashunit::skip "flaky" && return
3855

0 commit comments

Comments
 (0)