Skip to content

Commit

Permalink
Merge pull request #9 from infosiftr/commits.json
Browse files Browse the repository at this point in the history
Implement `commits.json` that tracks whether `sources.json` is potentially outdated
  • Loading branch information
yosifkit authored Dec 15, 2023
2 parents 88f2840 + eb7251f commit 21eba83
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions Jenkinsfile.update
Original file line number Diff line number Diff line change
Expand Up @@ -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
'''
}
Expand All @@ -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
'''
Expand Down

0 comments on commit 21eba83

Please sign in to comment.