diff --git a/adbc_drivers_dev/generate.py b/adbc_drivers_dev/generate.py index 75758ef..d2e5467 100644 --- a/adbc_drivers_dev/generate.py +++ b/adbc_drivers_dev/generate.py @@ -64,6 +64,12 @@ class LangBuildConfig(BaseModel): description="A list of additional arguments to pass to adbc-make.", ) + lang_tools: list[str] = Field( + default_factory=list, + alias="lang-tools", + description="Install tools for these languages to use in the build.", + ) + class LangConfig(BaseModel): model_config = { diff --git a/adbc_drivers_dev/make.py b/adbc_drivers_dev/make.py index dff7432..880e22e 100644 --- a/adbc_drivers_dev/make.py +++ b/adbc_drivers_dev/make.py @@ -152,11 +152,19 @@ def detect_version( raise ValueError(f"{driver_root} is not in a git repository") repo_root = repo_root.parent - prefix = str(driver_root.relative_to(repo_root)) - if prefix == ".": + is_script_build = not any( + (driver_root / name).is_file() for name in ("Cargo.toml", "go.mod") + ) + if is_script_build: + # We're going to assume custom builds like this are effectively the + # entire repo, and use just plain tags "v1.0.0". prefix = "v" else: - prefix = f"{prefix}/v" + prefix = str(driver_root.relative_to(repo_root)) + if prefix == ".": + prefix = "v" + else: + prefix = f"{prefix}/v" tags = check_output( [ diff --git a/adbc_drivers_dev/package.py b/adbc_drivers_dev/package.py index 0ab6408..59f8a8c 100644 --- a/adbc_drivers_dev/package.py +++ b/adbc_drivers_dev/package.py @@ -22,6 +22,7 @@ import enum import io import itertools +import os import subprocess import sys import tarfile @@ -151,6 +152,33 @@ def generate_rust_license(license_template: Path) -> str: return license_data +def generate_custom_license(license_script: Path) -> str: + import platform + + args = [str(license_script.absolute())] + if ( + platform.system() == "Windows" + and os.environ.get("CI", "").lower().strip() == "true" + ): + # Force use of Git Bash on GitHub Actions + args = [r"C:\Program Files\Git\bin\bash.EXE", *args] + license_proc = subprocess.run( + args, + cwd=license_script.parent.parent.parent, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + ) + if license_proc.returncode != 0: + print("Failed to generate license", file=sys.stderr) + print("Stdout:", file=sys.stderr) + print(license_proc.stdout, file=sys.stderr) + print("Stderr:", file=sys.stderr) + print(license_proc.stderr, file=sys.stderr) + license_proc.check_returncode() + license_data = license_proc.stdout + return license_data + + def generate_packages( manifest: dict[str, typing.Any], driver_name: str, @@ -272,8 +300,11 @@ def main(): if not notice_file.is_file(): raise RuntimeError(f"NOTICE.txt ({notice_file}) is missing") + license_script = args.manifest_template.parent / "ci/scripts/generate_license.sh" license_template = args.manifest_template.with_name("license.tpl") - if license_template.is_file(): + if license_script.is_file(): + license_data = generate_custom_license(license_script) + elif license_template.is_file(): if (gomod := args.manifest_template.with_name("go.mod")).is_file(): license_data = generate_go_license(license_template, gomod) elif args.manifest_template.with_name("Cargo.toml").is_file(): diff --git a/adbc_drivers_dev/templates/test.yaml b/adbc_drivers_dev/templates/test.yaml index 1c2fd9f..cfa04d7 100644 --- a/adbc_drivers_dev/templates/test.yaml +++ b/adbc_drivers_dev/templates/test.yaml @@ -139,13 +139,14 @@ jobs: submodules: 'recursive' <% endif %> -<% if lang == "go" %> +<% if "go" in lang_tools %> - uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0 with: cache-dependency-path: go/go.sum check-latest: true go-version-file: go/go.mod -<% elif lang == "rust" %> +<% endif %> +<% if "rust" in lang_tools %> - uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1.15.2 with: components: "clippy" @@ -317,13 +318,14 @@ jobs: submodules: 'recursive' <% endif %> -<% if lang == "go" %> +<% if "go" in lang_tools %> - uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0 with: cache-dependency-path: go/go.sum check-latest: true go-version-file: go/go.mod -<% elif lang == "rust" %> +<% endif %> +<% if "rust" in lang_tools %> - uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1.15.2 with: components: "clippy" @@ -493,13 +495,14 @@ jobs: submodules: 'recursive' <% endif %> -<% if lang == "go" %> +<% if "go" in lang_tools %> - uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0 with: cache-dependency-path: go/go.sum check-latest: true go-version-file: go/go.mod -<% elif lang == "rust" %> +<% endif %> +<% if "rust" in lang_tools %> - uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1.15.2 with: components: "clippy" @@ -582,12 +585,13 @@ jobs: submodules: 'recursive' <% endif %> -<% if lang == "go" %> +<% if "go" in lang_tools %> - uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0 with: check-latest: true go-version: "stable" -<% elif lang == "rust" %> +<% endif %> +<% if "rust" in lang_tools %> - uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1.15.2 with: components: "clippy" @@ -606,7 +610,7 @@ jobs: - name: Install tools working-directory: <{ lang_subdir }> run: | -<% if lang == "go" %> +<% if "go" in lang_tools %> # XXX: can't install go-licenses under go 1.25 # https://github.com/google/go-licenses/issues/312 git clone --depth=1 https://github.com/google/go-licenses @@ -619,7 +623,8 @@ jobs: go mod tidy go install . popd -<% elif lang == "rust" %> +<% endif %> +<% if "rust" in lang_tools %> cargo install cargo-about <% endif %> @@ -786,11 +791,6 @@ jobs: submodules: 'recursive' <% endif %> - - uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0 - with: - check-latest: true - go-version: "stable" - - uses: prefix-dev/setup-pixi@a0af7a228712d6121d37aba47adf55c1332c9c2e # v0.9.4 with: pixi-version: v0.63.2 diff --git a/adbc_drivers_dev/workflow.py b/adbc_drivers_dev/workflow.py index bd2cec0..adc848a 100644 --- a/adbc_drivers_dev/workflow.py +++ b/adbc_drivers_dev/workflow.py @@ -116,6 +116,9 @@ def generate_workflows(args) -> int: (args.repository / lang_subdir).mkdir(parents=True, exist_ok=True) + lang_tools = {lang} + lang_tools.update(lang_config.build.lang_tools) + template = env.get_template("test.yaml") write_workflow( workflows, @@ -130,6 +133,7 @@ def generate_workflows(args) -> int: "lang_human": lang_human, "lang_subdir": lang_subdir, "lang_config": lang_config, + "lang_tools": lang_tools, }, ) write_workflow( @@ -144,6 +148,7 @@ def generate_workflows(args) -> int: "lang_human": lang_human, "lang_subdir": lang_subdir, "lang_config": lang_config, + "lang_tools": lang_tools, }, ) template = env.get_template("go_test_pr.yaml")