diff --git a/Jenkinsfile.update b/Jenkinsfile.update index 5d255e0..a3ab6c7 100644 --- a/Jenkinsfile.update +++ b/Jenkinsfile.update @@ -50,23 +50,25 @@ node { stage('Sources') { sh ''' # we only need to regenerate "sources.json" if ".doi", ".scripts", or "subset.txt" have changed since we last generated it - needsUpdate= - if ! git diff --exit-code .doi .scripts; then - # if .doi or .scripts updated in this job ("git submodule update" above) - needsUpdate=1 - else - # if subset.txt, .doi, or .scripts updated outside this job (merged PR, etc) - sourcesCommit="$(git log -1 --format='format:%H' -- sources.json)" - for f in subset.txt .doi .scripts; do - commit="$(git log -1 --format='format:%H' -- "$f")" - if ! git merge-base --is-ancestor "$commit" "$sourcesCommit"; then - needsUpdate=1 - break - fi - done + + needsBuild= + if [ ! -s commits.json ] || [ ! -s sources.json ]; then + needsBuild=1 + fi + + doi="$(git -C .doi log -1 --format='format:%H')" + scripts="$(git -C .scripts log -1 --format='format:%H')" + subset="$(sha256sum subset.txt | cut -d' ' -f1)" + export doi scripts subset + jq -n '{ doi: env.doi, scripts: env.scripts, subset: env.subset }' | tee commits.json + if [ -z "$needsBuild" ] && ! git diff --exit-code commits.json; then + needsBuild=1 fi - if [ -n "$needsUpdate" ]; then - .scripts/sources.sh $(cat subset.txt) > sources.json + + if [ -n "$needsBuild" ]; then + images="$(cat subset.txt)" + [ -n "$images" ] + .scripts/sources.sh $images > sources.json fi ''' } @@ -76,9 +78,8 @@ node { } stage('Commit') { sh ''' - # only commit submodule updates if our JSON has changed (see https://github.com/docker-library/meta-scripts/pull/8) - if ! git diff --exit-code sources.json builds.json; then - git add -A . + git add -A . + if ! git diff --staged --exit-code; then # commit fails if there's nothing to commit git commit -m 'Update and regenerate' fi '''