diff --git a/.gitignore b/.gitignore index 7ee831e..e9ba520 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ target/ *.iws .idea/ .bloop/ +.bsp/ .metals/ metals.sbt diff --git a/README.md b/README.md index 1ea4149..f561aca 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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) diff --git a/src/main/scala/org/scoverage/coveralls/CIService.scala b/src/main/scala/org/scoverage/coveralls/CIService.scala index e1e7351..f40f3e3 100644 --- a/src/main/scala/org/scoverage/coveralls/CIService.scala +++ b/src/main/scala/org/scoverage/coveralls/CIService.scala @@ -25,18 +25,22 @@ case object TravisPro extends CIService { } case object GitHubActions extends CIService { - val name = "github" + val name = "" 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") + } }