diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a2e2fb9af6..99eb1ed57e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,22 +17,11 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v3.0.2 - - name: Install Go + - name: Set up Go uses: actions/setup-go@v3.2.0 with: - go-version: 1.18.0 - - name: Get Go cache paths - id: go-env - run: | - echo "::set-output name=cache::$(go env GOCACHE)" - echo "::set-output name=modcache::$(go env GOMODCACHE)" - - name: Set up Go cache - uses: actions/cache@v3.0.2 - with: - key: test-${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: test-${{ runner.os }}-go- - path: | - ${{ steps.go-env.outputs.cache }} - ${{ steps.go-env.outputs.modcache }} + go-version-file: .go-version + cache: true + cache-dependency-path: '**/go.sum' - name: Run tests run: go test -race go.pact.im/x/... diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index a912b6e2c5..d4237c5d58 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -10,25 +10,14 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v3.0.2 - - name: Install Go + - name: Set up Go uses: actions/setup-go@v3.2.0 with: - go-version: 1.18.0 - - name: Get Go cache paths - id: go-env - run: | - echo "::set-output name=cache::$(go env GOCACHE)" - echo "::set-output name=modcache::$(go env GOMODCACHE)" - - name: Set up Go cache - uses: actions/cache@v3.0.2 - with: - key: golangci-lint-${{ runner.os }}-go-${{ hashFiles('**/go.mod') }} - restore-keys: golangci-lint-${{ runner.os }}-go- - path: | - ${{ steps.go-env.outputs.cache }} - ${{ steps.go-env.outputs.modcache }} + go-version-file: .go-version + cache: true + cache-dependency-path: '**/go.sum' - name: Install golangci-lint - run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.45.2 + run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.46.2 - name: Get golangci-lint cache path id: golangci-lint-cache-status run: | @@ -40,44 +29,12 @@ jobs: restore-keys: golangci-lint-${{ runner.os }}-golangci-lint- path: ${{ steps.golangci-lint-cache-status.outputs.dir }} - name: Run golangci-lint - # Note that we filter some packages since they use type parameters and - # currently they are not supported in Go SSA analysis tooling. See also - # https://github.com/golangci/golangci-lint/issues/2649 run: | golangci-lint run --out-format=github-actions -- \ - $(go work edit -json | jq -c -r '[.Use[].DiskPath | select(. != "syncx" and . != "process")] | map_values(. + "/...")[]') - - go-mod-tidy: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v3.0.2 - - name: Install Go - uses: actions/setup-go@v3.2.0 - with: - go-version: 1.18.0 - - name: Get Go cache paths - id: go-env - run: | - echo "::set-output name=cache::$(go env GOCACHE)" - echo "::set-output name=modcache::$(go env GOMODCACHE)" - - name: Set up Go cache - uses: actions/cache@v3.0.2 - with: - key: go-mod-tidy-${{ runner.os }}-go-${{ hashFiles('**/go.mod') }} - restore-keys: | - go-mod-tidy-${{ runner.os }}-go- - path: | - ${{ steps.go-env.outputs.cache }} - ${{ steps.go-env.outputs.modcache }} - - name: Run go mod tidy - run: eval "$(go list -m -f '(cd {{printf "%q" .Dir}} && go mod tidy)')" - - name: Check git diff - run: git diff --exit-code + $(go work edit -json | jq -c -r '[.Use[].DiskPath] | map_values(. + "/...")[]') commitlint: runs-on: ubuntu-latest - if: github.actor != 'dependabot[bot]' steps: - name: Checkout code uses: actions/checkout@v3.0.2 diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml index 742a9a3d66..79c4977a46 100644 --- a/.github/workflows/pages.yml +++ b/.github/workflows/pages.yml @@ -14,30 +14,16 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v3.0.2 - - name: Install Go + - name: Set up Go uses: actions/setup-go@v3.2.0 with: - go-version: 1.18.0 - - name: Get Go cache paths - id: go-env - run: | - echo "::set-output name=cache::$(go env GOCACHE)" - echo "::set-output name=modcache::$(go env GOMODCACHE)" - - name: Set up Go cache - uses: actions/cache@v3.0.2 - with: - key: gocache-${{ runner.os }} - restore-keys: gocache- - path: | - ${{ steps.go-env.outputs.cache }} - ${{ steps.go-env.outputs.modcache }} + go-version-file: .go-version + cache: true + cache-dependency-path: '**/go.sum' - name: Install vangen run: go install 4d63.com/vangen@v1.2.0 - name: Install golds - run: go install go101.org/golds@v0.4.8 - # See https://github.com/go101/golds/issues/28 - - name: Warm up Go modules cache - run: go work sync + run: go install go101.org/golds@v0.4.9 - name: Build pages run: | vangen -out build diff --git a/.github/workflows/tidy.yml b/.github/workflows/tidy.yml new file mode 100644 index 0000000000..b6f7c67687 --- /dev/null +++ b/.github/workflows/tidy.yml @@ -0,0 +1,24 @@ +name: Tidy +on: + push: + pull_request: + workflow_dispatch: + +jobs: + check: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3.0.2 + - name: Set up Go + uses: actions/setup-go@v3.2.0 + with: + go-version-file: .go-version + cache: true + cache-dependency-path: '**/go.sum' + - name: Update go.sum + run: eval "$(go list -m -f '(cd {{printf "%q" .Dir}} && go mod tidy)')" + - name: Update go.work.sum + run: go work sync + - name: Check git diff + run: git diff --exit-code diff --git a/.go-version b/.go-version new file mode 100644 index 0000000000..b57fc7228b --- /dev/null +++ b/.go-version @@ -0,0 +1 @@ +1.18.2 diff --git a/.golangci.yml b/.golangci.yml index 57c34ad8ec..f08f723acb 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -31,3 +31,8 @@ linters: issues: exclude-use-default: false + exclude-rules: + # Workaround for https://github.com/mgechev/revive/issues/669 + - text: '^receiver-naming: receiver name \w+ should be consistent with previous receiver name \w+ for invalid-type$' + linters: + - revive diff --git a/clock/fakeclock/fakeclock.go b/clock/fakeclock/fakeclock.go index eab2010910..627765e3d2 100644 --- a/clock/fakeclock/fakeclock.go +++ b/clock/fakeclock/fakeclock.go @@ -41,17 +41,22 @@ type Clock struct { sched map[moment]time.Time } -// Unix returns a clock set to the Unix epoch time. +// Unix returns a clock set to the Unix epoch time. That is, it is set to +// 1970-01-01 00:00:00 UTC. func Unix() *Clock { return Time(time.Unix(0, 0)) } -// Go returns a clock set to the Go initial release date. +// Go returns a clock set to the Go initial release date. That is, it is set to +// 2009-11-10 23:00:00 UTC. func Go() *Clock { return Time(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)) } // Y2038 returns a clock set to d duration after the Year 2038 problem time. +// That is, it is set to the given duration after 2038-01-19 03:14:07 UTC, the +// latest time that can be properly encoded as a 32-bit integer that is a number +// of seconds after the Unix epoch. func Y2038(d time.Duration) *Clock { t := time.Unix(math.MaxInt32, 0) return Time(t.Add(d)) diff --git a/clock/fakeclock/fakeclock_test.go b/clock/fakeclock/fakeclock_test.go index 7e80a3188f..03b3036143 100644 --- a/clock/fakeclock/fakeclock_test.go +++ b/clock/fakeclock/fakeclock_test.go @@ -23,7 +23,7 @@ func TestClockNow(t *testing.T) { } func TestClockNext(t *testing.T) { - sim := Y2038(time.Nanosecond) + sim := Y2038(time.Second) now := sim.Now() next, ok := sim.Next() if !next.Equal(now) {