Skip to content

Commit

Permalink
add github workflow with linter and tests
Browse files Browse the repository at this point in the history
Signed-off-by: p4u <pau@dabax.net>
  • Loading branch information
p4u committed Dec 12, 2024
1 parent 563145e commit 106dff6
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 10 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
101 changes: 101 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: Build and Test

on:
push:
branches:
- dev
- stage
- main
- release**
pull_request:

jobs:
job_go_checks:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Print github env vars
run: |
echo github.event_name: ${{ github.event_name }}
echo github.ref: ${{ github.ref }}
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
if [[ $(git status --porcelain) ]]; then
git diff
echo
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 ./...
if [[ $(git status --porcelain) ]]; then
git diff
echo
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
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
fi
exit 2
fi
job_go_test:
runs-on: ubuntu-latest
env:
LOG_PANIC_ON_INVALIDCHARS: true # check that log lines contains no invalid chars (evidence of format mismatch)
steps:
- uses: actions/checkout@v4
- 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'
- 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'
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=15m -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 ./...
8 changes: 4 additions & 4 deletions crypto/ecc/bjj_iden3/babyjubjub.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ func (g *BJJ) Neg(a curve.Point) {
proj := g.inner.Projective()
proj.X = proj.X.Neg(proj.X)
g.inner.X = g.inner.X.Set(proj.Affine().X)
//g.inner.X = g.inner.X.Neg(g.inner.X) // Negate the x-coordinate
//g.inner.X = g.inner.X.Mod(g.inner.X, constants.Q)
// g.inner.X = g.inner.X.Neg(g.inner.X) // Negate the x-coordinate
// g.inner.X = g.inner.X.Mod(g.inner.X, constants.Q)
}

func (g *BJJ) SetZero() {
Expand All @@ -91,8 +91,8 @@ func (g *BJJ) SetGenerator() {
}

func (g *BJJ) String() string {
//bytes := g.Marshal()
//return fmt.Sprintf("%x", bytes)
// bytes := g.Marshal()
// return fmt.Sprintf("%x", bytes)
return fmt.Sprintf("%s,%s", g.inner.X.String(), g.inner.Y.String())
}

Expand Down
4 changes: 2 additions & 2 deletions crypto/elgamal/dkg/dkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ func (p *Participant) GenerateSecretPolynomial() {
p.PublicCoeffs = append(p.PublicCoeffs, commitment)

// Log the secret coefficient and commitment
//log.Printf("Participant %d: SecretCoeff[%d] = %s", p.ID, i, coeff.String())
//log.Printf("Participant %d: PublicCoeff[%d] = %s", p.ID, i, commitment.String())
// log.Printf("Participant %d: SecretCoeff[%d] = %s", p.ID, i, coeff.String())
// log.Printf("Participant %d: PublicCoeff[%d] = %s", p.ID, i, commitment.String())
}
}

Expand Down
1 change: 0 additions & 1 deletion crypto/elgamal/dkg/secies/secies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ func TestDecryptionWithMalformedCiphertext(t *testing.T) {
if recoveredMessage.Cmp(message) == 0 {
t.Fatal("Decryption should have failed with corrupted RBytes, but it succeeded")
}

}

func TestEncryptDecryptWithMaxMessage(t *testing.T) {
Expand Down
3 changes: 0 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,13 @@ require (
github.com/cockroachdb/pebble v1.1.2 // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/cometbft/cometbft v1.0.0-alpha.1 // indirect
github.com/consensys/bavard v0.1.24 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dchest/blake512 v1.0.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/getsentry/sentry-go v0.27.0 // indirect
github.com/glendc/go-external-ip v0.1.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/go-cmp v0.6.0 // indirect
Expand Down

0 comments on commit 106dff6

Please sign in to comment.