2022-02-10 17:27:00 +00:00
|
|
|
#!/bin/bash
|
2024-10-16 19:22:38 +00:00
|
|
|
|
|
|
|
branch=$1
|
|
|
|
output_file=$2
|
|
|
|
# Grabs the last 10 commit SHA's from the given branch, then purges any commits that do not have a passing CI build
|
2022-02-10 17:27:00 +00:00
|
|
|
iterations=0
|
2024-10-16 19:22:38 +00:00
|
|
|
commits_str=$(curl -s -H 'Accept: application/vnd.github.v3+json' "https://api.github.com/repos/k3s-io/k3s/commits?per_page=10&sha=$branch" | jq -j -r '.[] | .sha, " "')
|
|
|
|
read -a commits <<< "$commits_str"
|
|
|
|
|
|
|
|
# The VMs take time on startup to hit aws, wait loop until we can
|
2022-11-28 17:27:43 +00:00
|
|
|
while ! curl -s --fail https://k3s-ci-builds.s3.amazonaws.com > /dev/null; do
|
2022-03-02 20:42:55 +00:00
|
|
|
((iterations++))
|
|
|
|
if [ "$iterations" -ge 30 ]; then
|
2022-11-28 17:27:43 +00:00
|
|
|
echo "Unable to hit https://k3s-ci-builds.s3.amazonaws.com"
|
2022-03-02 20:42:55 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
|
2024-10-16 19:22:38 +00:00
|
|
|
for commit in "${commits[@]}"; do
|
|
|
|
if curl -s --fail https://k3s-ci-builds.s3.amazonaws.com/k3s-$commit.sha256sum > /dev/null; then
|
|
|
|
echo "$commit" > "$output_file"
|
|
|
|
exit 0
|
2022-02-10 17:27:00 +00:00
|
|
|
fi
|
2023-03-31 20:26:29 +00:00
|
|
|
done
|
2024-10-16 19:22:38 +00:00
|
|
|
|
|
|
|
echo "Failed to find a valid commit, checked: " "${commits[@]}"
|
|
|
|
exit 1
|