diff --git a/Jenkinsfile.update b/Jenkinsfile.update index f93ed84..5d255e0 100644 --- a/Jenkinsfile.update +++ b/Jenkinsfile.update @@ -48,7 +48,27 @@ node { sh 'bashbrew --library .doi/library fetch $(cat subset.txt)' // TODO --all } stage('Sources') { - sh '.scripts/sources.sh $(cat subset.txt) > sources.json' + 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 + fi + if [ -n "$needsUpdate" ]; then + .scripts/sources.sh $(cat subset.txt) > sources.json + fi + ''' } stage('Builds') { sh '.scripts/builds.sh sources.json > builds.json' @@ -56,8 +76,11 @@ node { } stage('Commit') { sh ''' - git add -A . - git commit -m 'Update and regenerate' || : + # 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 commit -m 'Update and regenerate' + fi ''' } sshagent(['docker-library-bot']) {