Skip to content

Build and Test

Build and Test #2413

Workflow file for this run

name: Build and Test
on:
push:
branches:
- dev
- stage
- main
- release**
- ci/go-test-race
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
schedule:
- cron: "0 1 * * *" # 02:00 UTC+1
permissions:
contents: read
concurrency:
group: ${{ github.event_name == 'pull_request' && format('{0}-pr-{1}', github.workflow, github.event.pull_request.number) || format('{0}-push-{1}-{2}', github.workflow, github.ref, github.run_id) }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
job_go_checks:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
defaults:
run:
shell: bash
steps:
- name: Debug github context
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 }}
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version-file: go.mod
- name: Run go mod tidy
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 go fix
run: |
go fix ./...
if [[ $(git status --porcelain) ]]; then
git diff
echo
echo "go fix made these changes, please run 'go fix ./...' and include those changes in a commit"
exit 1
fi
- 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 golangci-lint
uses: golangci/golangci-lint-action@v9
with:
version: v2.5
- name: Run deadcode
run: go run golang.org/x/tools/cmd/deadcode@v0.41.0 -test ./... | tee deadcode.out
- name: Delete outdated PR review
uses: aki77/delete-pr-comments-action@v3
if: github.event_name == 'pull_request'
with:
bodyContains: |-
[reviewdog]
[deadcode]
noReply: "true"
- uses: reviewdog/action-setup@v1
if: github.event_name == 'pull_request'
- name: Submit fresh PR review
if: github.event_name == 'pull_request'
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: cat deadcode.out | reviewdog -f=golint -name=deadcode -reporter=github-pr-review -filter-mode=diff_context
job_go_test:
runs-on: [self-hosted]
permissions:
contents: read
issues: write
pull-requests: write
env:
LOG_PANIC_ON_INVALIDCHARS: true
LOG_LEVEL: debug
steps:
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version-file: go.mod
- run: mkdir -p "$PWD/gocoverage-unit/"
- name: Run unit tests
env:
RUN_CIRCUIT_TESTS: false
RUN_INTEGRATION_TESTS: false
run: |
go test -v ./... \
-failfast \
-vet=off \
-cover \
-coverpkg=./... \
-covermode=atomic \
-args -test.gocoverdir="$PWD/gocoverage-unit/"
- name: Store code coverage artifact (unit)
uses: actions/upload-artifact@v7
with:
name: gocoverage-unit
path: gocoverage-unit/
- name: Compile circuit artifacts
run: go run ./cmd/circuit-compile --update-config
- name: Run integration tests
env:
RUN_INTEGRATION_TESTS: true
run: |
set -o pipefail
go test -v ./tests/... \
-failfast \
-vet=off \
-timeout=1h \
| tee integration-test.log
- name: Generate TestInputs.t.sol
run: ./scripts/generate_test_inputs.sh integration-test.log TestInputs.t.sol
- name: Store TestInputs.t.sol
uses: actions/upload-artifact@v7
with:
name: TestInputs.t.sol
path: TestInputs.t.sol
- name: Detect Solidity Verifier changes
if: github.event_name == 'pull_request'
id: solidity_changes
uses: dorny/paths-filter@v4
with:
filters: |
verifiers:
- 'config/*_vkey.sol'
- name: Comment on PR
uses: actions/github-script@v8
if: steps.solidity_changes.outputs.verifiers == 'true' && github.event_name == 'pull_request'
with:
script: |
const name = 'TestInputs.t.sol';
const runId = context.runId || process.env.GITHUB_RUN_ID || 'UNKNOWN_RUN_ID';
const body =
`Verifier contracts changed in this PR, when you pull this at davinci-contracts you'll need an updated \`${name}\`.\n\n` +
`Download the one just generated:\n\n` +
`\`\`\`bash\n` +
`gh run download -R ${context.repo.owner}/${context.repo.repo} ${runId} -n ${name}\n` +
`\`\`\`\n` +
`then:\n\n` +
`\`\`\`bash\n` +
`mv ${name} test/\n` +
`\`\`\`\n`;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body,
});
call-docker-build:
name: Docker
needs: [job_go_checks, job_go_test]
permissions:
contents: read
packages: write
if: github.event.pull_request.draft != true
uses: ./.github/workflows/docker-build.yml
secrets: inherit
with:
image-tag: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || github.ref_name }}
# docker releases are triggered only on push to the selected branches at the beginning of this file
push: ${{ github.event_name == 'push' }}