Continuous Integration repo reminders

For a number of projects I work on I pull in third party tools. Sometimes they’re straight copies - that’s what I inherited in some PHP projects I work on. But in others I use git subtree to pull them in.

However there’s a problem. I need a way to remind myself to check for updates. And generally I like things related to a project to live in the project. For my home projects I use Gitlab and their CI system. The config for which lives in my repo. So why not have the CI system check if the code is out of date?

First step is to script the updates. I have a repo where I store all my machine configuration which uses three third-party repos. The script to update it, scripts/update-3rd-party-src, works like so:

#!/bin/bash

set -e

git=/usr/bin/git

$git subtree pull -P roles/src/files/usr/local/src/cvssync \
     https://github.com/cvsync/cvsync.git master
$git subtree pull -P roles/src/files/usr/local/src/rcsparse \
     https://github.com/corecode/rcsparse.git master
$git subtree pull -P roles/src/files/usr/local/src/cvs2gitdump \
     https://github.com/yasuoka/cvs2gitdump.git master

date '+%s' > scripts/.update-3rd-party-src.stamp

This will pull down all changes in these repos and then update a stamp file with the current time. Usually stamp files use the file meta-data to track times, but git doesn’t maintain most file meta-data so the time tracking needs to be a bit more explicit.

All that’s left to do now is have Gitlab’s CI check the stamp file. In the .gitlab-ci.yml file this snippet exists:

test:
  type: test
  script:
    - ./hooks/gitlab/ci

And inside that script is this snippet:

# Check 3rd party sources have been updated recently (last 6 months).
if [ $(( $(date +%s) - $(cat scripts/.update-3rd-party-src.stamp) )) \
       -gt $(( 6 * 30 * 60 * 60 )) ]; then
  echo "Need to run ./scripts/update-3rd-party-src again."
  exit 1
fi

Now updates are tracked more explicitly in the tree and, due to that, reminders can be driven by the tree. Since the CI system actually manages the deployment and not just testing, this guarantees every six months I’ll at least give a little thought to updating the tools I’m using.