-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.py
86 lines (69 loc) · 2.3 KB
/
build.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
#! /usr/bin/env python3
import os
import os.path
import re
import shutil
import subprocess
projects = [
'FactoryFactory',
'FactoryFactory.AspNet.DependencyInjection'
]
version = '0.4.0'
suffix = 'beta'
is_release = False
def abspath(path):
home = os.path.abspath(os.path.dirname(__file__))
return os.path.normpath(os.path.join(home, path))
def dotnet(*args):
process = ["dotnet"] + list(args)
subprocess.run(process, check=True)
build_number = os.environ.get('APPVEYOR_BUILD_NUMBER', '0')
pull_request_number = os.environ.get('APPVEYOR_PULL_REQUEST_NUMBER', False)
if os.environ.get('APPVEYOR_REPO_TAG', False) == 'true':
is_release = True
version_number = re.search(r'^\d+\.\d+\.\d+', version)
if version_number:
version_number = version_number.group()
file_version = version_number + '.' + build_number
else:
file_version = False
if pull_request_number:
package_version = version + '-pr' + pull_request_number
else:
package_version = version
if suffix and suffix != '':
package_version += '-' + suffix
package_path = abspath('build')
os.makedirs(abspath('src/.version'), exist_ok=True)
with open(abspath('src/.version/version.cs'), 'w') as f:
f.writelines([
'using System.Reflection;\n'
'\n',
'[assembly:AssemblyInformationalVersion("{0}")]\n'.format(package_version)
])
if file_version:
f.writelines([
'[assembly:AssemblyVersion("{0}")]\n'.format(file_version),
'[assembly:AssemblyFileVersion("{0}")]\n'.format(file_version)
])
shutil.rmtree(abspath('build'), ignore_errors=True)
dotnet('build', abspath('src/FactoryFactory.sln'))
dotnet('test', abspath('src/FactoryFactory.Tests/FactoryFactory.Tests.csproj'))
for project in projects:
dotnet(
'pack',
'-o', package_path,
'--no-build',
abspath('src/{0}/{0}.csproj'.format(project))
)
if is_release:
key = os.environ.get('NUGET_KEY', False)
if key:
for f in os.listdir(package_path):
artifact = os.path.join(package_path, f)
if artifact.endswith('.nupkg') and os.path.isfile(artifact):
dotnet(
'nuget', 'push', artifact,
'-k', key,
'-s', 'https://api.nuget.org/v3/index.json'
)