summaryrefslogtreecommitdiff
path: root/pipelines
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2018-07-23 14:40:27 +0300
committerLars Wirzenius <liw@liw.fi>2018-07-23 14:40:27 +0300
commit8efc4d3f242a1a3530167b5c76d41caa5c3b14a8 (patch)
treeee63998856c4c5c2a9b25a9450943d325339a5ce /pipelines
parent18210d8ff0282426daecb1a7d31085bfeda0430e (diff)
downloadick2-8efc4d3f242a1a3530167b5c76d41caa5c3b14a8.tar.gz
Add: pipelines/get_sources.ick
Diffstat (limited to 'pipelines')
-rw-r--r--pipelines/get_sources.ick67
1 files changed, 67 insertions, 0 deletions
diff --git a/pipelines/get_sources.ick b/pipelines/get_sources.ick
new file mode 100644
index 0000000..94c72bf
--- /dev/null
+++ b/pipelines/get_sources.ick
@@ -0,0 +1,67 @@
+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