Skip to content

Commit a39807c

Browse files
authored
feat: handle generating licenses for script builds (#78)
1 parent 4b44093 commit a39807c

File tree

5 files changed

+69
-19
lines changed

5 files changed

+69
-19
lines changed

adbc_drivers_dev/generate.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ class LangBuildConfig(BaseModel):
6464
description="A list of additional arguments to pass to adbc-make.",
6565
)
6666

67+
lang_tools: list[str] = Field(
68+
default_factory=list,
69+
alias="lang-tools",
70+
description="Install tools for these languages to use in the build.",
71+
)
72+
6773

6874
class LangConfig(BaseModel):
6975
model_config = {

adbc_drivers_dev/make.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,19 @@ def detect_version(
152152
raise ValueError(f"{driver_root} is not in a git repository")
153153
repo_root = repo_root.parent
154154

155-
prefix = str(driver_root.relative_to(repo_root))
156-
if prefix == ".":
155+
is_script_build = not any(
156+
(driver_root / name).is_file() for name in ("Cargo.toml", "go.mod")
157+
)
158+
if is_script_build:
159+
# We're going to assume custom builds like this are effectively the
160+
# entire repo, and use just plain tags "v1.0.0".
157161
prefix = "v"
158162
else:
159-
prefix = f"{prefix}/v"
163+
prefix = str(driver_root.relative_to(repo_root))
164+
if prefix == ".":
165+
prefix = "v"
166+
else:
167+
prefix = f"{prefix}/v"
160168

161169
tags = check_output(
162170
[

adbc_drivers_dev/package.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import enum
2323
import io
2424
import itertools
25+
import os
2526
import subprocess
2627
import sys
2728
import tarfile
@@ -151,6 +152,33 @@ def generate_rust_license(license_template: Path) -> str:
151152
return license_data
152153

153154

155+
def generate_custom_license(license_script: Path) -> str:
156+
import platform
157+
158+
args = [str(license_script.absolute())]
159+
if (
160+
platform.system() == "Windows"
161+
and os.environ.get("CI", "").lower().strip() == "true"
162+
):
163+
# Force use of Git Bash on GitHub Actions
164+
args = [r"C:\Program Files\Git\bin\bash.EXE", *args]
165+
license_proc = subprocess.run(
166+
args,
167+
cwd=license_script.parent.parent.parent,
168+
stdout=subprocess.PIPE,
169+
stderr=subprocess.PIPE,
170+
)
171+
if license_proc.returncode != 0:
172+
print("Failed to generate license", file=sys.stderr)
173+
print("Stdout:", file=sys.stderr)
174+
print(license_proc.stdout, file=sys.stderr)
175+
print("Stderr:", file=sys.stderr)
176+
print(license_proc.stderr, file=sys.stderr)
177+
license_proc.check_returncode()
178+
license_data = license_proc.stdout
179+
return license_data
180+
181+
154182
def generate_packages(
155183
manifest: dict[str, typing.Any],
156184
driver_name: str,
@@ -272,8 +300,11 @@ def main():
272300
if not notice_file.is_file():
273301
raise RuntimeError(f"NOTICE.txt ({notice_file}) is missing")
274302

303+
license_script = args.manifest_template.parent / "ci/scripts/generate_license.sh"
275304
license_template = args.manifest_template.with_name("license.tpl")
276-
if license_template.is_file():
305+
if license_script.is_file():
306+
license_data = generate_custom_license(license_script)
307+
elif license_template.is_file():
277308
if (gomod := args.manifest_template.with_name("go.mod")).is_file():
278309
license_data = generate_go_license(license_template, gomod)
279310
elif args.manifest_template.with_name("Cargo.toml").is_file():

adbc_drivers_dev/templates/test.yaml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,14 @@ jobs:
139139
submodules: 'recursive'
140140
<% endif %>
141141

142-
<% if lang == "go" %>
142+
<% if "go" in lang_tools %>
143143
- uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0
144144
with:
145145
cache-dependency-path: go/go.sum
146146
check-latest: true
147147
go-version-file: go/go.mod
148-
<% elif lang == "rust" %>
148+
<% endif %>
149+
<% if "rust" in lang_tools %>
149150
- uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1.15.2
150151
with:
151152
components: "clippy"
@@ -317,13 +318,14 @@ jobs:
317318
submodules: 'recursive'
318319
<% endif %>
319320

320-
<% if lang == "go" %>
321+
<% if "go" in lang_tools %>
321322
- uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0
322323
with:
323324
cache-dependency-path: go/go.sum
324325
check-latest: true
325326
go-version-file: go/go.mod
326-
<% elif lang == "rust" %>
327+
<% endif %>
328+
<% if "rust" in lang_tools %>
327329
- uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1.15.2
328330
with:
329331
components: "clippy"
@@ -493,13 +495,14 @@ jobs:
493495
submodules: 'recursive'
494496
<% endif %>
495497

496-
<% if lang == "go" %>
498+
<% if "go" in lang_tools %>
497499
- uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0
498500
with:
499501
cache-dependency-path: go/go.sum
500502
check-latest: true
501503
go-version-file: go/go.mod
502-
<% elif lang == "rust" %>
504+
<% endif %>
505+
<% if "rust" in lang_tools %>
503506
- uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1.15.2
504507
with:
505508
components: "clippy"
@@ -582,12 +585,13 @@ jobs:
582585
submodules: 'recursive'
583586
<% endif %>
584587

585-
<% if lang == "go" %>
588+
<% if "go" in lang_tools %>
586589
- uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0
587590
with:
588591
check-latest: true
589592
go-version: "stable"
590-
<% elif lang == "rust" %>
593+
<% endif %>
594+
<% if "rust" in lang_tools %>
591595
- uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1.15.2
592596
with:
593597
components: "clippy"
@@ -606,7 +610,7 @@ jobs:
606610
- name: Install tools
607611
working-directory: <{ lang_subdir }>
608612
run: |
609-
<% if lang == "go" %>
613+
<% if "go" in lang_tools %>
610614
# XXX: can't install go-licenses under go 1.25
611615
# https://github.com/google/go-licenses/issues/312
612616
git clone --depth=1 https://github.com/google/go-licenses
@@ -619,7 +623,8 @@ jobs:
619623
go mod tidy
620624
go install .
621625
popd
622-
<% elif lang == "rust" %>
626+
<% endif %>
627+
<% if "rust" in lang_tools %>
623628
cargo install cargo-about
624629
<% endif %>
625630

@@ -786,11 +791,6 @@ jobs:
786791
submodules: 'recursive'
787792
<% endif %>
788793

789-
- uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0
790-
with:
791-
check-latest: true
792-
go-version: "stable"
793-
794794
- uses: prefix-dev/setup-pixi@a0af7a228712d6121d37aba47adf55c1332c9c2e # v0.9.4
795795
with:
796796
pixi-version: v0.63.2

adbc_drivers_dev/workflow.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ def generate_workflows(args) -> int:
116116

117117
(args.repository / lang_subdir).mkdir(parents=True, exist_ok=True)
118118

119+
lang_tools = {lang}
120+
lang_tools.update(lang_config.build.lang_tools)
121+
119122
template = env.get_template("test.yaml")
120123
write_workflow(
121124
workflows,
@@ -130,6 +133,7 @@ def generate_workflows(args) -> int:
130133
"lang_human": lang_human,
131134
"lang_subdir": lang_subdir,
132135
"lang_config": lang_config,
136+
"lang_tools": lang_tools,
133137
},
134138
)
135139
write_workflow(
@@ -144,6 +148,7 @@ def generate_workflows(args) -> int:
144148
"lang_human": lang_human,
145149
"lang_subdir": lang_subdir,
146150
"lang_config": lang_config,
151+
"lang_tools": lang_tools,
147152
},
148153
)
149154
template = env.get_template("go_test_pr.yaml")

0 commit comments

Comments
 (0)