-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tasks.py
197 lines (155 loc) · 5.48 KB
/
tasks.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
import sys
import time
import psutil
import json
import os
import subprocess
import shutil
from pathlib import Path
from glob import glob
from invoke import task
from galaxy.tools import zip_folder_to_file
import github
with open('src/manifest.json') as f:
__version__ = json.load(f)['version']
REQUIREMENTS = 'requirements/app.in'
REQUIREMENTS_DEV = 'requirements/dev.in'
REQUIREMENTS_LOCK = 'requirements/lock/app.txt'
REQUIREMENTS_DEV_LOCK = 'requirements/lock/dev.txt'
GALAXY_PATH = ''
DIST_DIR = ''
GALAXY_PYTHONPATH = ''
if sys.platform == 'win32':
PLATFORM = 'Windows'
GALAXY_PATH = 'C:\\Program Files (x86)\\GOG Galaxy\\GalaxyClient.exe'
DIST_DIR = os.environ['localappdata'] + '\\GOG.com\\Galaxy\\plugins\\installed'
PYTHON = 'python'
GALAXY_PYTHONPATH = str(Path(os.path.expandvars("%programfiles(x86)%")) / "GOG Galaxy" / "python" / "python.exe")
elif sys.platform == 'darwin':
PLATFORM = 'Mac'
GALAXY_PATH = "/Applications/GOG Galaxy.app/Contents/MacOS/GOG Galaxy"
DIST_DIR = os.environ['HOME'] + r"/Library/Application\ Support/GOG.com/Galaxy/plugins/installed"
PYTHON = 'python3'
DIST_PLUGIN = os.path.join(DIST_DIR, 'osu')
THIRD_PARTY_RELATIVE_DEST = 'modules'
def get_repo():
token = os.environ['GITHUB_TOKEN']
g = github.Github(token)
return g.get_repo('UncleGoogle/galaxy-integration-osu')
def asset_name(tag, platform):
return f'osu_{tag}_{platform[:3].lower()}.zip'
@task
def install(c, dev=False):
req = REQUIREMENTS_DEV_LOCK if dev else REQUIREMENTS_LOCK
c.run(f"{PYTHON} -m pip install -r {req}")
@task
def lock(c, dev=False):
req_in = REQUIREMENTS_DEV if dev else REQUIREMENTS
req_out = REQUIREMENTS_DEV_LOCK if dev else REQUIREMENTS_LOCK
c.run(f"pip-compile --generate-hashes --output-file={req_out} {req_in}")
@task
def build(c, output=DIST_PLUGIN):
print(f'Preparing build to folder `{output}`')
output = Path(output).resolve()
print('Removing', output)
if os.path.exists(output):
try:
shutil.rmtree(output)
except OSError as e:
if hasattr(e, 'winerror') and e.winerror in [145, 5]:
# something e.g. antivirus check holds a file. Try to wait to be released for a moment
time.sleep(3)
shutil.rmtree(output)
else:
raise
print('Copying source code to ', str(output))
shutil.copytree('src', output, ignore=shutil.ignore_patterns(
'__pycache__', '.mypy_cache', 'tests'))
args = [
PYTHON, "-m", "pip", "install",
"-r", REQUIREMENTS_LOCK,
"--target", str(output / THIRD_PARTY_RELATIVE_DEST),
# "--implementation", "cp",
# "--python-version", "37",
# "--no-deps"
]
print(f'Running `{" ".join(args)}`')
subprocess.check_call(args)
@task
def dist(c, output=DIST_PLUGIN, deps=False):
this_plugin = 'plugin-egg'
for proc in psutil.process_iter(attrs=['exe'], ad_value=''):
if proc.info['exe'] == GALAXY_PYTHONPATH:
if this_plugin in proc.cmdline()[-1]:
print(f'Running plugin instance found!. Terminating...')
proc.terminate()
break
if not deps:
print('Build without dependencies')
os.makedirs(output, exist_ok=True)
copy(c, output)
else:
build(c, output)
print("Now, click 'retry' for crashed plugin in Settings")
@task
def copy(c, output=DIST_PLUGIN):
print(f'Copying source code to {output}')
for file_ in glob("src/*.py"):
shutil.copy(file_, output)
shutil.copy('CHANGELOG.md', output)
@task
def test(c):
c.run('pytest')
@task
def archive(c, zip_name=None, target=None):
if target is None:
build(c, 'build')
target = 'build'
if zip_name is None:
zip_name = f'osu_{__version__}.zip'
print(f'Zipping build from `{target}` to `{zip_name}`')
zip_folder_to_file(target, zip_name)
zip_path = Path('.') / zip_name
return str(zip_path.resolve())
@task(aliases=['tag'])
def create_tag(c, tag=None):
if tag is None:
tag = 'v' + __version__
branch = c.run("git rev-parse --abbrev-ref HEAD").stdout.strip()
print(f'New tag version will be: [{tag}] on [{branch}] branch. Is it OK? (make sure new version is committed)')
if input('y/n').lower() != 'y':
return
print(f'Creating and pushing a new tag `{tag}`.')
c.run(f'git tag {tag}')
c.run(f'git push origin {tag}')
@task
def release(c, automa=False):
tag = 'v' + __version__
if automa:
print(f'Creating/updating release with assets for {PLATFORM} to version {tag}')
else:
print(f'New tag version for release will be: {tag}. is it OK?')
if input('y/n').lower() != 'y':
return
repo = get_repo()
for release in repo.get_releases():
if release.tag_name == tag and release.draft:
draft_release = release
break
else:
print('No draft release with given tag found.')
if not automa:
create_tag(c, tag)
print(f'Creating new release for tag `{tag}`')
draft_release = repo.create_git_release(
tag=tag,
name=__version__,
message="draft",
draft=True,
prerelease=not automa
)
build(c, output='build')
test(c)
asset_path = archive(c, target='build', zip_name=asset_name(tag, PLATFORM))
print(f'Uploading asset for {PLATFORM}: {asset_path}')
draft_release.upload_asset(asset_path)