Log uncommitted changes during deploy

This commit is contained in:
Igor Alexandrov
2023-07-21 18:37:45 +04:00
parent 5e8df58e6b
commit 0cfafd1d25
5 changed files with 25 additions and 4 deletions

View File

@@ -19,7 +19,13 @@ class Mrsk::Cli::Build < Mrsk::Cli::Base
run_locally do run_locally do
begin begin
MRSK.with_verbosity(:debug) { execute *MRSK.builder.push } MRSK.with_verbosity(:debug) do
if (uncommitted_changes = Mrsk::Utils.uncommitted_changes).present?
say "The following paths have uncommitted changes (check your .gitignore file):\n #{uncommitted_changes}", :yellow
end
execute *MRSK.builder.push
end
rescue SSHKit::Command::Failed => e rescue SSHKit::Command::Failed => e
if e.message =~ /(no builder)|(no such file or directory)/ if e.message =~ /(no builder)|(no such file or directory)/
error "Missing compatible builder, so creating a new one first" error "Missing compatible builder, so creating a new one first"

View File

@@ -262,7 +262,7 @@ class Mrsk::Configuration
def git_version def git_version
@git_version ||= @git_version ||=
if system("git rev-parse") if system("git rev-parse")
uncommitted_suffix = `git status --porcelain`.strip.present? ? "_uncommitted_#{SecureRandom.hex(8)}" : "" uncommitted_suffix = Mrsk::Utils.uncommitted_changes.present? ? "_uncommitted_#{SecureRandom.hex(8)}" : ""
"#{`git rev-parse HEAD`.strip}#{uncommitted_suffix}" "#{`git rev-parse HEAD`.strip}#{uncommitted_suffix}"
else else

View File

@@ -93,4 +93,8 @@ module Mrsk::Utils
end end
end end
end end
def uncommitted_changes
`git status --porcelain`.strip
end
end end

View File

@@ -84,7 +84,7 @@ class ConfigurationTest < ActiveSupport::TestCase
ENV.delete("VERSION") ENV.delete("VERSION")
@config.expects(:`).with("git rev-parse HEAD").returns("git-version") @config.expects(:`).with("git rev-parse HEAD").returns("git-version")
@config.expects(:`).with("git status --porcelain").returns("") Mrsk::Utils.expects(:uncommitted_changes).returns("")
assert_equal "git-version", @config.version assert_equal "git-version", @config.version
end end
@@ -92,7 +92,8 @@ class ConfigurationTest < ActiveSupport::TestCase
ENV.delete("VERSION") ENV.delete("VERSION")
@config.expects(:`).with("git rev-parse HEAD").returns("git-version") @config.expects(:`).with("git rev-parse HEAD").returns("git-version")
@config.expects(:`).with("git status --porcelain").returns("M file\n") # @config.expects(:`).with("git status --porcelain").returns("M file\n")
Mrsk::Utils.expects(:uncommitted_changes).returns("M file\n")
assert_match /^git-version_uncommitted_[0-9a-f]{16}$/, @config.version assert_match /^git-version_uncommitted_[0-9a-f]{16}$/, @config.version
end end

View File

@@ -61,4 +61,14 @@ class UtilsTest < ActiveSupport::TestCase
assert_equal "\"https://example.com/\\$2\"", assert_equal "\"https://example.com/\\$2\"",
Mrsk::Utils.escape_shell_value("https://example.com/$2") Mrsk::Utils.escape_shell_value("https://example.com/$2")
end end
test "uncommitted changes exist" do
Mrsk::Utils.expects(:`).with("git status --porcelain").returns("M file\n")
assert_equal "M file", Mrsk::Utils.uncommitted_changes
end
test "uncommitted changes do not exist" do
Mrsk::Utils.expects(:`).with("git status --porcelain").returns("")
assert_equal "", Mrsk::Utils.uncommitted_changes
end
end end