Skip to content

Commit

Permalink
Merge 7976423 into 785dbd4
Browse files Browse the repository at this point in the history
  • Loading branch information
troyfontaine committed May 28, 2020
2 parents 785dbd4 + 7976423 commit 9906642
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 1 deletion.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ ignore:
- ProjectTestsGroup/*
```

And then in your `.travis.yml` or `circle.yml`, call `slather` after a successful build:
And then in your `.travis.yml` or `circle.yml` or `github-action.yml`, call `slather` after a successful build:

```yml
# .travis.yml
Expand All @@ -168,6 +168,20 @@ test:

```

```yml
# github-action.yml
myjob:
steps:
- run: |
bundle config path vendor/bundle
bundle install --without=documentation --jobs 4 --retry 3
- run: bundle exec slather
env:
GIT_BRANCH: ${{ github.event.pull_request.head.ref }}

```

#### Usage with Travis CI Pro

To use Coveralls with Travis CI Pro (for private repos), add following lines along with other settings to `.slather.yml`:
Expand Down
2 changes: 2 additions & 0 deletions lib/slather/command/coverage_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ def setup_service_name
project.ci_service = :buildkite
elsif teamcity?
project.ci_service = :teamcity
elsif github?
project.ci_service = :github
end
end

Expand Down
40 changes: 40 additions & 0 deletions lib/slather/coverage_service/coveralls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ def jenkins_job_id
end
private :jenkins_job_id

def github_job_id
ENV['GITHUB_RUN_ID']
end
private :github_job_id

def jenkins_branch_name
branch_name = ENV['GIT_BRANCH'] || ENV['BRANCH_NAME']
if branch_name.include? 'origin/'
Expand All @@ -51,6 +56,11 @@ def teamcity_branch_name
end
private :teamcity_branch_name

def github_branch_name
ENV['GIT_BRANCH'] || `git ls-remote --heads origin | grep $(git rev-parse HEAD) | cut -d / -f 3-`.chomp
end
private :github_branch_name

def buildkite_job_id
ENV['BUILDKITE_BUILD_NUMBER']
end
Expand Down Expand Up @@ -119,6 +129,23 @@ def buildkite_build_url
"https://buildkite.com/" + ENV['BUILDKITE_PROJECT_SLUG'] + "/builds/" + ENV['BUILDKITE_BUILD_NUMBER'] + "#"
end

def github_git_info
{
:head => {
:id => ENV['GITHUB_SHA'],
:author_name => ENV['GITHUB_ACTOR'],
:message => (`git log --format=%s -n 1 HEAD`.chomp || "")
},
:branch => github_branch_name
}
end
private :github_git_info

def github_build_url
"https://github.com/" + ENV['GITHUB_REPOSITORY'] + "/actions/runs/" + ENV['GITHUB_RUN_ID']
end
private :github_build_url

def coveralls_coverage_data
if ci_service == :travis_ci || ci_service == :travis_pro
if travis_job_id
Expand Down Expand Up @@ -206,6 +233,19 @@ def coveralls_coverage_data
else
raise StandardError, "Environment variable `TC_BUILD_NUMBER` not set. Is this running on a teamcity build?"
end
elsif ci_service == :github
if github_job_id
{
:service_job_id => github_job_id,
:service_name => "github",
:repo_token => coverage_access_token,
:source_files => coverage_files.map(&:as_json),
:service_build_url => github_build_url,
:git => github_git_info
}.to_json
else
raise StandardError, "Environment variable `GITHUB_RUN_ID` not set. Is this running on github build?"
end
else
raise StandardError, "No support for ci named #{ci_service}"
end
Expand Down
19 changes: 19 additions & 0 deletions spec/slather/coverage_service/coveralls_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,25 @@
ENV['GIT_BRANCH'] = git_branch
end
end

context "coverage_service is :github" do
before(:each) { fixtures_project.ci_service = :github }

it "should return valid json for coveralls coverage data" do
allow(fixtures_project).to receive(:github_job_id).and_return("9182")
allow(fixtures_project).to receive(:coverage_access_token).and_return("abc123")
allow(fixtures_project).to receive(:github_build_url).and_return("https://github.com/Bruce/Wayne/actions/runs/1")
allow(fixtures_project).to receive(:github_git_info).and_return({ :head => { :id => "ababa123", :author_name => "bwayne", :message => "hello" }, :branch => "master" })
expect(fixtures_project.send(:coveralls_coverage_data)).to be_json_eql("{\"service_job_id\":\"9182\",\"service_name\":\"github\",\"repo_token\":\"abc123\",\"service_pull_request\":\"1\",\"service_build_url\":\"https://github.com/Bruce/Wayne/actions/runs/1\",\"git\":{\"head\":{\"id\":\"ababa123\",\"author_name\":\"bwayne\",\"message\":\"hello\"},\"branch\":\"master\"}}").excluding("source_files")
expect(fixtures_project.send(:coveralls_coverage_data)).to be_json_eql(fixtures_project.coverage_files.map(&:as_json).to_json).at_path("source_files")
end

it "should raise an error if there is no GITHUB_RUN_ID" do
allow(fixtures_project).to receive(:github_job_id).and_return(nil)
expect { fixtures_project.send(:coveralls_coverage_data) }.to raise_error(StandardError)
end
end

end

describe '#coveralls_coverage_data' do
Expand Down

0 comments on commit 9906642

Please sign in to comment.