Skip to content

Download release file instead of cloning repo in go-template (continued from #179) #180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 31 commits into from
Aug 27, 2017

Conversation

mbland
Copy link
Owner

@mbland mbland commented Aug 25, 2017

Closes #179.

I've taken @elpaquete's fine work from #179 and refactored it a bit to:

  • rebase on master (after I remembered to push the v1.5.0 commit just today—d'oh!)
  • fix a few bugs
  • add a few tests
  • clean up the formatting
  • restore the ability to test it without a network connection
  • add the capability to use wget and fetch as well.

I still need to test this on all the platforms (I think I might need to add tweaks for MSYS2), but I hope to have it in by tomorrow and cut v1.6.0 right away.

@elpaquete Note that I found a way to get rid of curl | tar and set -o pipefail, namely by using a command substitution and checking that the expected output is present.

juansaavedrauy and others added 20 commits August 25, 2017 12:23
Rather than use a bare string, we capture the output in an array.
This provides a better error than a raw `[[ -f ... ]]`.
Don't know why the test wasn't originally written using
`TEST_GO_ROOTDIR`. As intended, it exposed some missing quotes from
variables in `go-template` introduced in #179.

I've removed several instances of the following comment, as I'm not sure
it applies anymore. If it does, I'll make sure to restore it as needed:

  # Use `.*/scripts/go-script-bash` to account for the fact that `git clone` on
  # MSYS2 will output `C:/Users/<user>/AppData/Local/Temp/` in place of `/tmp`.
Also wraps a couple of lines that were previously longer than 80
columns.
These aren't necessary, as `stub_program_in_path` will update `PATH`
automatically.
By using a process substitution to provide input to `tar`, we eliminate
a subshell and the need for `set -o pipefail`.
Seems cleaner and easier to follow to give both operations descriptive
names and allow them to reside at the top level.
This prevents new processes from spawning just to detect whether a
program is present.

The new `create_forwarding_script` helper in `tests/template.bats`
ensured that the tests continued to pass before and after this change.
`create_forwarding_script` will move to `lib/bats/helpers` in a future
commit.
In addition to being more specific, the errors are now printed to
standard error.
Defining these variables at the top level keeps all the environment
variables defined in one consistent location, and makes them available
to suite names as well.
Now all of the lines are back down to 80 characters or less.
This had been hardcoded to the actual repo value in #179. The
`create_fake_tarball_if_not_using_real_url` helper function and
`TEST_ARCHIVE_URL` environment variable enable the test to run isolated
from the network.

Also tweaks `GO_SCRIPTS_DIR` to remove unnecessary braces.
Got rid of `GO_SCRIPT_BASH_VERSION_NUMBER`, since it was only used in
this function. Elided some of the `if` conditions into a single
`if/elif` chain. Made sure that the `mkdir -p` tries to create the full
parent of `GO_SCRIPT_BASH_CORE_DIR`, not just `GO_SCRIPTS_DIR`.
Attempts to be flexible as the `./go get file` command. The
`run_with_download_program` test helper creates a script that runs `cat`
on a local tarball to simulate downloads using each tool.
@mbland mbland self-assigned this Aug 25, 2017
mbland added 3 commits August 25, 2017 18:23
The `download uses ...` tests all restrict the avaiable programs to a
very small subset via forwarding scripts. Apparently GNU tar, unlike BSD
tar, calls out to the `gzip` program rather than linking in the library.
So this change adds a forwarding script for `gzip` to fix this
particular breakage:

* https://travis-ci.org/mbland/go-script-bash/jobs/268538634
As I'd already done with the 'fail to download a nonexistent version'
test case, I've updated the 'fail to download a nonexistent repo' test
case to use a series of `assert_output_matches` assertions rather than
checking the literal output with `assert_failure`. This avoids the
problem whereby tool+platform-specific error messages can cause the
tests to fail:

* https://travis-ci.org/mbland/go-script-bash/jobs/268538634
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.02%) to 94.605% when pulling 57e7356 on go-template-download into 779f544 on master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.02%) to 94.605% when pulling 238fcda on go-template-download into 779f544 on master.

mbland added 2 commits August 26, 2017 12:24
This is in preparation for using `cp` instead of `wget` for `file://`
urls, since `wget` only supports HTTP, HTTPS, and FTP.
This is because `wget` only supports HTTP, HTTPS, and FTP, as I
discovered when running the tests on Alpine Linux without cURL
installed.

Also, the BusyBox version of `tar` that comes with Alpine doesn't work
out of the box; the GNU version must be installed via `apk add tar`. Not
sure it's worth adding a check to `go-template` or not.
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.02%) to 94.605% when pulling 0784a04 on go-template-download into 779f544 on master.

This fixes test failures for the "fail to find download program uses git
clone" and the "fail to find tar uses git clone" test cases on MSYS2 and
Cygwin, due to the fact that helper programs couldn't be found with the
`PATH`. This resulted in errors such as:

  C:/msys64/usr/lib/git-core/git-upload-pack.exe: error while loading
  shared libraries: ?: cannot open shared object file: No such file or
  directory
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.02%) to 94.605% when pulling d27dc12 on go-template-download into 779f544 on master.

Cygwin and MSYS2 environments both contain the `cygpath` utility for
translating between Unix and native Windows file paths. `cygpath -m` is
just what's needed when passing file paths and URLs to native binary
programs such as `curl` and `git`.

This commit adds the `windows_native_path` helper function, which I'll
eventually extract into a `lib/` module at some point. It also adds
logic to ensure `GO_SCRIPT_BASH_DOWNLOAD_URL` begins with a protocol,
adds a test case to validate this, removes redundant comments and
assertions from several `git clone` test cases, and updates the
`create_forwarding_script` helper to only generate a script when a
program is present on the system.
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.02%) to 94.605% when pulling 2f6aeca on go-template-download into 779f544 on master.

As it turns out, regular MSYS2 and Cygwin do not work with with file
paths modified with `cygpath -m`. This change tries to ensure only Git
for Windows is affected by checking the `EXEPATH` variable.
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.02%) to 94.605% when pulling f4f5fd7 on go-template-download into 779f544 on master.

Turns out I made a mistake in the previous commit in adapting the
conditional to use `EXEPATH` instead of `command -v cygpath`, as the
tests were still broken on regular MSYS2 and Cygwin. This change
resolves the breakage and continues to work on Git for Windows.
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.02%) to 94.605% when pulling 757cf46 on go-template-download into 779f544 on master.

Turns out this is the most reliable and robust way, as `EXEPATH` won't
always be set or set with 'Git' as its final component.
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.02%) to 94.605% when pulling fc55a10 on go-template-download into 779f544 on master.

Turns out the 'fail to find tar uses git clone' test would fail on
systems that don't have `curl` installed, since
`create_forwarding_script` now only creates a script if a program is
present. This fixes the breakage by trying to create a forwarding script
for all three programs; at least one should be guaranteed to be present.
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.02%) to 94.605% when pulling 96af8f4 on go-template-download into 779f544 on master.

@mbland
Copy link
Owner Author

mbland commented Aug 27, 2017

Wow, it literally took me all day to get things smoothed out across platforms. Specifically, I came to realize how particular the Git for Windows environment is, even compared to plain MSYS2 and Cygwin. But now I'm armed with insight from that experience (including my discovery of the cygpath utility), and all the tests pass everywhere.

Thanks for the contribution, @elpaquete! Though since it's almost 9pm and I haven't had dinner yet, I think I'll cut v1.6.0 tomorrow. 🙂

@mbland mbland merged commit de7ce6c into master Aug 27, 2017
@mbland mbland deleted the go-template-download branch August 27, 2017 00:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants