Skip to content

Commit 70deb64

Browse files
authored
refactor(release): include docs/package.json in RELEASE_FILES (#652)
1 parent d1f049d commit 70deb64

3 files changed

Lines changed: 54 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
### Changed
1111
- Split documentation into its own npm workspace under `docs/`: VitePress dependencies and `docs:*` scripts moved out of the root `package.json` so the published npm package stays slim. CI workflows, release script and contributing docs updated for the new `cd docs && npm ci` workflow; `make docs/{install,dev,build,preview}` shortcuts added
1212
- Guard root `package.json` against accidental regression of the docs-split: assert no `dependencies`/`devDependencies`/`peerDependencies`/`scripts` blocks ever return to the published manifest
13+
- `release.sh` now treats `docs/package.json` as a first-class `RELEASE_FILES` entry, so the release flow backs it up, restores it on rollback, and stages it without inline duplication. Backup/restore preserves nested directory paths
1314
- Centralize all ANSI escape emission through the existing `_BASHUNIT_COLOR_*` constants. `src/coverage.sh` and the `--watch` screen-clear in `src/main.sh` no longer hardcode escape sequences (#247)
1415
- Speed up coverage report generation by collapsing the per-line non-executable pattern checks in `bashunit::coverage::is_executable_line` into a single combined `grep` invocation (#636)
1516
- Speed up coverage report generation further by combining executable + hit counting into a single source-file pass (`bashunit::coverage::compute_file_coverage`) shared across text/lcov/html reporters, removing per-line `get_line_hits` scans of the coverage data file (#636)

release.sh

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ declare -r EXIT_EXECUTION_ERROR=2
1313
# Constants
1414
GITHUB_REPO_PATH="TypedDevs/bashunit"
1515
GITHUB_REPO_URL="https://github.com/${GITHUB_REPO_PATH}"
16-
RELEASE_FILES=("bashunit" "install.sh" "package.json" "CHANGELOG.md")
16+
RELEASE_FILES=("bashunit" "install.sh" "package.json" "docs/package.json" "CHANGELOG.md")
1717

1818
# Helper function for regex matching (Bash 3.0+ compatible)
1919
function regex_match() {
@@ -287,7 +287,9 @@ function release::backup::init() {
287287
function release::backup::save_file() {
288288
local file=$1
289289
if [[ -f "$file" ]]; then
290-
cp "$file" "$BACKUP_DIR/"
290+
local dest="$BACKUP_DIR/$file"
291+
mkdir -p "$(dirname "$dest")"
292+
cp "$file" "$dest"
291293
release::log_verbose "Backed up: $file"
292294
fi
293295
}
@@ -313,14 +315,12 @@ function release::rollback::restore_files() {
313315
fi
314316

315317
release::log_info "Restoring files from backup..."
316-
for file in "$BACKUP_DIR"/*; do
317-
if [[ -f "$file" ]]; then
318-
local filename
319-
filename=$(basename "$file")
320-
cp "$file" "./$filename"
321-
release::log_verbose "Restored: $filename"
322-
fi
323-
done
318+
while IFS= read -r file; do
319+
local rel="${file#"$BACKUP_DIR"/}"
320+
mkdir -p "$(dirname "./$rel")"
321+
cp "$file" "./$rel"
322+
release::log_verbose "Restored: $rel"
323+
done < <(find "$BACKUP_DIR" -type f)
324324
release::log_success "Files restored from backup"
325325
}
326326

@@ -521,7 +521,7 @@ function release::sandbox::run() {
521521
release::blank_line
522522
# Commit changes (confirmations skipped in sandbox)
523523
release::log_info "Creating release commit..."
524-
git add "${RELEASE_FILES[@]}" docs/package.json
524+
git add "${RELEASE_FILES[@]}"
525525
git commit -m "release: $VERSION" -n
526526
release::log_success "Created commit"
527527
git tag "$VERSION"
@@ -843,7 +843,7 @@ function release::git_commit_and_tag() {
843843
return
844844
fi
845845

846-
git add "${RELEASE_FILES[@]}" docs/package.json
846+
git add "${RELEASE_FILES[@]}"
847847
git commit -m "release: $new_version" -n
848848
release::log_success "Created commit"
849849

tests/unit/release_utilities_test.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,47 @@ function test_rollback_restore_files_restores_backup() {
135135
rm -rf "$temp_dir"
136136
}
137137

138+
function test_backup_save_file_preserves_subdirectory_path() {
139+
local temp_dir
140+
temp_dir=$(mktemp -d)
141+
142+
local result
143+
result=$(
144+
cd "$temp_dir" || return
145+
mkdir -p docs
146+
echo "docs content" >docs/package.json
147+
release::backup::init
148+
release::backup::save_file "docs/package.json"
149+
cat "$BACKUP_DIR/docs/package.json"
150+
)
151+
152+
assert_same "docs content" "$result"
153+
rm -rf "$temp_dir"
154+
}
155+
156+
function test_rollback_restore_files_restores_nested_paths() {
157+
local temp_dir
158+
temp_dir=$(mktemp -d)
159+
160+
local result
161+
result=$(
162+
cd "$temp_dir" || return
163+
mkdir -p docs
164+
echo "original docs" >docs/package.json
165+
echo "original root" >root.txt
166+
release::backup::init
167+
release::backup::save_file "docs/package.json"
168+
release::backup::save_file "root.txt"
169+
echo "modified docs" >docs/package.json
170+
echo "modified root" >root.txt
171+
release::rollback::restore_files 2>/dev/null
172+
printf '%s|%s' "$(cat docs/package.json)" "$(cat root.txt)"
173+
)
174+
175+
assert_same "original docs|original root" "$result"
176+
rm -rf "$temp_dir"
177+
}
178+
138179
##########################
139180
# Pre-flight check tests
140181
##########################

0 commit comments

Comments
 (0)