Repository navigation
docs(gin-redis, sse-redis): Redis mocks need Keploy Enterprise #522
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build Go Sample Projects | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| types: [opened, edited, synchronize, reopened] | |
| jobs: | |
| # keploy's CI clones this repo at main and builds these Dockerfiles: one Go | |
| # module fetch made only once there fails its lane on a reset download. | |
| dockerfile-fetch: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Every Go module fetch in a Dockerfile runs in a retry loop | |
| run: python3 .github/scripts/check_go_fetch_retried.py --self-test | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| # 'stable' on purpose, and deliberately NOT the pinned version used | |
| # by golangci-lint.yml. Building on the current Go is this job's | |
| # whole point: it is the signal that these samples still compile | |
| # against the latest release. The lint job pins instead, because a | |
| # linter has to understand the compiler's export-data format and a | |
| # floating toolchain there silently outruns it. Every sample's | |
| # go.mod is <= the lint pin, so the lint toolchain can still build | |
| # all of them. | |
| go-version: 'stable' | |
| - name: Build projects | |
| run: | | |
| #!/bin/bash | |
| cd /home/runner/work/samples-go/samples-go | |
| for dir in */; do | |
| dir_name="${dir%/}" | |
| if [ -d "$dir" ] && [ -f "${dir}go.mod" ]; then | |
| echo "Building project in $dir" | |
| # Change to the project directory | |
| cd "$dir" || continue | |
| # Fetch what the build needs first, retried: proxy.golang.org | |
| # now and then resets a download mid-transfer, and one reset | |
| # would fail this whole job. `go list -deps` loads exactly the | |
| # packages `go build` does, so it fetches nothing more. | |
| n=0 | |
| until go list -deps ./... >/dev/null; do | |
| n=$((n+1)) | |
| if [ "$n" -ge 5 ]; then | |
| echo "go list -deps failed in $dir after $n attempts" >&2 | |
| exit 1 | |
| fi | |
| echo "go list -deps failed in $dir (attempt $n), retrying in $((n*5))s" | |
| sleep $((n*5)) | |
| done | |
| # Build the project (supports modules with multiple commands under ./cmd/*) | |
| if go build ./...; then | |
| echo "Successfully built $dir" | |
| else | |
| echo "Failed to build $dir" >&2 | |
| exit 1 | |
| fi | |
| # The SQS sample's builds that speak SQS's Query protocol, one | |
| # per Go SDK family (sqs-samples/README.md, 4.2). Each needs | |
| # modules the default build does not (aws-sdk-go v1; the | |
| # aws-sdk-go-v2 versions go.v2query.mod pins), fetched first | |
| # with the same retry. | |
| if [ "$dir_name" = sqs-samples ]; then | |
| for flag in -tags=sqs_sdk_v1 -modfile=go.v2query.mod; do | |
| n=0 | |
| until go list -deps "$flag" ./... >/dev/null; do | |
| n=$((n+1)) | |
| if [ "$n" -ge 5 ]; then | |
| echo "go list -deps $flag failed in $dir after $n attempts" >&2 | |
| exit 1 | |
| fi | |
| echo "go list -deps $flag failed in $dir (attempt $n), retrying in $((n*5))s" | |
| sleep $((n*5)) | |
| done | |
| done | |
| if go build -tags sqs_sdk_v1 ./... && go build -modfile=go.v2query.mod ./...; then | |
| echo "Successfully built the Query-protocol builds of $dir" | |
| else | |
| echo "Failed to build the Query-protocol builds of $dir" >&2 | |
| exit 1 | |
| fi | |
| fi | |
| # Return to the base directory | |
| cd .. | |
| else | |
| echo "Skipping $dir, no go.mod file found." | |
| fi | |
| done | |
| echo "All projects processed." |