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
|
# Lars Wirzenius, with help from Daniel Silverstone.
#
# Feel free to use this as you wish. It is simple enough that it is
# probably not even copyrightable.
pipelines:
# Get sources from git servers, as specified in the "sources"
# parameter. The sources are mirrored into ".mirrors" at the root of
# the workspace. This pipeline then constructs a source from the
# mirrored source trees.
#
# The "sources" parameter is a list of dicts, each dict having the
# fields "name", "repo", "location", and "ref":
#
# sources:
# - name: foo
# repo: git://git.example.com/foo.git
# location: src
# ref: master
# - name: foo-debian
# repo: git://git.example.com/foo-debian.git
# location: src/debian
# ref: master
#
# The above would clone the foo.git and foo-debian.git repositories
# and check them out as src and src/debian, respectively, at the
# root of the workspace. In both checkouts the master branch is
# checked out.
#
# If the checkouts already existed, "git pull" is run in them. This
# allows the workspace to persist across builds, and subsequent
# builds will only pull changes into the mirrored git repositories,
# and from there to the workspaces. The project's build system can
# then build only the changed parts.
#
# This pipeline needs to run with a container having Python3 and git
# installed.
- pipeline: get_sources
parameters:
- sources
actions:
- action: git_mirror
where: host
- python: |
import os, re, subprocess
def RUN(*args, cwd=None):
print('Executing:', args, 'cwd:', cwd)
subprocess.check_call(args, cwd=cwd)
sources = params['sources']
for source in sources:
name = source['name']
dirname = source['location']
ref = source['ref']
ref_is_sha = re.match('^[a-fA-F0-9]+$', ref) is not None
mirror = os.path.join('.mirrors', name)
if os.path.exists(dirname):
RUN('git', 'checkout', ref, cwd=dirname)
# Only pull if in a branch.
head = open('{}/.git/HEAD'.format(dirname)).read().strip()
if head.startswith('ref:'):
RUN('git', 'pull', cwd=dirname)
else:
# Initial clone. Handle ref being a commit id specially.
if re.match('^[a-fA-F0-9]+$', ref):
RUN('git', 'clone', mirror, dirname)
RUN('git', 'checkout', ref, cwd=dirname)
else:
RUN('git', 'clone', '-b', ref, mirror, dirname)
where: container
|