Skip to content

Commit

Permalink
ci: update Unified CI configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentsenta authored Jul 3, 2023
2 parents ea551d0 + 6253701 commit de83c0c
Show file tree
Hide file tree
Showing 8 changed files with 186 additions and 51 deletions.
11 changes: 11 additions & 0 deletions .github/actions/go-test-setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: "Go Test Setup"
# https://github.com/protocol/.github#setup-actions
description: "Setup the Go test environment."

runs:
using: "composite"
steps:
- name: Drop conformance tests - keep only unit tests
shell: bash
run: |
rm -rf ./tests
11 changes: 11 additions & 0 deletions .github/workflows/automerge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# File managed by web3-bot. DO NOT EDIT.
# See https://github.com/protocol/.github/ for details.

name: Automerge
on: [ pull_request ]

jobs:
automerge:
uses: protocol/.github/.github/workflows/automerge.yml@master
with:
job: 'automerge'
67 changes: 67 additions & 0 deletions .github/workflows/go-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# File managed by web3-bot. DO NOT EDIT.
# See https://github.com/protocol/.github/ for details.

on: [push, pull_request]
name: Go Checks

jobs:
unit:
runs-on: ubuntu-latest
name: All
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.20.x
- name: Run repo-specific setup
uses: ./.github/actions/go-check-setup
if: hashFiles('./.github/actions/go-check-setup') != ''
- name: Install staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@4970552d932f48b71485287748246cf3237cebdf # 2023.1 (v0.4.0)
- name: Check that go.mod is tidy
uses: protocol/multiple-go-modules@v1.2
with:
run: |
go mod tidy
if [[ -n $(git ls-files --other --exclude-standard --directory -- go.sum) ]]; then
echo "go.sum was added by go mod tidy"
exit 1
fi
git diff --exit-code -- go.sum go.mod
- name: gofmt
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
uses: protocol/multiple-go-modules@v1.2
with:
run: go vet ./...
- name: staticcheck
if: success() || failure() # run this step even if the previous one failed
uses: protocol/multiple-go-modules@v1.2
with:
run: |
set -o pipefail
staticcheck ./... | sed -e 's@\(.*\)\.go@./\1.go@g'
- name: go generate
uses: protocol/multiple-go-modules@v1.2
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 -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:"
git status --short
exit 1
fi
76 changes: 76 additions & 0 deletions .github/workflows/go-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# File managed by web3-bot. DO NOT EDIT.
# See https://github.com/protocol/.github/ for details.

on: [push, pull_request]
name: Go Test

jobs:
unit:
strategy:
fail-fast: false
matrix:
os: [ "ubuntu", "windows", "macos" ]
go: ["1.19.x","1.20.x"]
env:
COVERAGES: ""
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 }}
- name: Go information
run: |
go version
go env
- name: Use msys2 on 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
# If we prepend its location to the PATH
# subsequent 'shell: bash' steps will use msys2 instead of gitbash
run: echo "C:/msys64/usr/bin" >> $GITHUB_PATH
- name: Run repo-specific setup
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/multiple-go-modules@v1.2
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)
# 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/multiple-go-modules@v1.2
env:
GOARCH: 386
with:
run: |
export "PATH=$PATH_386:$PATH"
go test -v -shuffle=on ./...
- name: Run tests with race detector
# 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/multiple-go-modules@v1.2
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@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1
with:
files: '${{ env.COVERAGES }}'
env_vars: OS=${{ matrix.os }}, GO=${{ matrix.go }}
31 changes: 0 additions & 31 deletions .github/workflows/test-tooling.yml

This file was deleted.

24 changes: 12 additions & 12 deletions cmd/gateway-conformance/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ import (
"github.com/urfave/cli/v2"
)

type event struct {
Action string
Test string `json:",omitempty"`
}

type out struct {
Writer io.Writer
Filter func(s string) bool
Expand Down Expand Up @@ -118,8 +113,8 @@ func main() {
Destination: &specs,
},
&cli.BoolFlag{
Name: "verbose",
Usage: "Prints all the output to the console.",
Name: "verbose",
Usage: "Prints all the output to the console.",
Value: false,
Destination: &verbose,
},
Expand Down Expand Up @@ -155,12 +150,15 @@ func main() {
}
cmd.Stderr = os.Stderr

fmt.Println("Running tests...\n")
fmt.Println("Running tests...")
fmt.Println()
testErr := cmd.Run()
fmt.Println("\nDONE!\n")
fmt.Println("\nDONE!")
fmt.Println()

if testErr != nil {
fmt.Println("\nLooking for details...\n")
fmt.Println("\nLooking for details...")
fmt.Println()
strOutput := output.String()
lineDump := []string{}
for _, line := range strings.Split(strOutput, "\n") {
Expand All @@ -176,7 +174,8 @@ func main() {
lineDump = append(lineDump, line)
}
}
fmt.Println("\nDONE!\n")
fmt.Println("\nDONE!")
fmt.Println()
}

if jsonOutput != "" {
Expand Down Expand Up @@ -206,7 +205,8 @@ func main() {
if err != nil {
return err
}
fmt.Println("DONE!\n")
fmt.Println("DONE!")
fmt.Println()
}

return testErr
Expand Down
4 changes: 2 additions & 2 deletions tooling/check/car_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package check

import (
"io/ioutil"
"io"
"os"
"testing"

Expand All @@ -15,7 +15,7 @@ func loadFile(t *testing.T, carFilePath string) []byte {
}
defer file.Close()

fileBytes, err := ioutil.ReadAll(file)
fileBytes, err := io.ReadAll(file)
if err != nil {
t.Fatalf("failed to read car file: %v", err)
}
Expand Down
13 changes: 7 additions & 6 deletions tooling/test/sugar.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package test

import (
"bytes"
"net/url"

"github.com/ipfs/gateway-conformance/tooling/check"
Expand Down Expand Up @@ -128,7 +127,9 @@ func (r RequestBuilder) Clone() RequestBuilder {
Headers_: clonedHeaders,
FollowRedirects_: r.FollowRedirects_,
Query_: clonedQuery,
Body_: bytes.Clone(r.Body_),
// TODO: replace this call with bytes.Clone when we switch to Go 1.20
// See https://github.com/golang/go/issues/45038#issuecomment-799795384
Body_: append([]byte(nil), r.Body_...),
}
}

Expand Down Expand Up @@ -172,14 +173,14 @@ func (e ExpectBuilder) Body(body interface{}) ExpectBuilder {
e.Body_ = []byte(body)
case []byte:
e.Body_ = body
case check.Check[string]:
e.Body_ = body
case check.CheckWithHint[string]:
e.Body_ = body
case check.Check[[]byte]:
e.Body_ = body
case check.CheckWithHint[[]byte]:
e.Body_ = body
case check.Check[string]:
e.Body_ = body
case check.Check[[]byte]:
e.Body_ = body
default:
panic("body must be string, []byte, or a regular check")
}
Expand Down

0 comments on commit de83c0c

Please sign in to comment.