2020-08-08 18:42:21 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
def sub(path, pattern, repl, expected_count=1):
|
|
|
|
with open(path) as fh:
|
|
|
|
content = fh.read()
|
|
|
|
content, count = re.subn(pattern, repl, content, flags=re.MULTILINE)
|
|
|
|
if expected_count is not None:
|
|
|
|
assert count == expected_count, f"Pattern {pattern} replacement failed!"
|
|
|
|
with open(path, "wt") as fh:
|
|
|
|
fh.write(content)
|
|
|
|
|
|
|
|
|
|
|
|
def write_version(version: str):
|
|
|
|
for p in [
|
2021-03-07 20:03:16 +01:00
|
|
|
".github/workflows/ci-docker.yml",
|
|
|
|
".github/workflows/release-dev.yml",
|
|
|
|
".github/workflows/release.yml",
|
2020-08-08 18:42:21 +02:00
|
|
|
]:
|
2021-03-07 20:03:16 +01:00
|
|
|
sub(p, r'base_version=".*"', f'base_version="{version}"')
|
2020-08-08 18:42:21 +02:00
|
|
|
|
|
|
|
sub(
|
|
|
|
"docker/Dockerfile",
|
|
|
|
r"ARG BUILD_FROM=esphome/esphome-base-amd64:.*",
|
2021-03-07 20:03:16 +01:00
|
|
|
f"ARG BUILD_FROM=esphome/esphome-base-amd64:{version}",
|
2020-08-08 18:42:21 +02:00
|
|
|
)
|
|
|
|
sub(
|
|
|
|
"docker/Dockerfile.dev",
|
|
|
|
r"FROM esphome/esphome-base-amd64:.*",
|
2021-03-07 20:03:16 +01:00
|
|
|
f"FROM esphome/esphome-base-amd64:{version}",
|
2020-08-08 18:42:21 +02:00
|
|
|
)
|
|
|
|
sub(
|
|
|
|
"docker/Dockerfile.lint",
|
|
|
|
r"FROM esphome/esphome-lint-base:.*",
|
2021-03-07 20:03:16 +01:00
|
|
|
f"FROM esphome/esphome-lint-base:{version}",
|
2020-08-08 18:42:21 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
parser = argparse.ArgumentParser()
|
2021-03-07 20:03:16 +01:00
|
|
|
parser.add_argument("new_version", type=str)
|
2020-08-08 18:42:21 +02:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
version = args.new_version
|
|
|
|
print(f"Bumping to {version}")
|
|
|
|
write_version(version)
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
sys.exit(main() or 0)
|