# 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 . 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']))