Skip to content

Commit

Permalink
Merge-friendly output of command hashes for breeze
Browse files Browse the repository at this point in the history
We had just one hash generated from all commands in breeze and that
basically meant that when there were two PRs on two different
commands in Breeze, they resulted with merge conflict which
should be solved with `breeze regenerate-command-images`.

This change turns the hash output into a multi-command one - i.e.
each command has its own hash, which will make it much more
merge-friendly - i.e. if two PRs will work on two different commands
the rebase should result with merge rather than conflict.
  • Loading branch information
potiuk committed Jun 28, 2022
1 parent 5321577 commit 11911c2
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,10 @@ def command_hash_export(verbose: bool, output: IO):
the_context_dict = ctx.to_info_dict()
if verbose:
get_console().print(the_context_dict)
output.write(dict_hash(the_context_dict) + "\n")
output.write(f"main:{dict_hash(the_context_dict['command']['params'])}\n")
commands_dict = the_context_dict['command']['commands']
for command in sorted(commands_dict.keys()):
output.write(f"{command}:{dict_hash(commands_dict[command])}\n")


def write_to_shell(command_to_execute: str, dry_run: bool, script_path: str, force_setup: bool) -> bool:
Expand Down
34 changes: 33 additions & 1 deletion images/breeze/output-commands-hash.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,36 @@
# This file is automatically generated by pre-commit. If you have a conflict with this file
# Please do not solve it but run `breeze regenerate-command-images`.
# This command should fix the conflict and regenerate help images that you have conflict with.
d382b111fddf3b8c0fd3434fce8aa948
main:fa4319079b275ce966502346f083f2e3
build-docs:deaecc6bf5fa84153d30b2167e5ca404
build-image:b62509a59badf3aa230e4562df751002
build-prod-image:1902ec077a6d70336de6038d13472ef3
cleanup:9a94bd1063296ea86e895f671db0b330
command-hash-export:83bc6a4a8c60b62da3d0f00e81d2c3ea
config:92653afc11889e1b78e3a2e38f41107f
docker-compose-tests:8ae3b6211fd31db81a750d1c6b96ec3d
exec:e4329909b8b2a610fa4fad5116c4b896
find-newer-dependencies:00000f7afb289e36e8c573fcc654df44
fix-ownership:596143cc74217f0a90850a554220ea45
free-space:bb8e7ac63d12ab3ede272a898de2f527
generate-constraints:a5120e79439f30eb7fbee929dca23156
prepare-airflow-package:cff9d88ca313db10f3cc464c6798f6be
prepare-provider-documentation:08ffb712f527fd57748929ac220cb5df
prepare-provider-packages:3a601458490ef2fab3421ed7b1c41d9f
pull-image:a9bb83372b5da5212f48e2affeedc551
pull-prod-image:6e8467a2b8c833a392c8bdd65189363e
regenerate-command-images:4fd2e7ecbfd6eebb18b854f3eb0f29c8
release-prod-images:8858fe5a13989c7c65a79dc97a880928
resource-check:0fb929ac3496dbbe97acfe99e35accd7
selective-check:eb1cf022ae43fa9c737b1647142e5a96
self-upgrade:b5437c0a1a91533a11ee9d0a9692369c
setup-autocomplete:355b72dee171c2fcba46fc90ac7c97b0
shell:4680295fdd8a276d51518d29360c365c
start-airflow:92cf775a952439a32d409cd2536da507
static-checks:96a0bcc981be838ae32f53e804157ee5
stop:8ebd8a42f1003495d37b884de5ac7ce6
tests:ae8d62b505ff8f79bddc202fe9d575e3
verify-image:a6b3c70957aea96a5d4d261f23359a2d
verify-prod-image:bf3cf39200e010e3015ef071fd387c6f
verify-provider-packages:797e60067fc4611112527de808b5c1c1
version:d11da4c17a23179830079b646160149c
17 changes: 11 additions & 6 deletions scripts/ci/pre_commit/pre_commit_breeze_cmd_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def print_help_for_all_commands():
env['RECORD_BREEZE_OUTPUT_FILE'] = str(BREEZE_IMAGES_DIR / "output-commands.svg")
env['TERM'] = "xterm-256color"
env['PYTHONPATH'] = str(BREEZE_SOURCES_DIR)
new_hash = check_output(
new_hash_dump = PREAMBLE + check_output(
[
sys.executable,
str(BREEZE_SOURCES_DIR / "airflow_breeze" / "breeze.py"),
Expand All @@ -67,12 +67,17 @@ def print_help_for_all_commands():
)
hash_file_path = BREEZE_IMAGES_DIR / "output-commands-hash.txt"
try:
old_hash = hash_file_path.read_text()[len(PREAMBLE) :]
old_hash_dump = hash_file_path.read_text()
except FileNotFoundError:
old_hash = ""
if old_hash == new_hash:
console.print(f"[bright_blue]Skip generation of SVG images as command hash is unchanged {old_hash}")
old_hash_dump = ""
if old_hash_dump == new_hash_dump:
console.print("[bright_blue]Skip generation of SVG images as command hash files are unchanged:")
console.print(old_hash_dump, markup=False)
return
else:
console.print("[yellow]The hash files differ")
console.print(new_hash_dump, markup=False)
console.print(old_hash_dump, markup=False)
run([sys.executable, "-m", "pip", "install", "--upgrade", "-e", BREEZE_INSTALL_DIR])
env = os.environ.copy()
env['AIRFLOW_SOURCES_ROOT'] = str(AIRFLOW_SOURCES_DIR)
Expand All @@ -89,7 +94,7 @@ def print_help_for_all_commands():
env['RECORD_BREEZE_OUTPUT_FILE'] = str(BREEZE_IMAGES_DIR / f"output-{command}.svg")
env['TERM'] = "xterm-256color"
check_call(["breeze", command, "--help"], env=env)
hash_file_path.write_text(PREAMBLE + new_hash)
hash_file_path.write_text(new_hash_dump)


def verify_all_commands_described_in_docs():
Expand Down

0 comments on commit 11911c2

Please sign in to comment.