From 5a8b2ec1d94eb080f7f2e92e4f1ad08cf6a6c929 Mon Sep 17 00:00:00 2001 From: Toan Nguyen Date: Sat, 29 Jun 2024 00:00:48 +0700 Subject: [PATCH] ci: skip reporting coverage from forked repositories (#145) * ci: skip reporting coverage from forked repositories --- .github/workflows/test.yml | 16 ++------ .../graphql-ws-bc/server/package-lock.json | 38 +++++++++---------- example/graphql-ws-bc/server/package.json | 8 ++-- example/subscription/subscription_test.go | 16 +++----- 4 files changed, 32 insertions(+), 46 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9da8609..526b6f2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,14 +26,6 @@ jobs: - uses: actions/setup-go@v5 with: go-version: "1.20" - - uses: actions/cache@v4 - with: - path: | - ~/go/pkg/mod - ~/.cache/go-build - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- - name: Install dependencies run: | go get -t -v ./... @@ -52,8 +44,6 @@ jobs: version: latest only-new-issues: true skip-cache: true - skip-pkg-cache: true - skip-build-cache: true args: --timeout=120s - name: Run Go unit tests for example/subscription run: | @@ -63,13 +53,13 @@ jobs: - name: Run Go unit tests run: go test -v -race -timeout 3m -coverprofile=coverage.out ./... - name: Go coverage format - if: ${{ github.event_name == 'pull_request' }} + if: ${{ github.event_name == 'pull_request' && github.repository == 'hasura/go-graphql-client' }} run: | go get github.com/boumenot/gocover-cobertura go install github.com/boumenot/gocover-cobertura gocover-cobertura < coverage.out > coverage.xml - name: Code Coverage Summary Report - if: ${{ github.event_name == 'pull_request' }} + if: ${{ github.event_name == 'pull_request' && github.repository == 'hasura/go-graphql-client' }} uses: irongut/CodeCoverageSummary@v1.3.0 with: filename: coverage.xml @@ -83,7 +73,7 @@ jobs: thresholds: "60 80" - name: Add Coverage PR Comment uses: marocchino/sticky-pull-request-comment@v2 - if: ${{ github.event_name == 'pull_request' }} + if: ${{ github.event_name == 'pull_request' && github.repository == 'hasura/go-graphql-client' }} with: path: code-coverage-results.md - name: Dump docker logs on failure diff --git a/example/graphql-ws-bc/server/package-lock.json b/example/graphql-ws-bc/server/package-lock.json index ce9c413..e5e8253 100644 --- a/example/graphql-ws-bc/server/package-lock.json +++ b/example/graphql-ws-bc/server/package-lock.json @@ -9,15 +9,15 @@ "version": "1.0.0", "license": "MIT", "dependencies": { - "graphql": "^16.8.1", - "graphql-ws": "^5.14.3", + "graphql": "^16.9.0", + "graphql-ws": "^5.16.0", "subscriptions-transport-ws": "^0.11.0", - "ws": "^8.16.0" + "ws": "^8.17.1" }, "devDependencies": { "@types/ws": "^8.5.10", "ts-node": "^10.9.2", - "typescript": "^5.3.3" + "typescript": "^5.5.2" } }, "node_modules/@cspotcode/source-map-support": { @@ -152,17 +152,17 @@ "integrity": "sha512-tvtQIeLVHjDkJYnzf2dgVMxfuSGJeM/7UCG17TT4EumTfNtF+0nebF/4zWOIkCreAbtNqhGEboB6BWrwqNaw4Q==" }, "node_modules/graphql": { - "version": "16.8.1", - "resolved": "https://registry.npmjs.org/graphql/-/graphql-16.8.1.tgz", - "integrity": "sha512-59LZHPdGZVh695Ud9lRzPBVTtlX9ZCV150Er2W43ro37wVof0ctenSaskPPjN7lVTIN8mSZt8PHUNKZuNQUuxw==", + "version": "16.9.0", + "resolved": "https://registry.npmjs.org/graphql/-/graphql-16.9.0.tgz", + "integrity": "sha512-GGTKBX4SD7Wdb8mqeDLni2oaRGYQWjWHGKPQ24ZMnUtKfcsVoiv4uX8+LJr1K6U5VW2Lu1BwJnj7uiori0YtRw==", "engines": { "node": "^12.22.0 || ^14.16.0 || ^16.0.0 || >=17.0.0" } }, "node_modules/graphql-ws": { - "version": "5.14.3", - "resolved": "https://registry.npmjs.org/graphql-ws/-/graphql-ws-5.14.3.tgz", - "integrity": "sha512-F/i2xNIVbaEF2xWggID0X/UZQa2V8kqKDPO8hwmu53bVOcTL7uNkxnexeEgSCVxYBQUTUNEI8+e4LO1FOhKPKQ==", + "version": "5.16.0", + "resolved": "https://registry.npmjs.org/graphql-ws/-/graphql-ws-5.16.0.tgz", + "integrity": "sha512-Ju2RCU2dQMgSKtArPbEtsK5gNLnsQyTNIo/T7cZNp96niC1x0KdJNZV0TIoilceBPQwfb5itrGl8pkFeOUMl4A==", "engines": { "node": ">=10" }, @@ -198,9 +198,9 @@ } }, "node_modules/subscriptions-transport-ws/node_modules/ws": { - "version": "7.5.9", - "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.9.tgz", - "integrity": "sha512-F+P9Jil7UiSKSkppIiD94dN07AwvFixvLIj1Og1Rl9GGMuNipJnV9JzjD6XuqmAeiswGvUmNLjr5cFuXwNS77Q==", + "version": "7.5.10", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.10.tgz", + "integrity": "sha512-+dbF1tHwZpXcbOJdVOkzLDxZP1ailvSxM6ZweXTegylPny803bFhA+vqBYw4s31NSAk4S2Qz+AKXK9a4wkdjcQ==", "engines": { "node": ">=8.3.0" }, @@ -269,9 +269,9 @@ } }, "node_modules/typescript": { - "version": "5.3.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.3.tgz", - "integrity": "sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==", + "version": "5.5.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.2.tgz", + "integrity": "sha512-NcRtPEOsPFFWjobJEtfihkLCZCXZt/os3zf8nTxjVH3RvTSxjrCamJpbExGvYOF+tFHc3pA65qpdwPbzjohhew==", "dev": true, "bin": { "tsc": "bin/tsc", @@ -294,9 +294,9 @@ "dev": true }, "node_modules/ws": { - "version": "8.16.0", - "resolved": "https://registry.npmjs.org/ws/-/ws-8.16.0.tgz", - "integrity": "sha512-HS0c//TP7Ina87TfiPUz1rQzMhHrl/SG2guqRcTOIUYD2q8uhUdNHZYJUaQ8aTGPzCh+c6oawMKW35nFl1dxyQ==", + "version": "8.17.1", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.17.1.tgz", + "integrity": "sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ==", "engines": { "node": ">=10.0.0" }, diff --git a/example/graphql-ws-bc/server/package.json b/example/graphql-ws-bc/server/package.json index 827fa39..fb222ab 100644 --- a/example/graphql-ws-bc/server/package.json +++ b/example/graphql-ws-bc/server/package.json @@ -8,14 +8,14 @@ }, "license": "MIT", "dependencies": { - "graphql": "^16.8.1", - "graphql-ws": "^5.14.3", + "graphql": "^16.9.0", + "graphql-ws": "^5.16.0", "subscriptions-transport-ws": "^0.11.0", - "ws": "^8.16.0" + "ws": "^8.17.1" }, "devDependencies": { "@types/ws": "^8.5.10", "ts-node": "^10.9.2", - "typescript": "^5.3.3" + "typescript": "^5.5.2" } } diff --git a/example/subscription/subscription_test.go b/example/subscription/subscription_test.go index be3a6e8..1bf65cf 100644 --- a/example/subscription/subscription_test.go +++ b/example/subscription/subscription_test.go @@ -8,6 +8,7 @@ import ( "log" "net/http" "sync" + "sync/atomic" "testing" "time" @@ -370,8 +371,7 @@ func testSubscription_LifeCycleEvents(t *testing.T, syncMode bool) { var lock sync.Mutex subscriptionResults := []gql.Subscription{} - wasConnected := false - wasDisconnected := false + var wasConnected, wasDisconnected int32 addResult := func(s gql.Subscription) int { lock.Lock() defer lock.Unlock() @@ -436,20 +436,16 @@ func testSubscription_LifeCycleEvents(t *testing.T, syncMode bool) { WithTimeout(3 * time.Second). WithSyncMode(syncMode). OnConnected(func() { - lock.Lock() - defer lock.Unlock() log.Println("connected") - wasConnected = true + atomic.StoreInt32(&wasConnected, 1) }). OnError(func(sc *gql.SubscriptionClient, err error) error { t.Fatalf("got error: %v, want: nil", err) return err }). OnDisconnected(func() { - lock.Lock() - defer lock.Unlock() log.Println("disconnected") - wasDisconnected = true + atomic.StoreInt32(&wasDisconnected, 1) }). OnSubscriptionComplete(func(s gql.Subscription) { log.Println("OnSubscriptionComplete: ", s) @@ -542,10 +538,10 @@ func testSubscription_LifeCycleEvents(t *testing.T, syncMode bool) { } } - if !wasConnected { + if atomic.LoadInt32(&wasConnected) != 1 { t.Fatalf("expected OnConnected event, got none") } - if !wasDisconnected { + if atomic.LoadInt32(&wasDisconnected) != 1 { t.Fatalf("expected OnDisconnected event, got none") } }