Set a UTF-8 locale for Danger
Danger parses git diff
output using Ruby. When a non-ascii character is present in the output, it chokes with the following error (seen in https://gitlab.com/gitlab-org/gitlab-ce/-/jobs/275286625)
$ danger --fail-on-errors=true
/usr/local/bundle/gems/danger-6.0.9/lib/danger/scm_source/git_repo.rb:29:in `tr': (Danger::DSLError)
[!] Invalid `Dangerfile` file:
[!] Invalid `Dangerfile` file: invalid byte sequence in US-ASCII
# from danger/specs/Dangerfile:14
# -------------------------------------------
#
> has_app_changes = !helper.all_changed_files.grep(%r{\A(ee/)?(app|lib|db/(geo/)?(post_)?migrate)/}).empty?
# has_spec_changes = !helper.all_changed_files.grep(%r{\A(ee/)?spec/}).empty?
# -------------------------------------------
# from danger/specs/Dangerfile:14
# -------------------------------------------
# danger.import_dangerfile(path: 'danger/frozen_string')
> danger.import_dangerfile(path: 'danger/commit_messages')
# danger.import_dangerfile(path: 'danger/duplicate_yarn_dependencies')
# -------------------------------------------
from /usr/local/bundle/gems/danger-6.0.9/lib/danger/scm_source/git_repo.rb:29:in `block in renamed_files'
from /usr/local/bundle/gems/danger-6.0.9/lib/danger/scm_source/git_repo.rb:29:in `map'
from /usr/local/bundle/gems/danger-6.0.9/lib/danger/scm_source/git_repo.rb:29:in `renamed_files'
from /usr/local/bundle/gems/danger-6.0.9/lib/danger/danger_core/plugins/dangerfile_git_plugin.rb:83:in `renamed_files'
from /builds/gitlab-org/gitlab-ce/lib/gitlab/danger/helper.rb:31:in `all_changed_files'
from danger/specs/Dangerfile:14:in `eval_file'
from /usr/local/bundle/gems/danger-6.0.9/lib/danger/danger_core/dangerfile.rb:297:in `eval'
from /usr/local/bundle/gems/danger-6.0.9/lib/danger/danger_core/dangerfile.rb:297:in `eval_file'
from /usr/local/bundle/gems/danger-6.0.9/lib/danger/danger_core/dangerfile.rb:200:in `block in parse'
from /usr/local/bundle/gems/danger-6.0.9/lib/danger/danger_core/dangerfile.rb:197:in `instance_eval'
from /usr/local/bundle/gems/danger-6.0.9/lib/danger/danger_core/dangerfile.rb:197:in `parse'
from /usr/local/bundle/gems/danger-6.0.9/lib/danger/danger_core/plugins/dangerfile_danger_plugin.rb:129:in `import_dangerfile_from_path'
from /usr/local/bundle/gems/danger-6.0.9/lib/danger/danger_core/plugins/dangerfile_danger_plugin.rb:84:in `import_dangerfile'
from Dangerfile:9:in `eval_file'
from /usr/local/bundle/gems/danger-6.0.9/lib/danger/danger_core/dangerfile.rb:297:in `eval'
from /usr/local/bundle/gems/danger-6.0.9/lib/danger/danger_core/dangerfile.rb:297:in `eval_file'
from /usr/local/bundle/gems/danger-6.0.9/lib/danger/danger_core/dangerfile.rb:200:in `block in parse'
from /usr/local/bundle/gems/danger-6.0.9/lib/danger/danger_core/dangerfile.rb:197:in `instance_eval'
from /usr/local/bundle/gems/danger-6.0.9/lib/danger/danger_core/dangerfile.rb:197:in `parse'
from /usr/local/bundle/gems/danger-6.0.9/lib/danger/danger_core/dangerfile.rb:273:in `run'
from /usr/local/bundle/gems/danger-6.0.9/lib/danger/danger_core/executor.rb:29:in `run'
from /usr/local/bundle/gems/danger-6.0.9/lib/danger/commands/runner.rb:72:in `run'
from /usr/local/bundle/gems/claide-1.0.3/lib/claide/command.rb:334:in `run'
from /usr/local/bundle/gems/danger-6.0.9/bin/danger:5:in `<top (required)>'
from /usr/local/bundle/bin/danger:23:in `load'
from /usr/local/bundle/bin/danger:23:in `<main>'
Here is an example of the same MR with an added export LC_ALL=C.UTF-8
, verifying that this fix works: https://gitlab.com/gitlab-org/gitlab-ce/-/jobs/275424353.
I went with C.UTF-8
instead of en_US.UTF-8
because that locale is already present in the image, and we can avoid installing the locale-gen
utility.