cache and skip commits that have passed already

Commits marked as passed can be re-run by changing their hash or
clearing the cache.
This commit is contained in:
Charles Hall 2024-11-01 12:45:03 -07:00
parent 2265b6615e
commit 976aef690f
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF

21
bin/job
View file

@ -30,6 +30,19 @@ bail() (
exit 1
)
mark_commit_passed() (
set -euo pipefail
mkdir -p ".gitlab-ci.d/passed/$1"
touch ".gitlab-ci.d/passed/$1/$(git rev-parse HEAD)"
)
commit_passed() (
set -euo pipefail
[[ -f ".gitlab-ci.d/passed/$1/$(git rev-parse HEAD)" ]]
)
run() (
set -euo pipefail
@ -59,7 +72,15 @@ run() (
<(git rev-list --reverse "$CI_MERGE_REQUEST_DIFF_BASE_SHA..HEAD")
for commit in "${commits[@]}"; do
git checkout "$commit"
if commit_passed "$job"; then
echo "Skipping commit because it already passed: $commit"
continue
fi
job_"$job" || bail
mark_commit_passed "$job"
done
fi
)