diff --git a/CHANGELOG.md b/CHANGELOG.md index 84b746278..f9e934d2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,10 @@ * Add `--key_file` to allow using a service account key file +### pages + +* Fix to allow being run on a Windows Git bash + ### Releases * Make --file glob files by default, and default to `*` diff --git a/Gemfile b/Gemfile index fea7af7e3..bacbe0c2e 100644 --- a/Gemfile +++ b/Gemfile @@ -12,6 +12,8 @@ gems.each do |name, version, opts| gem name, version, opts end +gem 'os' + group :test do gem 'coveralls' gem 'rspec' diff --git a/lib/dpl/ctx/bash.rb b/lib/dpl/ctx/bash.rb index e76062826..d5b994b1c 100644 --- a/lib/dpl/ctx/bash.rb +++ b/lib/dpl/ctx/bash.rb @@ -2,6 +2,7 @@ require 'fileutils' require 'logger' require 'open3' +require 'os' require 'tmpdir' require 'securerandom' require 'dpl/support/version' @@ -262,7 +263,17 @@ def shell(cmd, opts = {}) info cmd.echo if cmd.echo? @last_out, @last_err, @last_status = retrying(cmd.retry ? 2 : 0) do - send(cmd.capture? ? :open3 : :system, cmd.cmd, cmd.opts) + if OS.windows? + command = "set -o pipefail && #{cmd.cmd}" + # required to get rsync working as rsync otherwise outputs "ssh: Could not resolve hostname c: Name or service not known" + command = command.sub("C:/", "/c/") + command = "bash -c \"#{command}\"" + system("#{command}") + cmd_status = $? + return cmd_status.exitstatus == 0 + else + send(cmd.capture? ? :open3 : :system, cmd.cmd, cmd.opts) + end end info cmd.success % { out: last_out } if success? && cmd.success? @@ -405,14 +416,14 @@ def git_author_name `git log #{git_sha} -n 1 --pretty=%an`.chomp end - # Returns the comitter email of the commit `git_sha`. + # Returns the committer email of the commit `git_sha`. def git_author_email `git log #{git_sha} -n 1 --pretty=%ae`.chomp end # Whether or not the git working directory is dirty def git_dirty? - !Kernel.system('git diff --quiet') + !shell('git diff --quiet') end # Returns the output of `git log`, using the given args. @@ -430,7 +441,7 @@ def git_ls_files # Returns true if the given ref exists remotely def git_ls_remote?(url, ref) - Kernel.system("git ls-remote --exit-code #{url} #{ref} > /dev/null 2>&1") + shell("git ls-remote --exit-code #{url} #{ref} > /dev/null 2>&1") end # Returns known Git remote URLs diff --git a/lib/dpl/providers/pages/git.rb b/lib/dpl/providers/pages/git.rb index cc61aeb83..dda6f2607 100644 --- a/lib/dpl/providers/pages/git.rb +++ b/lib/dpl/providers/pages/git.rb @@ -82,8 +82,6 @@ def login def setup info :setup_dir, src_dir - info :committer_from_gh if committer_from_gh? - info :git_config end def prepare @@ -95,8 +93,10 @@ def prepare def deploy git_clone? ? git_clone : git_init + info :committer_from_gh if committer_from_gh? + info :git_config copy_files - return info :stop unless git_dirty? + return info :stop unless !(git_clone?) || git_dirty? git_config git_commit git_push diff --git a/spec/dpl/providers/pages/git_spec.rb b/spec/dpl/providers/pages/git_spec.rb index 3369304bf..46ca1ea89 100644 --- a/spec/dpl/providers/pages/git_spec.rb +++ b/spec/dpl/providers/pages/git_spec.rb @@ -16,10 +16,10 @@ describe 'by default', record: true do it { should have_run '[info] Authenticated as login' } - it { should have_run '[info] Configuring git committer to be author name (via Travis CI) ' } it { should have_run '[info] Deploying branch gh-pages to github.com/travis-ci/dpl.git' } it { should have_run '[info] Cloning the branch gh-pages from the remote repo' } it { should have_run 'git clone --quiet --branch="gh-pages" --depth=1 "https://token@github.com/travis-ci/dpl.git" . > /dev/null 2>&1' } + it { should have_run '[info] Configuring git committer to be author name (via Travis CI) ' } it { should have_run %(rsync -rl --exclude .git --delete "#{cwd}/" .) } it { should have_run 'git config user.name "author name (via Travis CI)"' } it { should have_run 'git config user.email "author email"' }