prepare-release.py
Go to the documentation of this file.
1 #! /usr/bin/env python3
2 #
3 #
4 # C++ Insights, copyright (C) by Andreas Fertig
5 # Distributed under an MIT license. See LICENSE for details
6 #
7 #------------------------------------------------------------------------------
8 
9 import re
10 import os
11 import subprocess
12 #------------------------------------------------------------------------------
13 
14 def main():
15  versionH = open('version.h.in', 'r').read()
16 
17  oldClangStable = '17'
18  newClangStable = '18'
19  newInsightsVersion = '18.0'
20  oldInsightsVersion = re.search(r'INSIGHTS_VERSION\s+"(.*?)"', versionH, re.DOTALL | re.MULTILINE).group(1)
21 
22 
23  print('Preparing a new release:')
24  print(' Current Clang stable : %s' %(oldClangStable))
25  print(' New Clang stable : %s' %(newClangStable))
26  print(' Current Insights version : %s' %(oldInsightsVersion))
27  print(' New Insights version : %s' %(newInsightsVersion))
28 
29  print(' - Updating .github/workflows/ci.yml')
30  travis = open('.github/workflows/ci.yml', 'r').read()
31 
32  regEx = re.compile('[clang|llvm]-([0-9]+)')
33 
34  travis = re.sub(r'(clang|llvm|clang\+\+|llvm-config|llvm-toolchain-bionic|clang-format|clang-tidy|llvm-toolchain-trusty)(-%s)' %(oldClangStable), '\\1-%s' %(newClangStable) , travis)
35  travis = re.sub('(clang|Clang|llvm|LLVM) (%s)' %(oldClangStable), '\\1 %s' %(newClangStable) , travis)
36  travis = re.sub(r"(LLVM_VERSION=)('%s)" %(oldClangStable), r"\1'%s" %(newClangStable) , travis)
37  travis = re.sub(r"(LLVM_VERSION:)\s*(%s.0.0)" %(oldClangStable), r"\1 %s.0.0" %(newClangStable) , travis)
38  travis = re.sub(r'(llvm_version:\s*)("%s)(.0.0",)' %(oldClangStable), '\\1"%s.0.0",' %(newClangStable), travis)
39  travis = re.sub(r"clang(%s)0" %(oldClangStable), r"clang%s0" %(newClangStable) , travis)
40  travis = re.sub(r"(llvm-toolchain-xenial)-(%s)" %(oldClangStable), r"\1-%s" %(newClangStable) , travis)
41  travis = re.sub(r"(./llvm.sh) (%s)" %(oldClangStable), r"\1 %s" %(newClangStable) , travis)
42 
43 # print(travis)
44  open('.github/workflows/ci.yml', 'w').write(travis)
45 
46 
47  print(' - Updating CMakeLists.txt')
48  cmake = open('CMakeLists.txt', 'r').read()
49  cmake = re.sub(r'(set\‍(INSIGHTS_MIN_LLVM_MAJOR_VERSION)( %s)\‍)' %(oldClangStable), '\\1 %s)' %(newClangStable) , cmake)
50  open('CMakeLists.txt', 'w').write(cmake)
51 
52 
53  print(' - Updating version.h %s -> %s' %(oldInsightsVersion, newInsightsVersion))
54  version = open('version.h.in', 'r').read()
55  version = re.sub('(INSIGHTS_VERSION )"(.*)"', '\\1"%s"' %(newInsightsVersion) , version)
56  open('version.h.in', 'w').write(version)
57 
58 
59  print(' - Generating CHANGELOG.md')
60  os.system('gren changelog --override --username=andreasfertig --repo=cppinsights %s...continous' %(oldInsightsVersion))
61 
62  cmd = ['gren', 'changelog', '--override', '--username=andreasfertig', '--repo=cppinsights', '%s...continous' %(oldInsightsVersion)]
63  p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
64  stdout, stderr = p.communicate()
65 
66  if 0 != p.returncode:
67  print('ERR: gren failed')
68  print(stderr)
69  return 1
70 
71  changeLog = open('CHANGELOG.md', 'r').read()
72  changeLog = re.sub('(## Continuous build.*?---)\n', '', changeLog, flags=re.DOTALL)
73  open('CHANGELOG.md', 'w').write(changeLog)
74 
75  gitTag = 'v_%s' %(oldInsightsVersion)
76  print(' - Tagging %s' %(gitTag))
77 
78  #cmd = ['git', 'tag', '-a', '-m', gitTag, gitTag, 'main']
79  cmd = ['git', 'tag', gitTag, 'main']
80  p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
81  stdout, stderr = p.communicate()
82 
83  if 0 != p.returncode:
84  print('ERR: git tag failed!')
85  print(stderr)
86  return 1
87 
88  cppInsightsDockerBaseFile = '../cppinsights-docker-base/Dockerfile'
89 
90  print(' - Updating cppinsights-docker-base (%s)' %(cppInsightsDockerBaseFile))
91 
92  dockerFile = open(cppInsightsDockerBaseFile, 'r').read()
93  dockerFile = re.sub(r'(ENV\s+CLANG_VERSION=)([0-9]+)', r'\g<1>%s' %(newClangStable), dockerFile)
94  open(cppInsightsDockerBaseFile, 'w').write(dockerFile)
95 #------------------------------------------------------------------------------
96 
97 main()
98 #------------------------------------------------------------------------------
99