Skip to content

Commit

Permalink
Revert "feat(bitrisescript): Add build_variations key to support more…
Browse files Browse the repository at this point in the history
… variati…" (#987)

This reverts commit cb6950a.
  • Loading branch information
hneiva committed May 8, 2024
1 parent cb6950a commit 338d627
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,67 +17,8 @@
"description": "Prefix to store task artifacts. Setting this to 'public' will generate public artifacts.",
"type": "string"
},
"workflow_params": {
"description": "Workflow-specific values to form a Bitrise build_params object. Mapping a workflow id to a list of permutations. It CAN override values in global_params.",
"type": "object",
"additionalProperties":{
"type": "array",
"items": {
"type": "object",
"properties": {
"branch": {
"description": "The branch running the build. For pull requests, this should be the head branch.",
"type": "string"
},
"branch_dest": {
"description": "The destination branch where the branch running the build will merge into. Only valid for pull requests.",
"type": "string"
},
"branch_dest_repo_owner": {
"description": "The repository owning the destination branch. Only valid for pull requests.",
"type": "string"
},
"branch_repo_owner": {
"description": "The repository owning the branch.",
"type": "string"
},
"commit_hash": {
"description": "The hash of the commit running the build.",
"type": "string"
},
"commit_message": {
"description": "The commit message of the commit running the build.",
"type": "string"
},
"environments": {
"description": "Environment variables to pass into the build.",
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"pull_request_author": {
"description": "The author of the pull request running the build.",
"type": "string"
},
"pull_request_id": {
"description": "The id of the pull request running the build.",
"type": "integer"
},
"skip_git_status_report": {
"description": "Whether Bitrise should send a status report to Github (default False).",
"type": "boolean"
},
"tag": {
"description": "The tag of the commit running the build.",
"type": "string"
}
}
}
}
},
"global_params": {
"description": "Default parameters describing the build context to pass onto Bitrise. All keys are optional but specific workflows may depend on particular keys being set.",
"build_params": {
"description": "Parameters describing the build context to pass onto Bitrise. All keys are optional but specific workflows may depend on particular keys being set.",
"type": "object",
"properties": {
"branch": {
Expand Down
6 changes: 3 additions & 3 deletions bitrisescript/src/bitrisescript/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ async def async_main(config, task):
log.info(f"Bitrise app: '{app}'")

artifact_dir = get_artifact_dir(config, task)
build_params = get_build_params(task)

futures = []
for workflow in get_bitrise_workflows(config, task):
build_params_list = get_build_params(task, workflow)
for build_params in build_params_list:
futures.append(run_build(artifact_dir, **build_params))
build_params["workflow_id"] = workflow
futures.append(run_build(artifact_dir, **build_params))

client = None
try:
Expand Down
49 changes: 3 additions & 46 deletions bitrisescript/src/bitrisescript/task.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,10 @@
import os
from copy import deepcopy
from typing import Any

from scriptworker_client.exceptions import TaskVerificationError
from scriptworker_client.utils import get_single_item_from_sequence


def _deep_merge_dict(source: dict, dest: dict) -> dict:
"""Deep merge two dictionaries.
Copied from taskgraph.utils.templates.merge_to
https://github.com/taskcluster/taskgraph/blob/main/src/taskgraph/util/templates.py
Args:
source (dict): The base dictionary to be copied from.
dest (dict): The destinatioon dictionary modified.
"""
for key, value in source.items():
# Override mismatching or empty types
if type(value) != type(dest.get(key)): # noqa: E721
dest[key] = source[key]
continue

# Merge dict
if isinstance(value, dict):
_deep_merge_dict(value, dest[key])
continue

# Merge list
if isinstance(value, list):
dest[key] = dest[key] + source[key]
continue

dest[key] = source[key]

return dest


def _get_allowed_scope_prefixes(config):
prefixes = config["taskcluster_scope_prefixes"]
return [prefix if prefix.endswith(":") else "{}:".format(prefix) for prefix in prefixes]
Expand Down Expand Up @@ -118,27 +86,16 @@ def get_bitrise_workflows(config: dict[str, Any], task: dict[str, Any]) -> list[
return workflows


def get_build_params(task: dict[str, Any], workflow: str = None) -> list[dict[str, Any]]:
def get_build_params(task: dict[str, Any]) -> dict[str, Any]:
"""Get the build_params from the task payload or an empty dict.
Args:
task (dict): The task definition.
workflow (str): Optional workflow reference used to load workflow_params
Returns:
dict: The bitrise build_params to specify. Always adds workflow_id to the returned dict.
dict: The bitrise build_params to specify. Empty dict if unspecified.
"""
global_params = task["payload"].get("global_params", {})
workflow_params = task["payload"].get("workflow_params", {}).get(workflow)
global_params["workflow_id"] = workflow
if not workflow_params:
return [global_params]
build_params = []
for variation in workflow_params:
params = deepcopy(global_params)
params = _deep_merge_dict(variation, params)
build_params.append(params)
return build_params
return task["payload"].get("build_params", {})


def get_artifact_dir(config: dict[str, Any], task: dict[str, Any]) -> str:
Expand Down
55 changes: 6 additions & 49 deletions bitrisescript/tests/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,63 +112,20 @@ def test_get_bitrise_workflows(config, task, expectation, expected):


@pytest.mark.parametrize(
"task_payload, expected",
"task, expected",
(
# Simple payload with no global_params
(
{"payload": {}},
{},
[{"workflow_id": "wkflw"}],
),
# Simple payload with global_params
(
{"global_params": {"foo": "bar"}},
[{"foo": "bar"}],
),
# Payload with multiple workflow_params
(
{"global_params": {"foo": "bar"}, "workflow_params": {"wkflw": [{"baz": "qux"}, {"tap": "zab"}]}},
[
{"foo": "bar", "baz": "qux"},
{"foo": "bar", "tap": "zab"},
],
),
# Payload with workflow_params but no global_params
(
{"workflow_params": {"wkflw": [{"baz": "qux"}]}},
[{"baz": "qux"}],
),
# Payload with workflow_params and overriding workflow_params
(
{"global_params": {"foo": "bar"}, "workflow_params": {"wkflw": [{"baz": "qux"}, {"foo": "zab"}]}},
[
{"foo": "bar", "baz": "qux"},
{"foo": "zab"},
],
),
# Complex global_params and workflow_params
(
{
"global_params": {"environment": {"var1": "value1"}},
"workflow_params": {
"wkflw": [
{"environment": {"var2": "value2"}},
{"environment": {"var3": "value3"}},
# Override var1
{"environment": {"var3": "value3", "var1": "OVERRIDE"}},
]
},
},
[
{"environment": {"var1": "value1", "var2": "value2"}},
{"environment": {"var1": "value1", "var3": "value3"}},
{"environment": {"var1": "OVERRIDE", "var3": "value3"}},
],
{"payload": {"build_params": "foo"}},
"foo",
),
),
)
def test_get_build_params(task_payload, expected):
# workflow_id should always be inserted into build_params
assert task_mod.get_build_params({"payload": task_payload}, "wkflw") == [{"workflow_id": "wkflw", **item} for item in expected]
def test_get_build_params(task, expected):
assert task_mod.get_build_params(task) == expected


@pytest.mark.parametrize(
Expand Down

0 comments on commit 338d627

Please sign in to comment.