# 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: ick/get_sources parameters: - sources actions: - action: git_mirror where: host - python: | import os, re 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', 'clean', '-fdx', cwd=dirname) RUN('git', 'reset', '--hard', cwd=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