Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed gihub actions upload #211 #212

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ target/
*.iws
.idea/
.bloop/
.bsp/
.metals/
metals.sbt

Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.3.1")
1) Add the following to your `.github/workflows/ci.yml`

```yaml
- name: Git checkout (merge)
uses: actions/checkout@v3
if: github.event_name != 'pull_request'
with:
fetch-depth: 0

- name: Git checkout (PR)
uses: actions/checkout@v3
if: github.event_name == 'pull_request'
with:
fetch-depth: 0
# see: https://frontside.com/blog/2020-05-26-github-actions-pull_request/#how-does-pull_request-affect-actionscheckout
ref: ${{ github.event.pull_request.head.sha }}

- name: Run tests
run: sbt clean coverage test

Expand All @@ -67,6 +81,11 @@ addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.3.1")
COVERALLS_FLAG_NAME: Scala ${{ matrix.scala }}
```

Note the separate checkout step for pull requests.
It is needed because of
[the way pull_request affects actions checkout](https://frontside.com/blog/2020-05-26-github-actions-pull_request/#how-does-pull_request-affect-actionscheckout),
so correct commit info could be sent to coveralls.io

If you have a multi-module project, perform `coverageAggregate`
[as a separate command](https://github.com/scoverage/sbt-scoverage#multi-project-reports)

Expand Down
12 changes: 8 additions & 4 deletions src/main/scala/org/scoverage/coveralls/CIService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,22 @@ case object TravisPro extends CIService {
}

case object GitHubActions extends CIService {
val name = "github"
val name = ""
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently, that was the reason it was failing. Idk, maybe in case of gihub actions some more params are required by coveralls.io api.

Copy link
Contributor

@ruippeixotog ruippeixotog Jun 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, params are fine - it was failing because when the service is "github" you needed to pass a GitHub token, not a token obtained from Coveralls.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that makes sense, good catch!

val jobId: Option[String] = sys.env.get("GITHUB_RUN_ID")

// https://github.com/coverallsapp/github-action/blob/master/src/run.ts#L31-L40
val pullRequest: Option[String] = for {
eventName <- sys.env.get("GITHUB_EVENT_NAME") if eventName == "pull_request"
eventName <- sys.env.get("GITHUB_EVENT_NAME") if eventName.startsWith("pull_request")
payloadPath <- sys.env.get("GITHUB_EVENT_PATH")
source = Source.fromFile(payloadPath, "utf-8")
lines = try source.mkString finally source.close()
payload <- JSON.parseRaw(lines)
prNumber <- payload.asInstanceOf[JSONObject].obj.get("number")
} yield prNumber.toString
} yield prNumber.toString.stripSuffix(".0")

val currentBranch: Option[String] = sys.env.get("GITHUB_REF")
// https://docs.github.com/en/actions/learn-github-actions/environment-variables
val currentBranch: Option[String] = pullRequest match {
case Some(_) => sys.env.get("GITHUB_HEAD_REF")
case None => sys.env.get("GITHUB_REF_NAME")
}
}