Skip to content

fix: Allow multiple accounts per (party, org, instrument) - unblock n… #7678

fix: Allow multiple accounts per (party, org, instrument) - unblock n…

fix: Allow multiple accounts per (party, org, instrument) - unblock n… #7678

Workflow file for this run

name: Test
on:
push:
branches: [develop, main]
paths:
- '**.go'
- 'go.mod'
- 'go.sum'
- 'api/proto/**'
- 'buf.yaml'
- 'buf.gen.yaml'
- 'buf.lock'
- 'Makefile'
- '.github/workflows/test.yml'
pull_request:
branches: [develop, main]
paths:
- '**.go'
- 'go.mod'
- 'go.sum'
- 'api/proto/**'
- 'buf.yaml'
- 'buf.gen.yaml'
- 'buf.lock'
- 'Makefile'
- '.github/workflows/test.yml'
permissions:
contents: read
pull-requests: write
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
test:
name: "Tests (shard ${{ matrix.shard_index }})"
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
shard_index: [0, 1, 2]
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: '1.26.2'
cache: true
- name: Set up buf
uses: bufbuild/buf-action@v1
with:
setup_only: true
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Generate protobuf files
run: buf generate
- name: Download dependencies
run: go mod download
- name: Install gotestsum
run: go install gotest.tools/gotestsum@v1.13.0
- name: Run tests with coverage
env:
SKIP_KAFKA_TESTS: "1"
run: |
mkdir -p coverage
# Split packages across 3 shards via round-robin for parallel execution
shard_pkgs=$(go list ./... | awk "NR % 3 == ${{ matrix.shard_index }}")
pkg_count=$(printf '%s\n' "$shard_pkgs" | sed '/^\s*$/d' | wc -l | tr -d ' ')
echo "Shard ${{ matrix.shard_index }}/3: testing $pkg_count packages"
if [ -z "$shard_pkgs" ] || [ "$pkg_count" -eq 0 ]; then
echo "No packages in this shard, skipping"
exit 0
fi
# Use -short flag to skip timing-sensitive tests in CI
gotestsum --format testdox \
--junitfile test-results.xml \
--jsonfile test-results.json \
-- -short -race -coverprofile=coverage/coverage.out -covermode=atomic $shard_pkgs
- name: Upload coverage artifact
uses: actions/upload-artifact@v7
if: always()
with:
name: coverage-shard-${{ matrix.shard_index }}
path: coverage/coverage.out
if-no-files-found: ignore
- name: Upload test results
uses: actions/upload-artifact@v7
if: always()
with:
name: test-results-shard-${{ matrix.shard_index }}
path: |
test-results.xml
test-results.json
if-no-files-found: ignore
- name: Test summary
uses: test-summary/action@v2
if: ${{ always() && hashFiles('test-results.xml') != '' }}
with:
paths: test-results.xml
- name: Annotate failures
if: failure()
run: |
jq -r 'select(.Action == "fail" and .Test != null) | "::error file=\(.Package | sub("github.com/meridianhub/meridian/"; "")),line=1::\(.Test) failed"' test-results.json | sort -u || true
coverage:
name: Coverage Report
needs: test
runs-on: ubuntu-latest
timeout-minutes: 15
if: always() && !cancelled()
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: '1.26.2'
cache: true
- name: Set up buf
uses: bufbuild/buf-action@v1
with:
setup_only: true
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Generate protobuf files
run: buf generate
- name: Download dependencies
run: go mod download
- name: Download coverage artifacts
uses: actions/download-artifact@v8
with:
pattern: coverage-shard-*
path: coverage-shards
- name: Install gocovmerge
run: go install github.com/wadey/gocovmerge@b5bfa59
- name: Merge coverage from shards
run: |
mkdir -p coverage
shopt -s nullglob
cov_files=(coverage-shards/coverage-shard-*/coverage.out)
if [ ${#cov_files[@]} -eq 0 ]; then
echo "No coverage files found, creating empty profile"
echo "mode: atomic" > coverage/coverage.out
cp coverage/coverage.out coverage/coverage-filtered.out
exit 0
fi
gocovmerge "${cov_files[@]}" > coverage/coverage.out
echo "Filtering excluded paths from coverage (derived from codecov.yml)..."
exclude_pattern=$(./scripts/codecov-exclude-pattern.sh) || exclude_pattern=""
if [ -n "$exclude_pattern" ]; then
grep -v -E "$exclude_pattern" coverage/coverage.out > coverage/coverage-filtered.out || true
else
cp coverage/coverage.out coverage/coverage-filtered.out
fi
- name: Generate coverage report
run: go tool cover -html=coverage/coverage.out -o coverage/coverage.html
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v6
with:
files: ./coverage/coverage-filtered.out
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: Upload coverage artifacts
uses: actions/upload-artifact@v7
with:
name: coverage-report
path: coverage/
retention-days: 30
- name: Check test coverage threshold
run: |
coverage=$(go tool cover -func=coverage/coverage-filtered.out | grep total | awk '{print $3}' | sed 's/%//')
echo "Coverage (excluding codecov.yml ignore paths): ${coverage}%"
if (( $(echo "$coverage < 80.0" | bc -l) )); then
echo "❌ Coverage ${coverage}% is below 80% threshold"
exit 1
fi
echo "✅ Coverage ${coverage}% meets threshold"
# Gate job preserves the "Run Tests" check name for required status checks
test-gate:
name: Run Tests
needs: [test, coverage]
runs-on: ubuntu-latest
if: always()
steps:
- name: Check results
run: |
if [ "${{ needs.test.result }}" != "success" ]; then
echo "Test shards failed"
exit 1
fi
if [ "${{ needs.coverage.result }}" != "success" ]; then
echo "Coverage check failed"
exit 1
fi
echo "All tests and coverage checks passed"