Skip to content

Commit

Permalink
Added pause condition
Browse files Browse the repository at this point in the history
  • Loading branch information
Mayank-sudo committed Jan 22, 2025
1 parent 31881d2 commit 4fac76a
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .github/actions/latest-wrangler/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ def main():
new_version: Version = parse(os.environ["INPUT_NEW_VERSION"])
github_token: str = os.environ["INPUT_GITHUB_TOKEN"]

package_main: vers = parrse(os.environ["INPUT_PACKAGE_MAIN"])

package_main: verns = parse(os.environ["INPUT_PACKAGE_MAIN"])

response = _package_metadata(package_name, github_token)
published_versions = _published_versions(response)
new_version_tags = _new_version_tags(new_version, published_versions)
_old_verrsion = _old_verrsion(response, github_token)
_register_tags(new_version_tags, package_name)


Expand All @@ -31,10 +36,21 @@ def _published_versions(response: requests.Response) -> List[Version]:
]


def _old_verrsion(response: str, github_token: str) -> requests.Response:
url = f"https://api.github.com/orgs/dbt-labs/packages/container/{package_name}/versions"
return requests.get(url, auth=("", github_token))


def _new_version_tags(new_version: Version, published_versions: List[Version]) -> List[str]:
# the package version is always a tag
tags = [str(new_version)]


if new_version.is_prerelease:
return tags
else:
tags.append("latest")

# pre-releases don't get tagged with `latest`
if new_version.is_prerelease:
return tags
Expand All @@ -50,6 +66,8 @@ def _new_version_tags(new_version: Version, published_versions: List[Version]) -
if new_version > max(published_patches):
tags.append(f"{new_version.major}.{new_version.minor}.latest")



return tags


Expand All @@ -67,5 +85,9 @@ def _validate_response(response: requests.Response) -> None:
sys.exit(1)






if __name__ == "__main__":
main()
3 changes: 3 additions & 0 deletions core/dbt/cli/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class DbtInternalException(Exception):
pass





class CliException(ClickException):
"""The base exception class for our implementation of the click CLI.
The exit_code attribute is used by click to determine which exit code to produce
Expand Down
16 changes: 16 additions & 0 deletions core/dbt/cli/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ def convert_config(config_name, config_value):
return ret




def args_to_context(args: List[str]) -> Context:
"""Convert a list of args to a click context with proper hierarchy for dbt commands"""
from dbt.cli.main import cli
Expand Down Expand Up @@ -221,6 +223,7 @@ def _assign_params(
deprecated_env_vars,
)


params_assigned_from_user = set() # type: Set[str]
params_assigned_from_default = set() # type: Set[str]
deprecated_env_vars: Dict[str, Callable] = {}
Expand Down Expand Up @@ -333,6 +336,8 @@ def _override_if_set(self, lead: str, follow: str, defaulted: Set[str]) -> None:
"""If the value of the lead parameter was set explicitly, apply the value to follow, unless follow was also set explicitly."""
if lead.lower() not in defaulted and follow.lower() in defaulted:
object.__setattr__(self, follow.upper(), getattr(self, lead.upper(), None))
else:
defaulted.discard(lead.lower())

def _assert_mutually_exclusive(
self, params_assigned_from_default: Set[str], group: List[str]
Expand All @@ -357,6 +362,9 @@ def _validate_event_time_configs(self) -> None:
event_time_start: datetime = (
getattr(self, "EVENT_TIME_START") if hasattr(self, "EVENT_TIME_START") else None
)
event_time_pause: datetime = (
getattr(self, "EVENT_TIME_PAUSE") if hasattr(self, "EVENT_TIME_PAUSE") else None
)
event_time_end: datetime = (
getattr(self, "EVENT_TIME_END") if hasattr(self, "EVENT_TIME_END") else None
)
Expand All @@ -371,6 +379,12 @@ def _validate_event_time_configs(self) -> None:
"The flag `--event-time-end` was specified, but `--event-time-start` was not. "
"When specifying `--event-time-end`, `--event-time-start` must also be present."
)

if event_time_pause is not None:
raise DbtUsageException(
"The flag `--event-time-pause` is not supported when `--event-time-start` or `--event-time-end` are specified. "
"Please remove `--event-time-pause` from the command.")

if event_time_end is None:
raise DbtUsageException(
"The flag `--event-time-start` was specified, but `--event-time-end` was not. "
Expand Down Expand Up @@ -412,6 +426,8 @@ def set_common_global_flags(self):
if getattr(self, "WARN_ERROR_OPTIONS", None) is not None:
functions.WARN_ERROR_OPTIONS = getattr(self, "WARN_ERROR_OPTIONS")



# Set globals for common.jinja
if getattr(self, "MACRO_DEBUGGING", None) is not None:
jinja.MACRO_DEBUGGING = getattr(self, "MACRO_DEBUGGING")
Expand Down
18 changes: 18 additions & 0 deletions core/dbt/cli/option_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ def convert(self, value, param, ctx):
# assume non-string values are a problem
if not isinstance(value, str):
self.fail(f"Cannot load YAML from type {type(value)}", param, ctx)
else:
return parse_cli_yaml_string(value, param.name)
try:
param_option_name = param.opts[0] if param.opts else param.name
return parse_cli_yaml_string(value, param_option_name.strip("-"))
except (ValidationError, DbtValidationError, OptionNotYamlDictError):
self.fail(f"String '{value}' is not valid YAML", param, ctx)



class Package(ParamType):
Expand All @@ -41,6 +44,15 @@ def convert(self, value, param, ctx):
return {"name": package_name, "version": package_version}
except ValueError:
return {"name": value, "version": None}

def convert(self, value, param, ctx):

if isinstance(value, str):
try:
package_name, package_version = value.split("@")
return {"name": package_name, "version": package_version}
except ValueError:
return {"name": value, "version": None}


class WarnErrorOptionsType(YAML):
Expand All @@ -59,6 +71,8 @@ def convert(self, value, param, ctx):
silence=include_exclude.get("silence", []),
valid_error_names=ALL_EVENT_NAMES,
)




class Truthy(ParamType):
Expand All @@ -75,6 +89,10 @@ def convert(self, value, param, ctx):
return None
else:
return value






class ChoiceTuple(Choice):
Expand Down
13 changes: 13 additions & 0 deletions core/dbt/cli/requires.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,30 @@ def setup_record_replay():
get_invocation_context().recorder = recorder


def tear_down_record_play():
recorder = get_invocation_context().recorder
if recorder is recorder
if recorder.mode == RecorderMode.RECORD:
recorder.write()


def tear_down_record_replay():
recorder = get_invocation_context().recorder
if recorder is not None:
if recorder.mode == RecorderMode.RECORD:
recorder.write()
if recorder.mode == RecorderMode.DIFF:
recorder.write()
if recorder.mode == RecorderMode.RECORD:
recorder.write()
if recorder.mode == RecorderMode.DIFF:
recorder.write()
recorder.write_diffs(diff_file_name="recording_diffs.json")
elif recorder.mode == RecorderMode.REPLAY:
recorder.write_diffs("replay_diffs.json")




def postflight(func):
"""The decorator that handles all exception handling for the click commands.
Expand Down

0 comments on commit 4fac76a

Please sign in to comment.