From 8efc4d3f242a1a3530167b5c76d41caa5c3b14a8 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Mon, 23 Jul 2018 14:40:27 +0300 Subject: Add: pipelines/get_sources.ick --- pipelines/get_sources.ick | 67 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 pipelines/get_sources.ick (limited to 'pipelines') 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 -- cgit v1.2.1