-
Notifications
You must be signed in to change notification settings - Fork 97
/
version.py
executable file
·111 lines (89 loc) · 3.38 KB
/
version.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env python3
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
import os
# To be updated every time we start a new major.minor version.
major_minor = "1.12"
# Default to 'dev' builds
BUILD_TYPE = os.environ.get("BUILD_TYPE") or "dev"
BUILD_NUMBER = os.environ.get("BUILD_NUMBER")
if not BUILD_NUMBER:
raise Exception("BUILD_NUMBER environment variable must be set")
if BUILD_TYPE not in ["dev", "rc", "stable"]:
print("BUILD_TYPE environment variable must be 'dev', 'rc', or 'stable'")
exit(1)
try:
build_ver = int(BUILD_NUMBER)
except:
print("BUILD_NUMBER environment variable must be set to a valid integer")
exit(1)
print("Build type: {}".format(BUILD_TYPE))
version_triple = "{}.{}".format(major_minor, build_ver)
pip_suffix = {"stable": "", "rc": "rc0", "dev": ".dev0"}
npm_suffix = {"stable": "", "rc": "-rc", "dev": "-dev"}
pip_version = "{}{}".format(version_triple, pip_suffix.get(BUILD_TYPE))
npm_version = "{}{}".format(version_triple, npm_suffix.get(BUILD_TYPE))
print("Pip version: {}".format(pip_version))
print("Npm version: {}".format(npm_version))
print("VS Code version: {}".format(version_triple))
def update_file(file: str, old_text: str, new_text: str):
# Open the file and replace the first string matching the old text with the new text
with open(file, "r+", newline="") as f:
contents = f.read()
new_contents = contents.replace(old_text, new_text, 1)
f.seek(0)
f.write(new_contents)
f.truncate()
root_dir = os.path.dirname(os.path.abspath(__file__))
update_file(
os.path.join(root_dir, "pip/pyproject.toml"),
r'version = "0.0.0"',
r'version = "{}"'.format(pip_version),
)
update_file(
os.path.join(root_dir, "pip/qsharp/telemetry.py"),
r'QSHARP_VERSION = "0.0.0.dev0"',
r'QSHARP_VERSION = "{}"'.format(pip_version),
)
update_file(
os.path.join(root_dir, "widgets/pyproject.toml"),
r'version = "0.0.0"',
r'version = "{}"'.format(pip_version),
)
# Publish the jupyterlab extension without the 'pre-release' tagging for rc builds.
# It is already stable and the prior publishing (and yanking) of release versions causes issues.
update_file(
os.path.join(root_dir, "jupyterlab/pyproject.toml"),
r'version = "0.0.0"',
r'version = "{}"'.format(pip_version if BUILD_TYPE == "dev" else version_triple),
)
update_file(
os.path.join(root_dir, "npm/qsharp/package.json"),
r'"version": "0.0.0",',
r'"version": "{}",'.format(npm_version),
)
update_file(
os.path.join(root_dir, "vscode/package.json"),
r'"version": "0.0.0",',
r'"version": "{}",'.format(version_triple),
)
# If not a 'dev' build, update the VS Code extension identifier to be the non-dev version
if BUILD_TYPE != "dev":
update_file(
os.path.join(root_dir, "vscode/package.json"),
r'"name": "qsharp-lang-vscode-dev",',
r'"name": "qsharp-lang-vscode",',
)
update_file(
os.path.join(root_dir, "vscode/package.json"),
r"[DEV BUILD] Azure Quantum Development Kit",
r"Azure Quantum Development Kit",
)
else:
# Update the README to contain the dev version contents
with open(
os.path.join(root_dir, "vscode/README-DEV.md"), "r", newline=""
) as dev_readme:
contents = dev_readme.read()
with open(os.path.join(root_dir, "vscode/README.md"), "w", newline="") as readme:
readme.write(contents)