Skip to content

Commit 0e958d9

Browse files
nogatesclaude
andauthored
Explore performance improvements in golang generation pipeline (#3979)
* Move staticcheck to its own CI job using dominikh/staticcheck-action Extract staticcheck from run-tests.sh into a dedicated parallel job in reusable-go-test.yml, using dominikh/staticcheck-action@v1 for better caching. Move run-tests.sh to scripts/ for consistency. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Split example builds into parallel matrix jobs to cut CI time ~60% Replace the single check-examples.sh job (~7min for 1490 examples) with a two-stage workflow: scripts/prepare-examples.sh counts examples and emits a dynamic matrix, then scripts/build-examples-group.sh runs in parallel across 4 groups (~400 examples each, ~2.5min per job). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent a34e4f8 commit 0e958d9

7 files changed

Lines changed: 110 additions & 26 deletions

File tree

.github/workflows/reusable-examples.yml

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,26 @@ on:
1010
default: ''
1111

1212
jobs:
13-
examples:
13+
prepare:
1414
runs-on: ubuntu-latest
15+
outputs:
16+
matrix: ${{ steps.split.outputs.matrix }}
17+
steps:
18+
- uses: actions/checkout@v3
19+
with:
20+
repository: DataDog/datadog-api-client-go
21+
ref: ${{ inputs.target-branch || github.ref }}
22+
- name: Compute example groups
23+
id: split
24+
run: ./scripts/prepare-examples.sh
25+
shell: bash
26+
27+
build:
28+
needs: prepare
29+
runs-on: ubuntu-latest
30+
strategy:
31+
matrix:
32+
group: ${{ fromJson(needs.prepare.outputs.matrix) }}
1533
steps:
1634
- uses: actions/checkout@v3
1735
with:
@@ -23,6 +41,6 @@ jobs:
2341
go-version: 1.22.x
2442
cache: true
2543
cache-dependency-path: tests/go.sum
26-
- name: Check examples
27-
run: ./check-examples.sh
28-
shell: bash
44+
- name: Build examples (group ${{ matrix.group }})
45+
run: ./scripts/build-examples-group.sh ${{ matrix.group }}
46+
shell: bash

.github/workflows/reusable-go-test.yml

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,37 @@ on:
2121
required: false
2222

2323
jobs:
24+
staticcheck:
25+
strategy:
26+
matrix:
27+
go-version: ["1.22.x", "1.23.x"]
28+
go-build-tags: ["--tags=goccy_gojson", ""]
29+
platform: ["ubuntu-latest"]
30+
runs-on: ${{ matrix.platform }}
31+
steps:
32+
- name: Checkout code
33+
uses: actions/checkout@v3
34+
with:
35+
repository: DataDog/datadog-api-client-go
36+
ref: ${{ inputs.target-branch || github.ref }}
37+
- name: Install Go
38+
uses: actions/setup-go@v4
39+
with:
40+
go-version: ${{ matrix.go-version }}
41+
cache: true
42+
cache-dependency-path: tests/go.sum
43+
- name: Staticcheck (api module)
44+
uses: dominikh/staticcheck-action@v1
45+
with:
46+
checks: "-SA1009"
47+
working-directory: api
48+
cache-key: ${{ matrix.go }}
49+
- name: Staticcheck (tests module)
50+
uses: dominikh/staticcheck-action@v1
51+
with:
52+
checks: "inherit,-SA1019"
53+
cache-key: ${{ matrix.go }}
54+
working-directory: tests
2455
test:
2556
strategy:
2657
matrix:
@@ -41,7 +72,7 @@ jobs:
4172
cache: true
4273
cache-dependency-path: tests/go.sum
4374
- name: Test
44-
run: ./run-tests.sh
75+
run: ./scripts/run-tests.sh
4576
env:
4677
TESTARGS: ${{ matrix.go-build-tags }}
4778

.github/workflows/reusable-integration-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ jobs:
111111
cache-dependency-path: tests/go.sum
112112
- name: Run integration tests
113113
shell: bash
114-
run: ./run-tests.sh
114+
run: ./scripts/run-tests.sh
115115
env:
116116
CI: "true"
117117
DD_AGENT_HOST: localhost

check-examples.sh

Lines changed: 0 additions & 17 deletions
This file was deleted.

scripts/build-examples-group.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
GROUP=${1:?usage: build-examples-group.sh <group-number>}
5+
EXAMPLES_PER_GROUP=${EXAMPLES_PER_GROUP:-400}
6+
7+
ALL_EXAMPLES=()
8+
while IFS= read -r f; do ALL_EXAMPLES+=("$f"); done < <(find examples -mindepth 3 -maxdepth 3 -name "*.go" | sort)
9+
TOTAL=${#ALL_EXAMPLES[@]}
10+
11+
START=$(( (GROUP - 1) * EXAMPLES_PER_GROUP ))
12+
SLICE=("${ALL_EXAMPLES[@]:$START:$EXAMPLES_PER_GROUP}")
13+
14+
echo "Building group $GROUP: examples $((START + 1))-$((START + ${#SLICE[@]})) of $TOTAL"
15+
16+
for f in "${SLICE[@]}"; do
17+
df="build/$(dirname "$f")/$(basename "$f" .go)"
18+
mkdir -p "$df"
19+
cp "$f" "$df/main.go"
20+
done
21+
22+
if go build -o /dev/null -ldflags "-s -w -linkmode internal" ./build/examples/*/*/*; then
23+
echo "Examples are buildable"
24+
else
25+
echo "Failed to build examples"
26+
exit 1
27+
fi

scripts/prepare-examples.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
EXAMPLES_PER_GROUP=${EXAMPLES_PER_GROUP:-400}
5+
6+
ALL_EXAMPLES=()
7+
while IFS= read -r f; do ALL_EXAMPLES+=("$f"); done < <(find examples -mindepth 3 -maxdepth 3 -name "*.go" | sort)
8+
TOTAL=${#ALL_EXAMPLES[@]}
9+
NUM_GROUPS=$(( (TOTAL + EXAMPLES_PER_GROUP - 1) / EXAMPLES_PER_GROUP ))
10+
11+
echo "Total examples: $TOTAL, groups: $NUM_GROUPS (max $EXAMPLES_PER_GROUP per group)"
12+
13+
MATRIX_JSON="["
14+
for i in $(seq 1 "$NUM_GROUPS"); do
15+
[ "$i" -gt 1 ] && MATRIX_JSON+=","
16+
MATRIX_JSON+="$i"
17+
done
18+
MATRIX_JSON+="]"
19+
20+
echo "matrix=$MATRIX_JSON"
21+
if [ -n "${GITHUB_OUTPUT:-}" ]; then
22+
echo "matrix=$MATRIX_JSON" >> "$GITHUB_OUTPUT"
23+
fi

run-tests.sh renamed to scripts/run-tests.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,26 @@ fi
2323
# make sure the below installed dependencies don't get added to go.mod/go.sum
2424
# unfortunately there's no better way to fix this than change directory
2525
# this might get solved in Go 1.14: https://github.com/golang/go/issues/30515
26+
echo "Installing gotestsum"
2627
cd "$(mktemp -d)"
27-
GO111MODULE=on go install honnef.co/go/tools/cmd/staticcheck@latest
2828
GO111MODULE=on go install gotest.tools/gotestsum@latest
2929
cd -
3030

31-
staticcheck -checks -SA1009 ./api/...
31+
echo "Running mod tidy and cleanup test cache"
3232
go mod tidy
3333
go clean -testcache
3434

3535
# Run the same in tests submodule
3636
cd tests
37-
staticcheck -checks inherit,-SA1019 ./...
37+
echo "Running mod tidy and cleanup test cache in test module"
3838
go mod tidy
3939
go clean -testcache
4040

4141
if [ "$RECORD" == "none" ]; then
42+
echo "Running with no RECORD"
4243
gotestsum --rerun-fails=1 --format short-verbose --packages ./... -- -timeout=20m $TESTARGS
4344
else
45+
echo "Running with RECORD"
4446
gotestsum --format short-verbose --packages ./... -- $TESTARGS
4547
fi
4648

0 commit comments

Comments
 (0)