forked from linvi/tweetinvi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtweetinvi-builder.py
executable file
·210 lines (150 loc) · 7.7 KB
/
tweetinvi-builder.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#! /usr/local/bin/python3
import os
import re
import glob
import argparse
import sys
from shutil import copyfile, rmtree
from pathlib import Path
parser = argparse.ArgumentParser()
parser.add_argument('--version', nargs=1, default='5.0.4')
parser.add_argument('--pre', nargs=1, default='')
parser.add_argument('--build-version', action='store_true')
parser.add_argument('--nuget-push', action='store_true')
args = parser.parse_args()
version = args.version
nugetVersion = version + args.pre
if args.build_version:
print(nugetVersion)
sys.exit(0)
if args.nuget_push:
print('This is going to publish 3 packages on nuget.org as version' + nugetVersion + '. Please confirm by typing "continue"')
answer = input()
if answer == 'continue':
print('publishing on nuget...')
os.system('cd TweetinviAPI && nuget push TweetinviAPI.' + nugetVersion + '.nupkg -Source nuget.org')
os.system('cd TweetinviAPI-Symbols && nuget push TweetinviAPI.' + nugetVersion + '.snupkg -Source nuget.org')
os.system('cd TweetinviAspNet && nuget push TweetinviAPI.AspNetPlugin.' + nugetVersion + '.nupkg -Source nuget.org')
else:
print('nuget push aborted')
sys.exit(0)
srcFolders = os.listdir('../src/')
tweetinviProjects = list(filter(lambda folder: "Tweetinvi" in folder, srcFolders))
def replace(filepath, regex, with_content):
with open(filepath, 'r') as file:
filedata = file.read()
filedata = re.sub(regex, with_content, filedata)
with open(filepath, 'w') as file:
file.write(filedata)
def remove_files_in(path):
files = glob.glob(path + '/*')
for f in files:
os.remove(f)
def createPath(path):
try:
os.makedirs(path)
except FileExistsError:
print("Directory ", path, " already exists")
def update_version():
nuspecVersionRegex = re.compile(r'<version>.*</version>')
nuspecNewVersion = '<version>' + nugetVersion + '</version>'
replace('./TweetinviAPI/TweetinviAPI.nuspec', nuspecVersionRegex, nuspecNewVersion)
replace('./TweetinviAPI-Symbols/TweetinviAPI-Symbols.nuspec', nuspecVersionRegex, nuspecNewVersion)
replace('./TweetinviAspNet/TweetinviAPI.AspNetPlugin.nuspec', nuspecVersionRegex, nuspecNewVersion)
nugetDependency = '<dependency id="TweetinviAPI" version="' + nugetVersion + '" />'
aspnetPluginTweetinviDependencyVersionRegex = re.compile(r'<dependency id="TweetinviAPI" version=".*" \/>')
replace('./TweetinviAspNet/TweetinviAPI.AspNetPlugin.nuspec', aspnetPluginTweetinviDependencyVersionRegex, nugetDependency)
userAgentRegex = re.compile(r'"User-Agent",\s"Tweetinvi/.+"')
replace('../src/Tweetinvi.WebLogic/TwitterClientHandler.cs', userAgentRegex, '"User-Agent", "Tweetinvi/' + nugetVersion + '"')
print('updated nuspec versions to ' + version)
csprojVersionRegex = re.compile(r'<VersionPrefix>.*</VersionPrefix>')
csprojNewVersion = '<VersionPrefix>' + version + '</VersionPrefix>'
for projectPath in tweetinviProjects:
filePath = '../src/' + projectPath + '/' + projectPath + '.csproj'
print('updating ' + projectPath + ' version to ' + version)
replace(filePath, csprojVersionRegex, csprojNewVersion)
def clean_build():
print('Cleaning build folders')
releasePath = '../src/Tweetinvi/bin/'
if os.path.exists(releasePath):
rmtree(releasePath)
releasePath = '../src/Tweetinvi.AspNet/bin/'
if os.path.exists(releasePath):
rmtree(releasePath)
def compile_tweetinvi():
print('Compiling Tweetinvi...')
os.system('dotnet build -c release ../src/Tweetinvi')
os.system('dotnet build -c release ../src/Tweetinvi.AspNet')
def clean_nuget_folder():
print('Cleaning nuget build...')
cachePackagePath = 'C:/Users/linvi/.nuget/packages/tweetinviapi/' + version
if os.path.exists(cachePackagePath):
rmtree(cachePackagePath)
cachePackagePath = 'C:/Users/linvi/.nuget/packages/tweetinviapi.aspnetplugin/' + version
if os.path.exists(cachePackagePath):
rmtree(cachePackagePath)
files = glob.glob('./TweetinviAPI/*.nupkg')
for f in files:
os.remove(f)
remove_files_in('./TweetinviAPI/lib/netstandard1.4')
remove_files_in('./TweetinviAPI/lib/netstandard2.0')
createPath('./TweetinviAPI/lib/netstandard1.4')
createPath('./TweetinviAPI/lib/netstandard2.0')
files = glob.glob('./TweetinviAPI-Symbols/*.snupkg')
for f in files:
os.remove(f)
remove_files_in('./TweetinviAPI-Symbols/lib/netstandard1.4')
remove_files_in('./TweetinviAPI-Symbols/lib/netstandard2.0')
createPath('./TweetinviAPI-Symbols/lib/netstandard1.4')
createPath('./TweetinviAPI-Symbols/lib/netstandard2.0')
files = glob.glob('./TweetinviAspNet/*.nupkg')
for f in files:
os.remove(f)
createPath('./TweetinviAspNet/lib/netstandard2.0')
remove_files_in('./TweetinviAspNet/lib/netcoreapp2.1')
remove_files_in('./TweetinviAspNet/lib/netcoreapp3.1')
createPath('./TweetinviAspNet/lib/netstandard2.0')
createPath('./TweetinviAspNet/lib/netcoreapp2.1')
createPath('./TweetinviAspNet/lib/netcoreapp3.1')
def build_tweetinvi_nuget_package():
print('Building nuget package...')
tweetinviBuildFiles = os.listdir('../src/Tweetinvi/bin/release/netstandard2.0')
tweetinviDllFiles = list(filter(re.compile(r'.*\.dll').search, tweetinviBuildFiles))
tweetinviXmlFiles = list(filter(re.compile(r'.*\.xml').search, tweetinviBuildFiles))
for dll in tweetinviDllFiles:
copyfile('../src/Tweetinvi/bin/release/netstandard1.4/' + dll, './TweetinviAPI/lib/netstandard1.4/' + dll)
copyfile('../src/Tweetinvi/bin/release/netstandard2.0/' + dll, './TweetinviAPI/lib/netstandard2.0/' + dll)
for xml in tweetinviXmlFiles:
copyfile('../src/Tweetinvi/bin/release/netstandard1.4/' + xml, './TweetinviAPI/lib/netstandard1.4/' + xml)
copyfile('../src/Tweetinvi/bin/release/netstandard2.0/' + xml, './TweetinviAPI/lib/netstandard2.0/' + xml)
os.system('cd TweetinviAPI && nuget pack')
def build_tweetinvi_nuget_symbols():
print('building symbols package')
tweetinviBuildFiles = os.listdir('../src/Tweetinvi/bin/release/netstandard2.0')
symbolsFilter = re.compile(r'.*\.pdb')
tweetinviSymbolFiles = list(filter(symbolsFilter.search, tweetinviBuildFiles))
for pdb in tweetinviSymbolFiles:
copyfile('../src/Tweetinvi/bin/release/netstandard1.4/' + pdb, './TweetinviAPI-Symbols/lib/netstandard1.4/' + pdb)
copyfile('../src/Tweetinvi/bin/release/netstandard2.0/' + pdb, './TweetinviAPI-Symbols/lib/netstandard2.0/' + pdb)
os.system('cd TweetinviAPI-Symbols && nuget pack')
os.rename('./TweetinviAPI-Symbols/TweetinviAPI.' + nugetVersion + '.nupkg', './TweetinviAPI-Symbols/TweetinviAPI.' + nugetVersion + '.snupkg')
def build_aspNet_nuget_package():
def copy_aspnet_file(filepath):
copyfile('../src/Tweetinvi.AspNet/bin/release/' + filepath, './TweetinviAspNet/lib/' + filepath)
Path("./TweetinviAspNet/lib/netstandard2.0").mkdir(parents=True, exist_ok=True)
Path("./TweetinviAspNet/lib/netcoreapp2.1").mkdir(parents=True, exist_ok=True)
Path("./TweetinviAspNet/lib/netcoreapp3.1").mkdir(parents=True, exist_ok=True)
copy_aspnet_file('netstandard2.0/Tweetinvi.AspNet.dll')
copy_aspnet_file('netstandard2.0/Tweetinvi.AspNet.xml')
copy_aspnet_file('netcoreapp2.1/Tweetinvi.AspNet.dll')
copy_aspnet_file('netcoreapp2.1/Tweetinvi.AspNet.xml')
copy_aspnet_file('netcoreapp3.1/Tweetinvi.AspNet.dll')
copy_aspnet_file('netcoreapp3.1/Tweetinvi.AspNet.xml')
os.system('cd TweetinviAspNet && nuget pack')
update_version()
clean_build()
compile_tweetinvi()
clean_nuget_folder()
build_tweetinvi_nuget_package()
build_tweetinvi_nuget_symbols()
build_aspNet_nuget_package()