diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7e70506..5feab01 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,3 +1,5 @@ + + name: Build and Test on: @@ -23,12 +25,15 @@ jobs: echo github.ref_name: ${{ github.ref_name }} echo github.head_ref: ${{ github.head_ref }} echo github.base_ref: ${{ github.base_ref }} + - name: Checkout code uses: actions/checkout@v4 + - name: Set up Go environment uses: actions/setup-go@v5 with: go-version: '1.23' + - name: Tidy go module run: | go mod tidy @@ -38,11 +43,14 @@ jobs: echo "go mod tidy made these changes, please run 'go mod tidy' and include those changes in a commit" exit 1 fi + - name: Run gofumpt # Run gofumpt first, as it's quick and issues are common. run: diff -u <(echo -n) <(go run mvdan.cc/gofumpt@v0.7.0 -d .) + - name: Run go vet run: go vet ./... + - name: Run go generate run: | go generate ./... @@ -52,11 +60,13 @@ jobs: echo "go generate made these changes, please run 'go generate ./...' and include those changes in a commit" exit 1 fi + - name: Run staticcheck run: | go install honnef.co/go/tools/cmd/staticcheck@2024.1.1 staticcheck -debug.version staticcheck ./... 2> staticcheck-stderr + - name: Check staticcheck stderr (this step isn't needed because we are using actions/setup-go@v5 on GitHub hosted runner) run: | if cat staticcheck-stderr | grep "matched no packages" ; then @@ -64,7 +74,6 @@ jobs: echo "Please re-run job." # seize the opportunity to fix the underlying problem: a permissions error in ~/.cache epoch=$(date +%s) - # if any file is reported by find, grep returns true and the mv is done if [ -d ~/.cache ] && find ~/.cache -not -user `id --user` -print0 | grep -qz . ; then echo "~/.cache had broken permissions, moving it away... (cache will be rebuilt with usage)" mv -v ~/.cache ~/.cache-broken-by-root-$epoch @@ -73,29 +82,65 @@ jobs: fi job_go_test: - runs-on: ubuntu-latest + runs-on: [self-hosted, z] env: - LOG_PANIC_ON_INVALIDCHARS: true # check that log lines contains no invalid chars (evidence of format mismatch) + LOG_PANIC_ON_INVALIDCHARS: true # check that log lines contain no invalid chars steps: - uses: actions/checkout@v4 - - uses: benjlevesque/short-sha@v3.0 # sets env.SHA to the first 7 chars of github.sha + + - uses: benjlevesque/short-sha@v3.0 + # sets env.SHA to the first 7 chars of github.sha + - uses: actions/setup-go@v5 with: go-version: '1.23' + + # Step to detect changes in /circuits + - name: Check if /circuits changed + id: check_circuits + run: | + # Decide what to compare against based on event type + if [ "${{ github.event_name }}" = "pull_request" ]; then + # For PRs, compare HEAD with base branch + git fetch origin ${{ github.base_ref }} --depth=1 + DIFF_TARGET="origin/${{ github.base_ref }}" + else + # For pushes, compare HEAD with HEAD^ + DIFF_TARGET="HEAD^" + fi + + echo "Comparing HEAD to $DIFF_TARGET" + if git diff --name-only "$DIFF_TARGET" HEAD | grep '^circuits/'; then + echo "RUN_CIRCUIT_TESTS=true" >> "$GITHUB_ENV" + echo "Found changes under /circuits." + else + echo "RUN_CIRCUIT_TESTS=false" >> "$GITHUB_ENV" + echo "No changes under /circuits." + fi + - run: mkdir -p "$PWD/gocoverage-unit/" + - name: Run Go test -race id: go-test-race # note that -race can easily make the crypto stuff 10x slower # this is further limited to selected branches at the beginning of this file - if: runner.debug || - github.event_name == 'push' && - github.ref != 'refs/heads/dev' + if: github.event_name == 'push' && github.ref != 'refs/heads/release' env: - GORACE: atexit_sleep_ms=10 # the default of 1000 makes every Go package test sleep for 1s; see https://go.dev/issues/20364 - run: go test ./... - -race -timeout=1h -vet=off - -cover -coverpkg=./... -covermode=atomic -args -test.gocoverdir="$PWD/gocoverage-unit/" + GORACE: atexit_sleep_ms=10 # the default of 1000 makes every Go package test sleep for 1s + RUN_CIRCUIT_TESTS: ${{ env.RUN_CIRCUIT_TESTS }} + run: | + go test ./... \ + -race \ + -timeout=1h \ + -vet=off \ + -cover \ + -coverpkg=./... \ + -covermode=atomic \ + -args -test.gocoverdir="$PWD/gocoverage-unit/" + - name: Run Go test if: steps.go-test-race.outcome == 'skipped' # quicker, non-race test in case it's a PR or push to dev - run: go test ./... -timeout=1h + env: + RUN_CIRCUIT_TESTS: ${{ env.RUN_CIRCUIT_TESTS }} + run: go test ./... -timeout=1h diff --git a/circuits/statetransition/circuit_test.go b/circuits/statetransition/circuit_test.go index ec0a067..71c2e5e 100644 --- a/circuits/statetransition/circuit_test.go +++ b/circuits/statetransition/circuit_test.go @@ -24,6 +24,9 @@ import ( ) func TestCircuitCompile(t *testing.T) { + if os.Getenv("RUN_CIRCUIT_TESTS") == "" || os.Getenv("RUN_CIRCUIT_TESTS") == "false" { + t.Skip("skipping circuit tests...") + } // enable log to see nbConstraints logger.Set(zerolog.New(zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: "15:04:05"}).With().Timestamp().Logger()) @@ -34,6 +37,9 @@ func TestCircuitCompile(t *testing.T) { } func TestCircuitProve(t *testing.T) { + if os.Getenv("RUN_CIRCUIT_TESTS") == "" || os.Getenv("RUN_CIRCUIT_TESTS") == "false" { + t.Skip("skipping circuit tests...") + } s := newMockState(t) // first batch @@ -145,6 +151,9 @@ func (circuit CircuitBallots) Define(api frontend.API) error { } func TestCircuitBallotsCompile(t *testing.T) { + if os.Getenv("RUN_CIRCUIT_TESTS") == "" || os.Getenv("RUN_CIRCUIT_TESTS") == "false" { + t.Skip("skipping circuit tests...") + } // enable log to see nbConstraints logger.Set(zerolog.New(zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: "15:04:05"}).With().Timestamp().Logger()) @@ -155,6 +164,9 @@ func TestCircuitBallotsCompile(t *testing.T) { } func TestCircuitBallotsProve(t *testing.T) { + if os.Getenv("RUN_CIRCUIT_TESTS") == "" || os.Getenv("RUN_CIRCUIT_TESTS") == "false" { + t.Skip("skipping circuit tests...") + } s := newMockState(t) if err := s.StartBatch(); err != nil { @@ -192,6 +204,10 @@ func (circuit CircuitMerkleTransitions) Define(api frontend.API) error { } func TestCircuitMerkleTransitionsCompile(t *testing.T) { + if os.Getenv("RUN_CIRCUIT_TESTS") == "" || os.Getenv("RUN_CIRCUIT_TESTS") == "false" { + t.Skip("skipping circuit tests...") + } + // enable log to see nbConstraints logger.Set(zerolog.New(zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: "15:04:05"}).With().Timestamp().Logger()) @@ -202,6 +218,10 @@ func TestCircuitMerkleTransitionsCompile(t *testing.T) { } func TestCircuitMerkleTransitionsProve(t *testing.T) { + if os.Getenv("RUN_CIRCUIT_TESTS") == "" || os.Getenv("RUN_CIRCUIT_TESTS") == "false" { + t.Skip("skipping circuit tests...") + } + s := newMockState(t) if err := s.StartBatch(); err != nil { diff --git a/circuits/test/aggregator/aggregator_test.go b/circuits/test/aggregator/aggregator_test.go index 93b8701..522648b 100644 --- a/circuits/test/aggregator/aggregator_test.go +++ b/circuits/test/aggregator/aggregator_test.go @@ -14,7 +14,7 @@ import ( ) func TestAggregatorCircuit(t *testing.T) { - if os.Getenv("RUN_CIRCUIT_TESTS") == "" { + if os.Getenv("RUN_CIRCUIT_TESTS") == "" || os.Getenv("RUN_CIRCUIT_TESTS") == "false" { t.Skip("skipping circuit tests...") } c := qt.New(t) diff --git a/circuits/test/voteverifier/vote_verifier_test.go b/circuits/test/voteverifier/vote_verifier_test.go index b3e5a07..26ae457 100644 --- a/circuits/test/voteverifier/vote_verifier_test.go +++ b/circuits/test/voteverifier/vote_verifier_test.go @@ -14,7 +14,7 @@ import ( ) func TestVerifySingleVoteCircuit(t *testing.T) { - if os.Getenv("RUN_CIRCUIT_TESTS") == "" { + if os.Getenv("RUN_CIRCUIT_TESTS") == "" || os.Getenv("RUN_CIRCUIT_TESTS") == "false" { t.Skip("skipping circuit tests...") } c := qt.New(t) @@ -39,7 +39,7 @@ func TestVerifySingleVoteCircuit(t *testing.T) { } func TestVerifyMultipleVotesCircuit(t *testing.T) { - if os.Getenv("RUN_CIRCUIT_TESTS") == "" { + if os.Getenv("RUN_CIRCUIT_TESTS") == "" || os.Getenv("RUN_CIRCUIT_TESTS") == "false" { t.Skip("skipping circuit tests...") } c := qt.New(t)