Skip to content

Store failed operations along with the specific result codes #1838

Store failed operations along with the specific result codes

Store failed operations along with the specific result codes #1838

Workflow file for this run

name: Go
on:
pull_request:
push:
branches:
- main
paths-ignore:
- 'internal/serve/graphql/generated/**'
workflow_call: # allows this workflow to be called from another workflow
jobs:
check:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: "1.24.2"
cache: true
cache-dependency-path: go.sum
- name: ./gomod.sh
run: ./gomod.sh
- name: Run `golangci-lint@v2.1.2`
run: |
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.1.2
golangci-lint run
- name: Run `shadow@v0.31.0`
run: |
go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow@v0.31.0
shadow ./... | { grep -v "generated.go" || true; }
- name: Run `exhaustive@v0.12.0`
run: |
go install github.com/nishanths/exhaustive/cmd/exhaustive@v0.12.0
exhaustive -default-signifies-exhaustive ./...
- name: Run `deadcode@v0.31.0`
run: |
go install golang.org/x/tools/cmd/deadcode@v0.31.0
output=$(deadcode -test ./... | { grep -v "UnmarshalUInt32" || true; } | { grep -v "isBalance" || true; })
if [[ -n "$output" ]]; then
echo "🚨 Deadcode found:"
echo "$output"
exit 1
else
echo "βœ… No deadcode found"
fi
- name: Run `goimports@v0.31.0`
run: |
go install golang.org/x/tools/cmd/goimports@v0.31.0
# Find all .go files excluding paths containing 'mock' and run goimports
non_compliant_files=$(find . -type f -name "*.go" ! -path "*mock*" | xargs goimports -local "github.com/stellar/wallet-backend" -l)
if [ -n "$non_compliant_files" ]; then
echo "🚨 The following files are not compliant with goimports:"
echo "$non_compliant_files"
exit 1
else
echo "βœ… All files are compliant with goimports."
fi
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: "1.24.2"
cache: true
cache-dependency-path: go.sum
- name: Build Project
run: go build ./...
test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:12-alpine
env:
POSTGRES_USER: postgres
POSTGRES_DB: postgres
POSTGRES_PASSWORD: postgres
PGHOST: localhost
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
env:
PGHOST: localhost
PGPORT: 5432
PGUSER: postgres
PGPASSWORD: postgres
PGDATABASE: postgres
DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: "1.24.2"
cache: true
cache-dependency-path: go.sum
- name: Install gotestsum@v1.11.0
run: go install gotest.tools/gotestsum@v1.11.0
- name: Run tests
run: gotestsum --format-hide-empty-pkg --format pkgname-and-test-fails -- -coverprofile=c.out ./... -timeout 3m -coverpkg ./...
- name: Validate Test Coverage Threshold
env:
TESTCOVERAGE_THRESHOLD: 65 # percentage
run: |
echo "Quality Gate: Checking if test coverage is above threshold..."
echo "Threshold: $TESTCOVERAGE_THRESHOLD%"
totalCoverage=`./scripts/exclude_from_coverage.sh && go tool cover -func=c.out | grep total: | grep -Eo '[0-9]+\.[0-9]+'`
echo "Test Coverage: $totalCoverage%"
echo "-------------------------"
if (( $(echo "$totalCoverage $TESTCOVERAGE_THRESHOLD" | awk '{print ($1 >= $2)}') )); then
echo " $totalCoverage% > $TESTCOVERAGE_THRESHOLD%"
echo "Current test coverage is above threshold πŸŽ‰πŸŽ‰πŸŽ‰! Please keep up the good work!"
else
echo " $totalCoverage% < $TESTCOVERAGE_THRESHOLD%"
echo "🚨 Current test coverage is below threshold 😱! Please add more unit tests or adjust threshold to a lower value."
echo "Failed 😭"
exit 1
fi
integration-test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.24.2'
- name: Get short commit hash
id: git
run: echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build integration test image with cache
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
tags: wallet-backend:integration-test-${{ steps.git.outputs.short_sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
push: false
load: true
build-args: |
GIT_COMMIT=${{ steps.git.outputs.short_sha }}
- name: Run Integration Tests
run: ENABLE_INTEGRATION_TESTS=true go test -v ./internal/integrationtests/... -timeout 30m
shell: bash
complete:
if: always()
needs: [check, build, test]
runs-on: ubuntu-latest
steps:
- if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
run: exit 1