Merge lp:~adam-collard/ols-jenkaas/detect-git-changes-again into lp:~ols-jenkaas-admins/ols-jenkaas/trunk

Proposed by Adam Collard
Status: Merged
Merged at revision: 590
Proposed branch: lp:~adam-collard/ols-jenkaas/detect-git-changes-again
Merge into: lp:~ols-jenkaas-admins/ols-jenkaas/trunk
Diff against target: 29 lines (+8/-4)
1 file modified
project/detect-changes (+8/-4)
To merge this branch: bzr merge lp:~adam-collard/ols-jenkaas/detect-git-changes-again
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Guillermo Gonzalez Approve
Review via email: mp+343598@code.launchpad.net

Commit message

Don't blindly copy the tip to the old_tip - munge it in place

Description of the change

Previous attempts at munging the old_tip were buggy:
 - bash and awk quoting/escaping bugs
 - truncation of input file which was also output file later in the pipeline

This version was tested in a subshell with REFS and OLD_TIP defined.

Verified that the environment has the necessary version (>= 4.1.0) of gawk installed (actually 4.1.3)

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
591. By Adam Collard

Replace gawk wonder with simpler printf

Revision history for this message
Guillermo Gonzalez (verterok) wrote :

LGTM, let's try it!

review: Approve
Revision history for this message
Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'project/detect-changes'
2--- project/detect-changes 2018-04-14 03:17:53 +0000
3+++ project/detect-changes 2018-04-19 11:23:24 +0000
4@@ -25,8 +25,9 @@
5 OLD_TIP_URL=${JENKINS_URL}/job/${JOB_NAME}/lastSuccessfulBuild/artifact/tip
6 OLD_TIP=${WORKSPACE}/old_tip
7
8-# wget will create an empty file if the artifact doesn't exist
9-wget -q ${OLD_TIP_URL} -O ${OLD_TIP} || echo > ${OLD_TIP}
10+touch ${OLD_TIP}
11+# Assume out of date if we've lost the history of the last successful build
12+wget -q ${OLD_TIP_URL} -O ${OLD_TIP} || true
13
14 # Introspect
15 . ~/.config/jenkaas/environment
16@@ -50,8 +51,11 @@
17 bzr version-info --custom --template ${INFO} "{revision_id}" ${TRUNK} > ${TIP}
18 else
19 git ls-remote ${TRUNK} $REFS > ${TIP}
20- # if refs don't match, ignore it
21- grep ${REFS} ${OLD_TIP} || cp ${TIP} ${OLD_TIP} || true
22+ # if refs don't match, we munge the old tip to look like current tip.
23+ if ! grep "$REFS" "$OLD_TIP" > /dev/null ; then
24+ printf '%s\t%s\n' "$(cut -f1 "$OLD_TIP")" "$REFS" > "$OLD_TIP.new"
25+ mv "$OLD_TIP.new" "$OLD_TIP"
26+ fi
27 fi
28
29 # Succeed if a new tip appears

Subscribers

People subscribed via source and target branches