From 9b9d7b4aac087688af34698a3a0b45fc8d6303a4 Mon Sep 17 00:00:00 2001
From: Anmol Sethi <hi@nhooyr.io>
Date: Mon, 14 Oct 2019 17:18:48 -0400
Subject: [PATCH] Cleanup coveralls setup

---
 .github/workflows/ci.yml | 10 +++++-----
 ci/Dockerfile            |  1 +
 ci/test.mk               | 12 ++++++++----
 3 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 6154df4..2cc6982 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -1,27 +1,27 @@
 name: ci
-on: [push]
+on: [push, pull_request]
 
 jobs:
   fmt:
     runs-on: ubuntu-latest
-    container: nhooyr/websocket-ci@sha256:046cd02e79dcbf81dc06eb6fd333fa8643f2503f437ddd46a4c1af9132078a2c
+    container: nhooyr/websocket-ci@sha256:8a8fd73fdea33585d50a33619c4936adfd016246a2ed6bbfbf06def24b518a6a
     steps:
       - uses: actions/checkout@v1
       - run: make fmt
   lint:
     runs-on: ubuntu-latest
-    container: nhooyr/websocket-ci@sha256:046cd02e79dcbf81dc06eb6fd333fa8643f2503f437ddd46a4c1af9132078a2c
+    container: nhooyr/websocket-ci@sha256:8a8fd73fdea33585d50a33619c4936adfd016246a2ed6bbfbf06def24b518a6a
     steps:
       - uses: actions/checkout@v1
       - run: make lint
   test:
     runs-on: ubuntu-latest
-    container: nhooyr/websocket-ci@sha256:046cd02e79dcbf81dc06eb6fd333fa8643f2503f437ddd46a4c1af9132078a2c
+    container: nhooyr/websocket-ci@sha256:8a8fd73fdea33585d50a33619c4936adfd016246a2ed6bbfbf06def24b518a6a
     steps:
       - uses: actions/checkout@v1
       - run: make test
         env:
-          COVERALLS_TOKEN: ${{ secrets.COVERALLS_TOKEN }}
+          COVERALLS_TOKEN: ${{ secrets.github_token }}
       - name: Upload coverage.html
         uses: actions/upload-artifact@master
         with:
diff --git a/ci/Dockerfile b/ci/Dockerfile
index b9068fa..0f0fc7d 100644
--- a/ci/Dockerfile
+++ b/ci/Dockerfile
@@ -3,6 +3,7 @@ FROM golang:1
 RUN apt-get update
 RUN apt-get install -y chromium
 RUN apt-get install -y npm
+RUN apt-get install -y jq
 
 ENV GOPATH=/root/gopath
 ENV PATH=$GOPATH/bin:$PATH
diff --git a/ci/test.mk b/ci/test.mk
index 2560953..f34c2b7 100644
--- a/ci/test.mk
+++ b/ci/test.mk
@@ -7,11 +7,15 @@ ci/out/coverage.html: gotest
 	go tool cover -html=ci/out/coverage.prof -o=ci/out/coverage.html
 
 coveralls: gotest
+	# https://github.com/coverallsapp/github-action/blob/master/src/run.ts
 	echo "--- coveralls"
-	export GIT_BRANCH=$${GITHUB_REF}
-	export BUILD_NUMBER=$${GITHUB_ACTION}
-	goveralls -coverprofile=ci/out/coverage.prof -service=github-actions
-
+	export GIT_BRANCH="$$GITHUB_REF"
+	export BUILD_NUMBER="$$GITHUB_SHA"
+	if [[ $$GITHUB_EVENT_NAME == pull_request ]]; then
+	  export CI_PULL_REQUEST="$$(jq .number "$$GITHUB_EVENT_PATH")"
+	  BUILD_NUMBER="$$BUILD_NUMBER-PR-$$CI_PULL_REQUEST"
+	fi
+	goveralls -coverprofile=ci/out/coverage.prof -service=github
 gotest:
 	go test -covermode=count -coverprofile=ci/out/coverage.prof -coverpkg=./... $${GOTESTFLAGS-} ./...
 	sed -i '/_stringer\.go/d' ci/out/coverage.prof
-- 
GitLab