Skip to content

Commit 0de7d1d

Browse files
authored
Merge pull request #321 from smvv/try-event-path
Compute job matrix distribution using extbuild matrix
2 parents fccd748 + 99e28ba commit 0de7d1d

File tree

15 files changed

+939
-2
lines changed

15 files changed

+939
-2
lines changed

.github/workflows/_extension_distribution.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,72 @@ jobs:
197197
ref: ${{ inputs.ci_tools_version }}
198198
repository: ${{ inputs.override_ci_tools_repository }}
199199

200+
- name: Setup Go
201+
uses: actions/setup-go@v5
202+
with:
203+
go-version-file: extension-ci-tools/scripts/extbuild/go.mod
204+
cache: true
205+
cache-dependency-path: extension-ci-tools/scripts/extbuild/go.sum
206+
207+
- name: Dump event path file
208+
run: |
209+
echo "$GITHUB_EVENT_PATH"
210+
cat "$GITHUB_EVENT_PATH"
211+
212+
- name: Compute extension build matrix
213+
continue-on-error: true
214+
run: |
215+
make -C extension-ci-tools/scripts/extbuild test build -sj4
216+
mkdir -p build
217+
extension-ci-tools/scripts/extbuild/build/extbuild matrix \
218+
--input extension-ci-tools/config/distribution_matrix.json \
219+
--exclude "${{ inputs.exclude_archs }}" \
220+
--opt-in "${{ inputs.opt_in_archs }}" \
221+
--reduced-ci-mode "${{ inputs.reduced_ci_mode }}" \
222+
--out build/extbuild_matrix.env
223+
echo "extbuild matrix output:"
224+
cat build/extbuild_matrix.env
225+
226+
- name: Compare extbuild vs python matrices
227+
continue-on-error: true
228+
run: |
229+
mkdir -p build/python_ref build/extbuild_ref
230+
231+
python3 extension-ci-tools/scripts/modify_distribution_matrix.py --input extension-ci-tools/config/distribution_matrix.json --select_os linux --output build/python_ref/linux_matrix.json --exclude "${{ inputs.exclude_archs }}" --opt_in "${{ inputs.opt_in_archs }}" --pretty --reduced_ci_mode ${{ inputs.reduced_ci_mode }}
232+
python3 extension-ci-tools/scripts/modify_distribution_matrix.py --input extension-ci-tools/config/distribution_matrix.json --select_os osx --output build/python_ref/osx_matrix.json --exclude "${{ inputs.exclude_archs }}" --opt_in "${{ inputs.opt_in_archs }}" --pretty --reduced_ci_mode ${{ inputs.reduced_ci_mode }}
233+
python3 extension-ci-tools/scripts/modify_distribution_matrix.py --input extension-ci-tools/config/distribution_matrix.json --select_os windows --output build/python_ref/windows_matrix.json --exclude "${{ inputs.exclude_archs }}" --opt_in "${{ inputs.opt_in_archs }}" --pretty --reduced_ci_mode ${{ inputs.reduced_ci_mode }}
234+
python3 extension-ci-tools/scripts/modify_distribution_matrix.py --input extension-ci-tools/config/distribution_matrix.json --select_os wasm --output build/python_ref/wasm_matrix.json --exclude "${{ inputs.exclude_archs }}" --opt_in "${{ inputs.opt_in_archs }}" --pretty --reduced_ci_mode ${{ inputs.reduced_ci_mode }}
235+
236+
for platform in linux osx windows wasm; do
237+
grep "^${platform}_matrix=" build/extbuild_matrix.env | sed "s/^${platform}_matrix=//" > "build/extbuild_ref/${platform}_matrix.json"
238+
done
239+
240+
has_diff=0
241+
for platform in linux osx windows wasm; do
242+
echo "=== ${platform} matrix diff (extbuild vs python) ==="
243+
if ! diff -u \
244+
<(jq -S 'walk(if type == "object" then del(.opt_in, .run_in_reduced_ci_mode) else . end)' "build/extbuild_ref/${platform}_matrix.json") \
245+
<(jq -S 'walk(if type == "object" then del(.opt_in, .run_in_reduced_ci_mode) else . end)' "build/python_ref/${platform}_matrix.json"); then
246+
has_diff=1
247+
else
248+
echo "No differences."
249+
fi
250+
echo
251+
done
252+
253+
if [ "$has_diff" -ne 0 ]; then
254+
echo "Matrix differences detected."
255+
echo "::warning title=Matrix differences detected::extbuild and python matrix outputs differ. See diff logs in this step."
256+
{
257+
echo "### Matrix differences detected"
258+
echo "extbuild and python matrix outputs differ. See the diff logs in this step."
259+
} >> "$GITHUB_STEP_SUMMARY"
260+
exit 1
261+
fi
262+
200263
- id: parse-matrices
201264
run: |
265+
rm -rf build
202266
mkdir build
203267
python3 ${{ inputs.matrix_parse_script }} --input extension-ci-tools/config/distribution_matrix.json --select_os linux --output build/linux_matrix.json --exclude "${{ inputs.exclude_archs }}" --opt_in "${{ inputs.opt_in_archs }}" --pretty --reduced_ci_mode ${{ inputs.reduced_ci_mode }}
204268
python3 ${{ inputs.matrix_parse_script }} --input extension-ci-tools/config/distribution_matrix.json --select_os osx --output build/osx_matrix.json --exclude "${{ inputs.exclude_archs }}" --opt_in "${{ inputs.opt_in_archs }}" --pretty --reduced_ci_mode ${{ inputs.reduced_ci_mode }}

scripts/extbuild/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build/
2+
coverage.out

scripts/extbuild/Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
GO_TEST_FLAGS ?= -coverprofile=coverage.out -timeout 2s
2+
3+
.PHONY: test cov build clean
4+
5+
test:
6+
go test ${GO_TEST_FLAGS} ./...
7+
8+
cov: test
9+
go tool cover -html=coverage.out
10+
11+
build:
12+
mkdir -p build
13+
go build -o build/extbuild ./cmd/extbuild
14+
15+
clean:
16+
rm -rf build
17+
18+
.PHONY: tidy
19+
20+
tidy:
21+
go mod tidy

scripts/extbuild/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Extbuild
2+
3+
A small CLI tool for iterating quickly on DuckDB extension CI pipelines.
4+
5+
For now, it can compute the job matrix. Later, the tool can be extended to
6+
generate the command list used.
7+
8+
# Development
9+
10+
## Install dependencies
11+
12+
```shell
13+
brew install go
14+
```
15+
16+
## Build extbuild
17+
18+
Build and test `extbuild`:
19+
20+
```shell
21+
make build test -sj4
22+
```
23+
24+
or from the repo root directory:
25+
26+
```shell
27+
make -C scripts/extbuild build test -sj4
28+
```
29+
30+
## How to use
31+
32+
The target `build` creates `./scripts/extbuild/build/extbuild`.
33+
34+
See `./scripts/extbuild/build/extbuild --help` for local usage and subcommands.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
)
7+
8+
func main() {
9+
if err := newRootCommand().Execute(); err != nil {
10+
fmt.Fprintln(os.Stderr, err)
11+
os.Exit(1)
12+
}
13+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/duckdb/extension-ci-tools/internal/distmatrix"
8+
"github.com/spf13/cobra"
9+
)
10+
11+
func newMatrixCommand() *cobra.Command {
12+
var (
13+
inputPath string
14+
platformsRaw string
15+
archsRaw string
16+
excludeRaw string
17+
optInRaw string
18+
reducedCIMode string
19+
outPath string
20+
)
21+
22+
cmd := &cobra.Command{
23+
Use: "matrix",
24+
Short: "Compute distribution matrices and emit GitHub output lines",
25+
RunE: func(cmd *cobra.Command, _ []string) error {
26+
data, err := os.ReadFile(inputPath)
27+
if err != nil {
28+
return fmt.Errorf("read input matrix %q: %w", inputPath, err)
29+
}
30+
matrix, err := distmatrix.ParseMatrixFile(data)
31+
if err != nil {
32+
return fmt.Errorf("parse input matrix %q: %w", inputPath, err)
33+
}
34+
35+
result, err := distmatrix.ComputePlatformMatrices(matrix, distmatrix.ComputeOptions{
36+
Platform: platformsRaw,
37+
Arch: archsRaw,
38+
Exclude: excludeRaw,
39+
OptIn: optInRaw,
40+
ReducedCIMode: distmatrix.ReducedCIMode(reducedCIMode),
41+
})
42+
if err != nil {
43+
return fmt.Errorf("compute platform matrices: %w", err)
44+
}
45+
46+
content, err := distmatrix.RenderGitHubOutputLines(result, distmatrix.MachineReadable)
47+
if err != nil {
48+
return fmt.Errorf("render GitHub output lines: %w", err)
49+
}
50+
readable, err := distmatrix.RenderGitHubOutputLines(result, distmatrix.HumanReadable)
51+
if err != nil {
52+
return fmt.Errorf("render readable output: %w", err)
53+
}
54+
55+
if outPath != "" {
56+
if err := os.WriteFile(outPath, []byte(content), 0o644); err != nil {
57+
return fmt.Errorf("write output file %q: %w", outPath, err)
58+
}
59+
}
60+
61+
_, _ = fmt.Fprint(cmd.OutOrStdout(), readable)
62+
63+
return nil
64+
},
65+
}
66+
67+
cmd.Flags().StringVar(&inputPath, "input", "config/distribution_matrix.json", "Input distribution matrix JSON file")
68+
cmd.Flags().StringVar(&platformsRaw, "platform", "", "Comma-separated list of platforms")
69+
cmd.Flags().StringVar(&archsRaw, "arch", "", "Comma-separated list of arch tokens (amd64;arm64)")
70+
cmd.Flags().StringVar(&excludeRaw, "exclude", "", "Comma-separated list of duckdb_arch values to exclude")
71+
cmd.Flags().StringVar(&optInRaw, "opt-in", "", "Comma-separated list of opt-in duckdb_arch values")
72+
cmd.Flags().StringVar(&reducedCIMode, "reduced-ci-mode", "", "Reduced CI mode: auto|enabled|disabled")
73+
cmd.Flags().StringVar(&outPath, "out", "", "Path to write GitHub output lines")
74+
75+
return cmd
76+
}

0 commit comments

Comments
 (0)