-
Notifications
You must be signed in to change notification settings - Fork 0
/
package.py
83 lines (68 loc) · 3.07 KB
/
package.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
import subprocess
import json
import re
from git import Repo
def readVersionFromPackageJson() -> None:
packageJson = open("package.json", "r")
contentRaw = packageJson.read()
contentJson = json.loads(contentRaw)
packageJson.close()
return contentJson["version"]
def isPackageJsonVersionTagged(repo, packageJsonVersion) -> bool:
packageJsonVersionTagFound = False
for tag in repo.tags:
if tag.name == packageJsonVersion:
packageJsonVersionTagFound = True
break
return packageJsonVersionTagFound
def isChangeLogUpdatedWithPackageJsonVersion(packageJsonVersion) -> bool:
packageJsonVersionChangeLogEntryFound = False
changeLog = open("CHANGELOG.md", "r")
changeLogContent = changeLog.readlines()
changeLog.close()
for line in changeLogContent:
match = re.search(f"^## Version {packageJsonVersion}$", line)
if match:
packageJsonVersionChangeLogEntryFound = True
break
return packageJsonVersionChangeLogEntryFound
def isAllPackagesInstalledLocally() -> bool:
process = subprocess.Popen(["cmd", "/c", "npm", "list", "--production", "--parseable",
"--depth=99999", "--loglevel=error"], stderr=subprocess.PIPE)
out = process.stderr.read()
success = (len(out) == 0)
if (not success):
print(f"Error while checking if all packages is installed locally: {out}")
return success
def packageExtension() -> bool:
process = subprocess.Popen(["cmd", "/c", "vsce", "package"], stderr=subprocess.PIPE)
out = process.stderr.read()
success = (len(out) == 0)
if (not success):
print(f"Error while packaging: {out}")
return success
def main():
packageJsonVersion = readVersionFromPackageJson()
repo = Repo("./")
packageJsonVersionTagFound = isPackageJsonVersionTagged(repo, packageJsonVersion)
packageJsonVersionChangeLogEntryFound = isChangeLogUpdatedWithPackageJsonVersion(packageJsonVersion)
allPackagesInstalledLocally = isAllPackagesInstalledLocally()
if not packageJsonVersionChangeLogEntryFound:
print("Fail: CHANGELOG.md not updated.")
else:
if not allPackagesInstalledLocally:
print("Fail: Not all packages installed locally. Please run 'npm install' to install packages, or run 'npm list --production --parseable --depth=99999 --loglevel=error' to identify the issue.")
else:
if packageJsonVersionTagFound:
print(f"Fail: Version already tagged: {packageJsonVersion}.")
print("No vsix package created")
else:
print("Creating vsix package...")
isPackagingOk = packageExtension()
if not isPackagingOk:
print("Fail: Packaging failed.")
else:
print(f"New version found in package.json: {packageJsonVersion}.")
print("Creating tag in Git...")
repo.create_tag(packageJsonVersion)
main()