Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions adbc_drivers_dev/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,13 @@ class LangConfig(BaseModel):
alias="exclude-platforms",
description="Platforms to exclude from build/test.",
)
github_stack_behavior: typing.Literal["all", "bottom", "top"] = Field(
default="all",
alias="github-stack-behavior",
description=(
"Which PRs in a stack run language_test.yaml: 'all', 'bottom' (lowest unmerged), and 'top'."
),
)
subdir: str | None = Field(
default=None,
description="Override the default subdirectory for this language. Use '.' to place files at the repository root.",
Expand Down
27 changes: 27 additions & 0 deletions adbc_drivers_dev/templates/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,21 @@ permissions:
<% set has_test_platforms = ["linux_amd64", "macos_arm64", "windows_amd64"] | reject("in", lang_config.exclude_platforms) | list %>
<% set run_tests = not lang_config.test.skip and has_test_platforms %>

<% set stack_condition = none %>
<% if not release %>
<% if lang_config.github_stack_behavior == "bottom" %>
<% set stack_condition = "github.event_name != 'pull_request' || github.event.pull_request.stack == null || github.event.pull_request.stack.base.ref == github.event.pull_request.base.ref" %>
<% elif lang_config.github_stack_behavior == "top" %>
<% set stack_condition = "github.event_name != 'pull_request' || github.event.pull_request.stack == null || github.event.pull_request.stack.position == github.event.pull_request.stack.size" %>
<% endif %>
<% endif %>

jobs:
<% if run_tests %>
test:
<% if stack_condition %>
if: <{stack_condition}>
<% endif %>
name: "Test/${{ matrix.platform }}_${{ matrix.arch }}"
runs-on: ${{ matrix.runner }}
strategy:
Expand Down Expand Up @@ -344,6 +356,9 @@ jobs:

<% if not lang_config.validation.skip %>
validate:
<% if stack_condition %>
if: <{stack_condition}>
<% endif %>
name: "Validate <{driver}> ${{ matrix.vendor_version }}/${{ matrix.platform }}_${{ matrix.arch }}"
runs-on: ${{ matrix.runner }}
strategy:
Expand Down Expand Up @@ -579,6 +594,9 @@ jobs:
<% endif %>

build:
<% if stack_condition %>
if: <{stack_condition}>
<% endif %>
name: "Build <{driver}>/${{ matrix.platform }}_${{ matrix.arch }}"
<% if run_tests %>
needs: test
Expand Down Expand Up @@ -710,6 +728,9 @@ jobs:
retention-days: 2

package:
<% if stack_condition %>
if: <{stack_condition}>
<% endif %>
name: "Generate Packages"
runs-on: ubuntu-latest
needs:
Expand Down Expand Up @@ -829,6 +850,9 @@ jobs:

<% if has_test_platforms %>
test-packages:
<% if stack_condition %>
if: <{stack_condition}>
<% endif %>
name: "Test Packages/${{ matrix.platform }}_${{ matrix.arch }}"
runs-on: ${{ matrix.runner }}
needs:
Expand Down Expand Up @@ -934,6 +958,9 @@ jobs:
<% endif %>

release:
<% if stack_condition %>
if: <{stack_condition}>
<% endif %>
<% if release %>
name: "Release"
<% else %>
Expand Down
11 changes: 11 additions & 0 deletions schema/generate-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@
"title": "Exclude-Platforms",
"type": "array"
},
"github-stack-behavior": {
"default": "all",
"description": "Which PRs in a stack run language_test.yaml: 'all', 'bottom' (lowest unmerged), and 'top'.",
"enum": [
"all",
"bottom",
"top"
],
"title": "Github-Stack-Behavior",
"type": "string"
},
"subdir": {
"anyOf": [
{
Expand Down
26 changes: 26 additions & 0 deletions tests/test_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,32 @@ def test_model_custom() -> None:
assert config != GenerateConfig.model_validate({})


def test_github_stack_behavior_default() -> None:
assert LangConfig().github_stack_behavior == "all"
config = GenerateConfig.model_validate({"lang": {"go": True}})
assert config.lang["go"].github_stack_behavior == "all"


@pytest.mark.parametrize("behavior", ["all", "bottom", "top"])
@pytest.mark.parametrize("key", ["github-stack-behavior", "github_stack_behavior"])
def test_github_stack_behavior(key: str, behavior: str) -> None:
config = GenerateConfig.model_validate({"lang": {"go": {key: behavior}}})
assert config.lang["go"].github_stack_behavior == behavior
assert (
config.model_dump(by_alias=True)["lang"]["go"]["github-stack-behavior"]
== behavior
)
assert config.model_dump()["lang"]["go"]["github_stack_behavior"] == behavior


@pytest.mark.parametrize("behavior", ["invalid", "TOP", "", None, True, 1])
def test_github_stack_behavior_invalid(behavior) -> None:
with pytest.raises(ValidationError):
GenerateConfig.model_validate(
{"lang": {"go": {"github-stack-behavior": behavior}}}
)


def test_params_secrets() -> None:
config = GenerateConfig.model_validate(
{
Expand Down
Loading