mbland / go-script-bash

Framework for writing modular, discoverable, testable Bash scripts
ISC License
95 stars 16 forks source link

Add @go.create_gzipped_tarball and perform other small refactors #211

Closed mbland closed 6 years ago

mbland commented 6 years ago

Closes #186. Normally I would split these into separate PRs, but in the interest of putting #186 to bed and moving on, I'm eliding them here.

@go.canonicalize_path now accepts --pwd and --parent <dir> options for convenience, rather than forcing the caller to use @go.add_parent_dir_if_relative_path directly.

@go.mirror_directory now mirrors the entire source directory by default.

@go.create_gzipped_tarball throws in tons of sanity checks and provides maximum portability, when a handful of direct commands just won't do. (The same could be said for @go.mirror_directory.)

create_fake_tarball_if_not_using_real_url now uses @go.mirror_directory, but not @go.create_gzipped_tarball, since the latter follows the convention that the extracted directory matches the basename of the tarball. With GitHub releases, the name of the extracted directory does not match the basename of the tarball, e.g. v1.6.0.tar.gz extracts to go-script-bash-v1.6.0. So in this case, it was easier to use @go.mirror_directory, then use tar directly, despite the fact that create_fake_tarball_if_not_using_real_url inspired @go.create_gzipped_tarball, which then inspired @go.mirror_directory.

(If @go.create_gzipped_tarball doesn't prove useful in the long run, I can remove it in v2.0.0.)

Finally, after digging deeper into process substitution vs. pipes during the implementation of @go.mirror_directory from lib/fileutil, I realized a few things:

Hence, go-template now uses a {curl,fetch,cat,wget} | tar pipe with a [[ ${PIPESTATUS[0]} -ne '0' ]] check. There's a new test case for tar failure, and the 'fail to download ...' test cases required a little tweaking to ensure they properly cover the cases where ${download_cmd[@]} fails.

(Yeah, really shoulda been separate PRs.)

coveralls commented 6 years ago

Coverage Status

Coverage increased (+0.07%) to 95.145% when pulling 41daa0cc87a318728908eb8f5fc1644d1af76688 on tarball-#186 into 2f731d6e38743a97f35f4034d5435ed78ca0f7dc on master.

coveralls commented 6 years ago

Coverage Status

Coverage increased (+0.07%) to 95.145% when pulling d60a27230ed6fa130f3c4c483d03fe71fac4ed58 on tarball-#186 into 2f731d6e38743a97f35f4034d5435ed78ca0f7dc on master.

coveralls commented 6 years ago

Coverage Status

Coverage increased (+0.07%) to 95.145% when pulling e885b4a752d704e5d525418de7e4e4acd627c071 on tarball-#186 into 2f731d6e38743a97f35f4034d5435ed78ca0f7dc on master.