Skip to content

Commit dd37af7

Browse files
andrcunsbaev
authored andcommitted
set coveralls environment variables (via #45)
1 parent 83e8f1f commit dd37af7

2 files changed

Lines changed: 15 additions & 8 deletions

File tree

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
run: bundle exec rake test_with_coverage
3434
env:
3535
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_TOKEN }}
36-
CI: true
36+
CI: "true"
3737
CI_NAME: github-ci
3838
CI_PULL_REQUEST: ${{ github.event.number }}
39-
GIT_ID: ${{ github.event.after }}
39+
CONTEXT: ${{ toJson(github) }}

rake/test.rb

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
require "rspec/core/rake_task"
44
require "rubocop/rake_task"
5+
require "json"
56

67
require_relative "util"
78

@@ -91,16 +92,22 @@ def display_coverage(result)
9192
end
9293

9394
def publish_coverage(result)
94-
ENV["GIT_BRANCH"] = ENV["CI_BRANCH"] = pull_request? ? ENV["GITHUB_HEAD_REF"] : ENV["GITHUB_REF"].split("/").last
95-
if pull_request?
96-
name, email, message = `git --no-pager show -s --format='%cn|%ce|%s' $GIT_ID`.strip.split("|")
97-
ENV["GIT_COMMITTER_NAME"] = name
98-
ENV["GIT_COMMITTER_EMAIL"] = email
99-
ENV["GIT_MESSAGE"] = message
95+
JSON.parse(ENV["CONTEXT"], object_class: OpenStruct).tap do |context|
96+
coveralls_set_env(pull_request? ? context.event.pull_request.head.sha : context.sha)
10097
end
10198
Coveralls::SimpleCov::Formatter.new.format(result)
10299
end
103100

101+
def coveralls_set_env(sha)
102+
ENV["GIT_ID"] = sha
103+
ENV["GIT_BRANCH"] = ENV["CI_BRANCH"] = pull_request? ? ENV["GITHUB_HEAD_REF"] : ENV["GITHUB_REF"].split("/").last
104+
ENV["GIT_MESSAGE"] = `git --no-pager show -s --format='%s' #{sha}`
105+
ENV["GIT_COMMITTER_NAME"] = `git --no-pager show -s --format='%cN' #{sha}`
106+
ENV["GIT_COMMITTER_EMAIL"] = `git --no-pager show -s --format='%ce' #{sha}`
107+
ENV["GIT_AUTHOR_NAME"] = `git --no-pager show -s --format='%aN' #{sha}`
108+
ENV["GIT_AUTHOR_EMAIL"] = `git --no-pager show -s --format='%ae' #{sha}`
109+
end
110+
104111
def pull_request?
105112
ENV["GITHUB_EVENT_NAME"] == "pull_request"
106113
end

0 commit comments

Comments
 (0)