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

sync: update CI config files #2073

Merged
merged 13 commits into from
Feb 12, 2023
24 changes: 9 additions & 15 deletions .github/workflows/go-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,20 @@ jobs:
unit:
runs-on: ubuntu-latest
name: All
env:
RUNGOGENERATE: false
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- id: config
uses: protocol/.github/.github/actions/read-config@master
- uses: actions/setup-go@v3
with:
go-version: "1.19.x"
go-version: 1.20.x
- name: Run repo-specific setup
uses: ./.github/actions/go-check-setup
if: hashFiles('./.github/actions/go-check-setup') != ''
- name: Read config
if: hashFiles('./.github/workflows/go-check-config.json') != ''
run: |
if jq -re .gogenerate ./.github/workflows/go-check-config.json; then
echo "RUNGOGENERATE=true" >> $GITHUB_ENV
fi
- name: Install staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@376210a89477dedbe6fdc4484b233998650d7b3c # 2022.1.3 (v0.3.3)
run: go install honnef.co/go/tools/cmd/staticcheck@4970552d932f48b71485287748246cf3237cebdf # 2023.1 (v0.4.0)
- name: Check that go.mod is tidy
uses: protocol/[email protected]
with:
Expand All @@ -39,32 +33,32 @@ jobs:
fi
git diff --exit-code -- go.sum go.mod
- name: gofmt
if: ${{ success() || failure() }} # run this step even if the previous one failed
if: success() || failure() # run this step even if the previous one failed
run: |
out=$(gofmt -s -l .)
if [[ -n "$out" ]]; then
echo $out | awk '{print "::error file=" $0 ",line=0,col=0::File is not gofmt-ed."}'
exit 1
fi
- name: go vet
if: ${{ success() || failure() }} # run this step even if the previous one failed
if: success() || failure() # run this step even if the previous one failed
uses: protocol/[email protected]
with:
run: go vet ./...
- name: staticcheck
if: ${{ success() || failure() }} # run this step even if the previous one failed
if: success() || failure() # run this step even if the previous one failed
uses: protocol/[email protected]
with:
run: |
set -o pipefail
staticcheck ./... | sed -e 's@\(.*\)\.go@./\1.go@g'
- name: go generate
uses: protocol/[email protected]
if: (success() || failure()) && env.RUNGOGENERATE == 'true'
if: (success() || failure()) && fromJSON(steps.config.outputs.json).gogenerate == true
with:
run: |
git clean -fd # make sure there aren't untracked files / directories
go generate ./...
go generate -x ./...
# check if go generate modified or added any files
if ! $(git add . && git diff-index HEAD --exit-code --quiet); then
echo "go generated caused changes to the repository:"
Expand Down
22 changes: 15 additions & 7 deletions .github/workflows/go-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ jobs:
fail-fast: false
matrix:
os: [ "ubuntu", "windows", "macos" ]
go: [ "1.18.x", "1.19.x" ]
go: ["1.19.x","1.20.x"]
env:
COVERAGES: ""
runs-on: ${{ format('{0}-latest', matrix.os) }}
runs-on: ${{ fromJSON(vars[format('UCI_GO_TEST_RUNNER_{0}', matrix.os)] || format('"{0}-latest"', matrix.os)) }}
name: ${{ matrix.os }} (go ${{ matrix.go }})
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- id: config
uses: protocol/.github/.github/actions/read-config@master
- uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}
Expand All @@ -27,7 +29,7 @@ jobs:
go version
go env
- name: Use msys2 on windows
if: ${{ matrix.os == 'windows' }}
if: matrix.os == 'windows'
shell: bash
# The executable for msys2 is also called bash.cmd
# https://github.com/actions/virtual-environments/blob/main/images/win/Windows2019-Readme.md#shells
Expand All @@ -38,31 +40,37 @@ jobs:
uses: ./.github/actions/go-test-setup
if: hashFiles('./.github/actions/go-test-setup') != ''
- name: Run tests
if: contains(fromJSON(steps.config.outputs.json).skipOSes, matrix.os) == false
uses: protocol/[email protected]
with:
# Use -coverpkg=./..., so that we include cross-package coverage.
# If package ./A imports ./B, and ./A's tests also cover ./B,
# this means ./B's coverage will be significantly higher than 0%.
run: go test -v -shuffle=on -coverprofile=module-coverage.txt -coverpkg=./... ./...
- name: Run tests (32 bit)
if: ${{ matrix.os != 'macos' }} # can't run 32 bit tests on OSX.
# can't run 32 bit tests on OSX.
if: matrix.os != 'macos' &&
fromJSON(steps.config.outputs.json).skip32bit != true &&
contains(fromJSON(steps.config.outputs.json).skipOSes, matrix.os) == false
uses: protocol/[email protected]
env:
GOARCH: 386
with:
run: |
export "PATH=${{ env.PATH_386 }}:$PATH"
export "PATH=$PATH_386:$PATH"
go test -v -shuffle=on ./...
- name: Run tests with race detector
if: ${{ matrix.os == 'ubuntu' }} # speed things up. Windows and OSX VMs are slow
# speed things up. Windows and OSX VMs are slow
if: matrix.os == 'ubuntu' &&
contains(fromJSON(steps.config.outputs.json).skipOSes, matrix.os) == false
uses: protocol/[email protected]
with:
run: go test -v -race ./...
- name: Collect coverage files
shell: bash
run: echo "COVERAGES=$(find . -type f -name 'module-coverage.txt' | tr -s '\n' ',' | sed 's/,$//')" >> $GITHUB_ENV
- name: Upload coverage to Codecov
uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0
uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1
with:
files: '${{ env.COVERAGES }}'
env_vars: OS=${{ matrix.os }}, GO=${{ matrix.go }}
4 changes: 3 additions & 1 deletion .github/workflows/release-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

name: Release Checker
on:
pull_request:
pull_request_target:
paths: [ 'version.json' ]

jobs:
release-check:
uses: protocol/.github/.github/workflows/release-check.yml@master
with:
go-version: 1.20.x
2 changes: 1 addition & 1 deletion core/test/peer.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package test

import (
"math/rand"
"crypto/rand"
"testing"

"github.com/libp2p/go-libp2p/core/peer"
Expand Down
2 changes: 1 addition & 1 deletion examples/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/libp2p/go-libp2p/examples

go 1.18
go 1.19

require (
github.com/gogo/protobuf v1.3.2
Expand Down
3 changes: 2 additions & 1 deletion examples/ipfs-camp-2019/07-Messaging/chat.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion examples/ipfs-camp-2019/08-End/chat.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/ipfs-camp-2019/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/libp2p/go-libp2p/examples/ipfs-camp-2019

go 1.18
go 1.19

require (
github.com/gogo/protobuf v1.3.2
Expand Down
4 changes: 2 additions & 2 deletions examples/multipro/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
)

func main() {
rnd := rand.New(rand.NewSource(666))
// Choose random ports between 10000-10100
rand.Seed(666)
port1 := rand.Intn(100) + 10000
port1 := rnd.Intn(100) + 10000
port2 := port1 + 1

done := make(chan bool, 1)
Expand Down
10 changes: 7 additions & 3 deletions examples/multipro/pb/p2p.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/pubsub/basic-chat-with-rendezvous/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/libp2p/go-libp2p/examples/pubsub/chat

go 1.18
go 1.19

require (
github.com/libp2p/go-libp2p v0.25.1
Expand Down
2 changes: 1 addition & 1 deletion examples/pubsub/chat/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/libp2p/go-libp2p/examples/pubsub/chat

go 1.18
go 1.19

require (
github.com/gdamore/tcell/v2 v2.5.2
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/libp2p/go-libp2p

go 1.18
go 1.19

require (
github.com/benbjohnson/clock v1.3.0
Expand Down
1 change: 0 additions & 1 deletion p2p/host/resource-manager/sys_unix.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build linux || darwin
// +build linux darwin

package rcmgr

Expand Down
8 changes: 3 additions & 5 deletions p2p/net/pnet/psk_conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package pnet
import (
"bytes"
"context"
"math/rand"
"crypto/rand"
"net"
"testing"
)
Expand Down Expand Up @@ -62,8 +62,7 @@ func TestPSKFragmentation(t *testing.T) {
psk1, psk2 := setupPSKConns(ctx, t)

in := make([]byte, 1000)
_, err := rand.Read(in)
if err != nil {
if _, err := rand.Read(in); err != nil {
t.Fatal(err)
}

Expand All @@ -85,8 +84,7 @@ func TestPSKFragmentation(t *testing.T) {
in = in[100:]
}

err = <-wch
if err != nil {
if err := <-wch; err != nil {
t.Fatal(err)
}
}
8 changes: 3 additions & 5 deletions p2p/protocol/circuitv2/relay/relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package relay_test
import (
"bytes"
"context"
"crypto/rand"
"fmt"
"io"
"math/rand"
"testing"
"time"

Expand Down Expand Up @@ -325,8 +325,7 @@ func TestRelayLimitData(t *testing.T) {

buf := make([]byte, 1024)
for i := 0; i < 3; i++ {
_, err = rand.Read(buf)
if err != nil {
if _, err := rand.Read(buf); err != nil {
t.Fatal(err)
}

Expand All @@ -345,8 +344,7 @@ func TestRelayLimitData(t *testing.T) {
}

buf = make([]byte, 4096)
_, err = rand.Read(buf)
if err != nil {
if _, err := rand.Read(buf); err != nil {
t.Fatal(err)
}

Expand Down
15 changes: 5 additions & 10 deletions p2p/security/noise/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,6 @@ func TestPeerIDOutboundNoCheck(t *testing.T) {
require.NoError(t, initErr)
}

func makeLargePlaintext(size int) []byte {
buf := make([]byte, size)
rand.Read(buf)
return buf
}

func TestLargePayloads(t *testing.T) {
initTransport := newTestTransport(t, crypto.Ed25519, 2048)
respTransport := newTestTransport(t, crypto.Ed25519, 2048)
Expand All @@ -287,11 +281,12 @@ func TestLargePayloads(t *testing.T) {

// enough to require a couple Noise messages, with a size that
// isn't a neat multiple of Noise message size, just in case
size := 100000
rnd := rand.New(rand.NewSource(1234))
const size = 100000
before := make([]byte, size)
rnd.Read(before)

before := makeLargePlaintext(size)
_, err := initConn.Write(before)
if err != nil {
if _, err := initConn.Write(before); err != nil {
t.Fatal(err)
}

Expand Down
5 changes: 3 additions & 2 deletions p2p/test/reconnects/reconnect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func runRound(t *testing.T, hosts []host.Host) {
numStreams = 5
maxDataLen = 64 << 10
)
rnd := rand.New(rand.NewSource(12345))
// exchange some data
for _, h1 := range hosts {
for _, h2 := range hosts {
Expand All @@ -80,10 +81,10 @@ func runRound(t *testing.T, hosts []host.Host) {
var wg sync.WaitGroup
wg.Add(numStreams)
for i := 0; i < numStreams; i++ {
data := make([]byte, rand.Intn(maxDataLen)+1)
rnd.Read(data)
Copy link
Contributor

Choose a reason for hiding this comment

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

math/rand.Read:

Read should not be called concurrently with any other Rand method.

go func() {
defer wg.Done()
data := make([]byte, rand.Intn(maxDataLen)+1)
rand.Read(data)
str, err := h1.NewStream(context.Background(), h2.ID(), protocol.TestingID)
require.NoError(t, err)
defer str.Close()
Expand Down
4 changes: 3 additions & 1 deletion p2p/transport/quic/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type transport struct {

holePunchingMx sync.Mutex
holePunching map[holePunchKey]*activeHolePunch
rnd rand.Rand

connMx sync.Mutex
conns map[quic.Connection]*conn
Expand Down Expand Up @@ -94,6 +95,7 @@ func NewTransport(key ic.PrivKey, connManager *quicreuse.ConnManager, psk pnet.P
rcmgr: rcmgr,
conns: make(map[quic.Connection]*conn),
holePunching: make(map[holePunchKey]*activeHolePunch),
rnd: *rand.New(rand.NewSource(time.Now().UnixNano())),

listeners: make(map[string][]*virtualListener),
}, nil
Expand Down Expand Up @@ -217,7 +219,7 @@ func (t *transport) holePunch(ctx context.Context, raddr ma.Multiaddr, p peer.ID
var punchErr error
loop:
for i := 0; ; i++ {
if _, err := rand.Read(payload); err != nil {
if _, err := t.rnd.Read(payload); err != nil {
punchErr = err
break
}
Expand Down
Loading