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
|
# Copyright (C) 2018 Lars Wirzenius
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import base64, json, os, subprocess, sys
import cliapp
import yaml
def RUN(*args, cwd=None):
# print('Executing:', args, 'cwd:', cwd)
with open('/dev/null', 'w') as f:
kwargs = {'stdout': f, 'stderr': f}
# kwargs = {}
return subprocess.check_call(args, cwd=cwd, **kwargs)
def find_pipeline(obj, name):
for p in obj['pipelines']:
if p['pipeline'] == name:
return p
assert 0
obj = yaml.safe_load(sys.stdin)
get_sources = find_pipeline(obj, 'get_sources')
actions = get_sources['actions']
actions = [a for a in actions if 'python' in a]
assert len(actions) == 1
code = actions[0]['python']
print('Setting up workspace, simulating git_mirror action')
RUN('rm', '-rf', 'workspace')
RUN('mkdir', 'workspace')
RUN('mkdir', 'workspace/.mirrors')
RUN('git', 'clone', '--mirror', 'git://git.liw.fi/heippa', 'workspace/.mirrors/heippa')
heippa = {
'name': 'heippa',
}
params = {
'sources': [
{
'name': 'heippa',
'location': 'master',
'ref': 'master',
'HEAD': 'ref: refs/heads/master',
},
{
'name': 'heippa',
'location': 'foo',
'ref': 'liw/foo',
'HEAD': 'ref: refs/heads/liw/foo',
},
{
'name': 'heippa',
'location': 'tag',
'ref': 'heippa-0.4',
'HEAD': 'f1b343f846c8f38d8e3bc35bc28064b46291676d'
},
{
'name': 'heippa',
'location': 'sha',
'ref': '58fffbf8b8aba0660f1759674c1ac818789b7d45',
'HEAD': '58fffbf8b8aba0660f1759674c1ac818789b7d45',
},
],
}
params_encoded = base64.b64encode(json.dumps(params).encode('UTF-8')).decode('UTF-8')
preamble = '''
import base64, json
params_encoded = '{}'
params = json.loads(base64.b64decode(params_encoded))
'''.format(params_encoded)
print('Execute pipeline to check everything out initially')
RUN('python3', '-c', preamble + code, cwd='workspace')
print('Check that all is checked out OK')
for src in params['sources']:
filename = 'workspace/{}/.git/HEAD'.format(src['location'])
data = open(filename).read().strip()
assert data == src['HEAD']
print('{} checked out OK'.format(src['name']))
print('Make every checkout have the wrong branch checked out')
for src in params['sources']:
RUN('git', 'checkout', 'wrong', cwd='workspace/{}'.format(src['location']))
print('Execute pipeline to update exiting checkouts')
RUN('python3', '-c', preamble + code, cwd='workspace')
print('Check that all is checked out OK again')
for src in params['sources']:
filename = 'workspace/{}/.git/HEAD'.format(src['location'])
data = open(filename).read().strip()
assert data == src['HEAD']
print('{} checked out OK'.format(src['name']))
|