Skip to content

Commit

Permalink
runt tests on circuits only if there are changes on /circuits directory
Browse files Browse the repository at this point in the history
Signed-off-by: p4u <[email protected]>
  • Loading branch information
p4u committed Jan 3, 2025
1 parent 933db5a commit d99addc
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 15 deletions.
69 changes: 57 additions & 12 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@


name: Build and Test

on:
Expand All @@ -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
Expand All @@ -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/[email protected] -d .)

- name: Run go vet
run: go vet ./...

- name: Run go generate
run: |
go generate ./...
Expand All @@ -52,19 +60,20 @@ 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/[email protected]
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
echo "staticcheck step did nothing, due to https://github.com/vocdoni/vocdoni-node/issues/444"
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
Expand All @@ -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/[email protected] # sets env.SHA to the first 7 chars of github.sha

- uses: benjlevesque/[email protected]
# 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
20 changes: 20 additions & 0 deletions circuits/statetransition/circuit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand All @@ -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
Expand Down Expand Up @@ -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())

Expand All @@ -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 {
Expand Down Expand Up @@ -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())

Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion circuits/test/aggregator/aggregator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions circuits/test/voteverifier/vote_verifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit d99addc

Please sign in to comment.