Skip to content

Commit 240a23e

Browse files
authored
feat: add support for overriding lang subdir (#140)
## What's Changed Adds and wires through a new option to `LangConfig` called `subdir` that lets driver repos use a non-default subdirectory (or the repo root) for their driver, rather than having to put their driver code in a language-specific subdir. Having a pattern for multi-lang driver repos is good but I think supporting single-lang driver repos is worthwhile. For example, a Go driver at the root of a repo would enable Go and set their subdir with, ```toml driver = "something" private = false [lang.go] subdir = "." ``` Also re-generates the generate schema and we were out of date so there are extra changes in there.
1 parent 9d4550a commit 240a23e

4 files changed

Lines changed: 156 additions & 37 deletions

File tree

adbc_drivers_dev/generate.py

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

67-
go_mod_path: str = Field(
68-
default="go",
67+
go_mod_path: str | None = Field(
68+
default=None,
6969
alias="go-mod-path",
70-
description="Path containing the go.mod file for Go drivers. Used to cache dependencies in CI.",
70+
description="Path containing the go.mod file for Go drivers. Used to cache dependencies in CI. Defaults to the language subdir.",
7171
)
7272

7373
lang_tools: list[str] = Field(
@@ -94,6 +94,10 @@ class LangConfig(BaseModel):
9494
default_factory=LangBuildConfig,
9595
description="Configuration for building the driver.",
9696
)
97+
subdir: str | None = Field(
98+
default=None,
99+
description="Override the default subdirectory for this language. Use '.' to place files at the repository root.",
100+
)
97101
skip_test: bool = Field(
98102
default=False,
99103
alias="skip-test",

adbc_drivers_dev/templates/test.yaml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,20 @@ on:
3434
branches:
3535
- main
3636
paths:
37-
- "<{lang_subdir}>/**"
37+
- "<{lang_path_glob}>"
3838
<% for path in pull_request_trigger_paths %>
3939
- <{path}>
4040
<% endfor %>
4141
<% endif %>
4242
push:
4343
<% if release %>
4444
tags:
45-
- "<{lang_subdir}>/v**"
45+
- "<{lang_tag_prefix}>v**"
4646
<% else %>
4747
branches:
4848
- main
4949
paths:
50-
- "<{lang_subdir}>/**"
50+
- "<{lang_path_glob}>"
5151
<% for path in pull_request_trigger_paths %>
5252
- <{path}>
5353
<% endfor %>
@@ -143,9 +143,9 @@ jobs:
143143
<% if "go" in lang_tools %>
144144
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
145145
with:
146-
cache-dependency-path: <{lang_config.build.go_mod_path}>/go.sum
146+
cache-dependency-path: <{go_mod_path}>/go.sum
147147
check-latest: true
148-
go-version-file: <{lang_config.build.go_mod_path}>/go.mod
148+
go-version-file: <{go_mod_path}>/go.mod
149149
<% endif %>
150150
<% if "rust" in lang_tools %>
151151
- uses: actions-rust-lang/setup-rust-toolchain@150fca883cd4034361b621bd4e6a9d34e5143606 # v1.15.4
@@ -323,9 +323,9 @@ jobs:
323323
<% if "go" in lang_tools %>
324324
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
325325
with:
326-
cache-dependency-path: <{lang_config.build.go_mod_path}>/go.sum
326+
cache-dependency-path: <{go_mod_path}>/go.sum
327327
check-latest: true
328-
go-version-file: <{lang_config.build.go_mod_path}>/go.mod
328+
go-version-file: <{go_mod_path}>/go.mod
329329
<% endif %>
330330
<% if "rust" in lang_tools %>
331331
- uses: actions-rust-lang/setup-rust-toolchain@150fca883cd4034361b621bd4e6a9d34e5143606 # v1.15.4
@@ -504,9 +504,9 @@ jobs:
504504
<% if "go" in lang_tools %>
505505
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
506506
with:
507-
cache-dependency-path: <{lang_config.build.go_mod_path}>/go.sum
507+
cache-dependency-path: <{go_mod_path}>/go.sum
508508
check-latest: true
509-
go-version-file: <{lang_config.build.go_mod_path}>/go.mod
509+
go-version-file: <{go_mod_path}>/go.mod
510510
<% endif %>
511511
<% if "rust" in lang_tools %>
512512
- uses: actions-rust-lang/setup-rust-toolchain@150fca883cd4034361b621bd4e6a9d34e5143606 # v1.15.4
@@ -836,8 +836,8 @@ jobs:
836836
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
837837
working-directory: <{ lang_subdir }>
838838
run: |
839-
git tag <{ lang_subdir }>/v1000.0.0
840-
tag=<{ lang_subdir }>/v1000.0.0
839+
git tag <{lang_tag_prefix}>v1000.0.0
840+
tag=<{lang_tag_prefix}>v1000.0.0
841841
842842
pixi run release --dry-run $(pwd) $tag
843843
echo gh release upload $tag $(find ~/packages -name '*.tar.gz') $(find ~/packages -name 'manifest.yaml') $(find ~/packages -name '*.md')
@@ -847,8 +847,8 @@ jobs:
847847
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
848848
working-directory: <{ lang_subdir }>
849849
run: |
850-
git tag <{ lang_subdir }>/v1000.0.0
851-
tag=<{ lang_subdir }>/v1000.0.0
850+
git tag <{lang_tag_prefix}>v1000.0.0
851+
tag=<{lang_tag_prefix}>v1000.0.0
852852
853853
pixi run release --dry-run $(pwd) $tag
854854
echo gh release upload $tag $(find ~/packages -name '*.tar.gz') $(find ~/packages -name 'manifest.yaml') $(find ~/packages -name '*.md')

adbc_drivers_dev/workflow.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -109,31 +109,46 @@ def generate_workflows(args) -> int:
109109
}
110110

111111
retcode = 0
112-
for lang, (lang_human, lang_subdir) in langs.items():
112+
for lang, (lang_human, lang_subdir_default) in langs.items():
113113
lang_config = params.lang.get(lang)
114114
if not lang_config:
115115
continue
116116

117+
lang_subdir = (
118+
lang_config.subdir
119+
if lang_config.subdir is not None
120+
else lang_subdir_default
121+
)
122+
lang_tag_prefix = "" if lang_subdir == "." else f"{lang_subdir}/"
123+
lang_path_glob = "**" if lang_subdir == "." else f"{lang_subdir}/**"
124+
117125
(args.repository / lang_subdir).mkdir(parents=True, exist_ok=True)
118126

119127
lang_tools = {lang}
120128
lang_tools.update(lang_config.build.lang_tools)
121129

122130
template = env.get_template("test.yaml")
131+
go_mod_path = lang_config.build.go_mod_path or lang_subdir
132+
lang_ctx = {
133+
"lang": lang,
134+
"lang_human": lang_human,
135+
"lang_subdir": lang_subdir,
136+
"lang_tag_prefix": lang_tag_prefix,
137+
"lang_path_glob": lang_path_glob,
138+
"go_mod_path": go_mod_path,
139+
"lang_config": lang_config,
140+
"lang_tools": lang_tools,
141+
}
123142
write_workflow(
124143
workflows,
125144
template,
126145
f"{lang}_test.yaml",
127146
{
128147
**params.to_dict(),
148+
**lang_ctx,
129149
"pull_request_trigger_paths": [f".github/workflows/{lang}_test.yaml"],
130150
"release": False,
131151
"workflow_name": "Test",
132-
"lang": lang,
133-
"lang_human": lang_human,
134-
"lang_subdir": lang_subdir,
135-
"lang_config": lang_config,
136-
"lang_tools": lang_tools,
137152
},
138153
)
139154
write_workflow(
@@ -142,13 +157,9 @@ def generate_workflows(args) -> int:
142157
f"{lang}_release.yaml",
143158
{
144159
**params.to_dict(),
160+
**lang_ctx,
145161
"release": True,
146162
"workflow_name": "Release",
147-
"lang": lang,
148-
"lang_human": lang_human,
149-
"lang_subdir": lang_subdir,
150-
"lang_config": lang_config,
151-
"lang_tools": lang_tools,
152163
},
153164
)
154165
template = env.get_template("go_test_pr.yaml")
@@ -169,10 +180,7 @@ def generate_workflows(args) -> int:
169180
"pixi.toml",
170181
{
171182
**params.to_dict(),
172-
"lang": lang,
173-
"lang_human": lang_human,
174-
"lang_subdir": lang_subdir,
175-
"lang_config": lang_config,
183+
**lang_ctx,
176184
},
177185
)
178186

schema/generate-schema.json

Lines changed: 113 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,86 @@
1616
"title": "AwsConfig",
1717
"type": "object"
1818
},
19+
"LangBuildConfig": {
20+
"additionalProperties": false,
21+
"properties": {
22+
"additional-make-args": {
23+
"description": "A list of additional arguments to pass to adbc-make.",
24+
"items": {
25+
"type": "string"
26+
},
27+
"title": "Additional-Make-Args",
28+
"type": "array"
29+
},
30+
"go-mod-path": {
31+
"anyOf": [
32+
{
33+
"type": "string"
34+
},
35+
{
36+
"type": "null"
37+
}
38+
],
39+
"default": null,
40+
"description": "Path containing the go.mod file for Go drivers. Used to cache dependencies in CI. Defaults to the language subdir.",
41+
"title": "Go-Mod-Path"
42+
},
43+
"lang-tools": {
44+
"description": "Install tools for these languages to use in the build.",
45+
"items": {
46+
"type": "string"
47+
},
48+
"title": "Lang-Tools",
49+
"type": "array"
50+
},
51+
"environment-contexts": {
52+
"description": "What parts of the build require the environment.",
53+
"items": {
54+
"type": "string"
55+
},
56+
"title": "Environment-Contexts",
57+
"type": "array"
58+
}
59+
},
60+
"title": "LangBuildConfig",
61+
"type": "object"
62+
},
63+
"LangConfig": {
64+
"additionalProperties": false,
65+
"properties": {
66+
"build": {
67+
"$ref": "#/$defs/LangBuildConfig",
68+
"description": "Configuration for building the driver."
69+
},
70+
"subdir": {
71+
"anyOf": [
72+
{
73+
"type": "string"
74+
},
75+
{
76+
"type": "null"
77+
}
78+
],
79+
"default": null,
80+
"description": "Override the default subdirectory for this language. Use '.' to place files at the repository root.",
81+
"title": "Subdir"
82+
},
83+
"skip-test": {
84+
"default": false,
85+
"description": "Whether to skip test workflows (primarily useful for build-only drivers)",
86+
"title": "Skip-Test",
87+
"type": "boolean"
88+
},
89+
"skip-validate": {
90+
"default": false,
91+
"description": "Whether to skip the validation suite in CI (this should only be used temporarily while setting up a driver)",
92+
"title": "Skip-Validate",
93+
"type": "boolean"
94+
}
95+
},
96+
"title": "LangConfig",
97+
"type": "object"
98+
},
1999
"SecretConfigDict": {
20100
"additionalProperties": false,
21101
"description": "Secret configuration with explicit secret name and contexts.",
@@ -29,6 +109,7 @@
29109
"description": "Workflow contexts where this secret should be available",
30110
"items": {
31111
"enum": [
112+
"build:test",
32113
"build:release",
33114
"test",
34115
"validate"
@@ -51,9 +132,15 @@
51132
"properties": {
52133
"extra-dependencies": {
53134
"additionalProperties": true,
54-
"description": "Additional dependencies to install for validation workflows. Specify as key-value pairs. Example:\n\n[validation.extra-dependencies]\npytest = \"^7.0\"\nblack = \"*\"",
135+
"description": "Additional dependencies to install for validation workflows. Specify as key-value pairs. Example:\n\n[validation.extra-dependencies]\npytest = \">=7,<8\"\nblack = \"*\"",
55136
"title": "Extra-Dependencies",
56137
"type": "object"
138+
},
139+
"extra-pypi-dependencies": {
140+
"additionalProperties": true,
141+
"description": "Additional dependencies to install for validation workflows. Specify as key-value pairs. Example:\n\n[validation.extra-pypi-dependencies]\npytest = \">=7,<8\"\nblack = \"*\"",
142+
"title": "Extra-Pypi-Dependencies",
143+
"type": "object"
57144
}
58145
},
59146
"title": "ValidationConfig",
@@ -64,6 +151,19 @@
64151
"additionalProperties": false,
65152
"description": "You can validate your generate.toml against this schema with tools like tombi (https://tombi-toml.github.io/tombi/docs/linter). Requires placing a `#:schema` directive at the top of your generate.toml file.",
66153
"properties": {
154+
"repository": {
155+
"anyOf": [
156+
{
157+
"type": "string"
158+
},
159+
{
160+
"type": "null"
161+
}
162+
],
163+
"default": null,
164+
"description": "GitHub repository name (if different from driver name)",
165+
"title": "Repository"
166+
},
67167
"driver": {
68168
"default": "(unknown)",
69169
"description": "Driver name. Should be lowercase (e.g., postgresql, sqlite)",
@@ -85,15 +185,22 @@
85185
},
86186
"private": {
87187
"default": false,
88-
"description": "Whether the driver is private. Most drivers will be non-private.",
188+
"description": "Whether the driver is private. Most drivers will be not be private so you can omit this.",
89189
"title": "Private",
90190
"type": "boolean"
91191
},
92192
"lang": {
93193
"additionalProperties": {
94-
"type": "boolean"
194+
"anyOf": [
195+
{
196+
"$ref": "#/$defs/LangConfig"
197+
},
198+
{
199+
"type": "null"
200+
}
201+
]
95202
},
96-
"description": "Programming languages to enable workflows for. Only go is really supported right now. Keys should be lowercase. Set to true to enable, false to disable. Example:\n\n[lang]\ngo = true\npython = false",
203+
"description": "Programming language(s) to enable workflows for. Only go and rust are supported. Keys should be lowercase. Set to true to enable with default config, or false (the default) to disable. Example:\n\n[lang]\ngo = true\n\n[lang.rust.build]\nadditional-make-args = [\"example\"]",
97204
"title": "Lang",
98205
"type": "object"
99206
},
@@ -108,7 +215,7 @@
108215
}
109216
]
110217
},
111-
"description": "Secrets to enable in workflows. By default, no secrets are available in your generated workflows unless you specify them here.\n\nFor a secret available in all workflows, use simple syntax:\n\n[secrets]\nMY_TOKEN = \"GITHUB_SECRET_NAME\"\n\nTo restrict secrets to specific workflows, use contexts (valid values: 'build:release', 'test', 'validate'):\n\n[secrets.DB_PASSWORD]\nsecret = \"TEST_DB_SECRET\"\ncontexts = [\"test\", \"validate\"]",
218+
"description": "Secrets to enable in workflows. By default, no secrets are available in your generated workflows unless you specify them here.\n\nTo make a secret available in all workflows, use the simple syntax:\n\n[secrets]\nMY_TOKEN = \"GITHUB_SECRET_NAME\"\n\nIf you want more fine-grained control, you can restrict secrets to specific workflows. To do this, specify contexts contexts ('build:release', 'test', 'validate') like this:\n\n[secrets.DB_PASSWORD]\nsecret = \"TEST_DB_SECRET\"\ncontexts = [\"test\", \"validate\"]",
112219
"title": "Secrets",
113220
"type": "object"
114221
},
@@ -122,7 +229,7 @@
122229
}
123230
],
124231
"default": null,
125-
"description": "Enables AWS authentication in workflows. Automatically adds AWS_ROLE and AWS_ROLE_SESSION_NAME secrets, and sets id_token permissions. Example:\n\naws.region = \"us-west-2\"\n\nOr:\n\n[aws]\nregion = \"us-west-2\""
232+
"description": "Enables AWS authentication in workflows. Automatically adds AWS_ROLE and AWS_ROLE_SESSION_NAME secrets, and sets id_token permissions. Example:\n\n[aws]\nregion = \"us-west-2\""
126233
},
127234
"gcloud": {
128235
"default": false,

0 commit comments

Comments
 (0)