Skip to content

Commit

Permalink
Merge pull request #199 from tie/go-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
tie committed May 28, 2022
2 parents d6c836a + 66375ac commit fa9f353
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 86 deletions.
19 changes: 4 additions & 15 deletions .github/workflows/ci.yml
Expand Up @@ -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/...
55 changes: 6 additions & 49 deletions .github/workflows/lint.yml
Expand Up @@ -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: |
Expand All @@ -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
Expand Down
24 changes: 5 additions & 19 deletions .github/workflows/pages.yml
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions .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
1 change: 1 addition & 0 deletions .go-version
@@ -0,0 +1 @@
1.18.2
5 changes: 5 additions & 0 deletions .golangci.yml
Expand Up @@ -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
9 changes: 7 additions & 2 deletions clock/fakeclock/fakeclock.go
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion clock/fakeclock/fakeclock_test.go
Expand Up @@ -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) {
Expand Down

0 comments on commit fa9f353

Please sign in to comment.