trim-reports: always run repack and prune
[puppet-git.git] / ppg-reports-to-dashboard
blobc4ea87064f1825373317d3bf1d6c9c07a18cafdd
1 #!/bin/bash
3 if [[ -n "${PPG_DEBUG}" ]]; then
4 set -x
5 fi
7 export GIT_DIR=${1:-/var/lib/ppg/reports-import.git}
8 pushd ${GIT_DIR} >/dev/null
10 if [[ "$(git config --get --bool core.bare)" != 'true' ]]; then
11 echo >&2 "ERROR: must run on a bare repository"
12 exit 1
15 trackdir=/var/lib/ppg/reports-import.track
16 reportstmpdir=$(mktemp -d --tmpdir=/var/tmp ppg-reports-to-dashboard.XXXXXXX )
17 seenany=no
19 for head in $(git branch | /bin/grep -v '(no branch)' ); do
20 lastimportstate=
21 if [ -e ${trackdir}/${head} ]; then
22 lastimportstate=$(<${trackdir}/${head})
25 if [ -n "${lastimportstate}" ]; then
26 # we have a local head, walk deltas
27 logparams="${lastimportstate}..refs/heads/${head}"
28 else
29 # Initial import will take only two days
30 # of old reports
31 logparams=" --since=2.days.ago refs/heads/${head}"
33 # !? - the last line of git log has no \n so tac returns a
34 # first line that runs together the last two lines. workaround injecting
35 # a newline...
36 for commit in $( (git log --pretty=format:%H ${logparams} && echo '') | tac); do
37 seenany=yes
38 # the branchname is the hostname
39 fname=reports/${head}.yaml
40 epoch=$(git show -s --pretty=format:%ct ${commit})
41 # magic:
42 # - get the file without checking out the commit
43 # - store it in a tmpdir for later import with rake
44 git show ${commit}:${fname} > ${reportstmpdir}/${epoch}-$head.yaml
45 echo ${commit} > ${trackdir}/${head}
46 done
47 done
48 if [ "${seenany}" = 'yes' ]; then
49 pushd /usr/share/puppet-dashboard >/dev/null
50 rake RAILS_ENV=production reports:import REPORT_DIR=${reportstmpdir} | grep -v 'ETA:.*Importing:'
51 popd >/dev/null
54 # the rake/import process needs the file to stick around for a while
55 # and does not delete it when done, so this is fugly
56 find /var/tmp -type d -name 'ppg-reports-to-dashboard.*' -user puppet-dashboard -mmin +120 -print0 | \
57 xargs -0 --no-run-if-empty -L 100 rm -fr