Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update knife to pick the latest snapshot closest to "yesterday" #1580

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions knife
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,19 @@ function cmd_lock() {

function find_latest_snapshot() {
local type="$1"
local current="$(date +%Y-%m-01)"
# If it's the first of the month, look at the last month, otherwise this -1 day has no effect since searches
# occur at the "month" level. This is an intentional buffer added to get the snapshots fully hydrated. We
# intentionally don't include complicated logic for the case where it's after the 1st and no snapshots are
# availalbe for the month (it's extremely unlikely for our updater to run into this situation unless the
# snapshot serving infrastructure is acting up).
local current="$(date -d '-1 day' +%Y-%m-%d)"
local tmp=$(mktemp)
for _ in 1 2; do
local q=$(date -d "$current" +"year=%Y&month=%m")
if curl -fs "https://snapshot-cloudflare.debian.org/archive/debian/?$q" | grep -ohE "([0-9]+T[0-9]+Z)" > $tmp; then
break
fi
echo "Could not find snapshot at $current, going back a month" >&2
# go back 1 month
current="$(date -d "$current -1 month" +%Y-%m-01)"
done
cat $tmp | grep -ohE "([0-9]+T[0-9]+Z)" | head -n1
local q=$(date -d "$current" +"year=%Y&month=%m")
if curl -fs "https://snapshot-cloudflare.debian.org/archive/debian/?$q" | grep -ohE "([0-9]+T[0-9]+Z)" > $tmp; then
# same logic as above, find the newest snapshot that isn't "today"
today=$(date +"%Y%m%dT")
cat $tmp | grep -v $today | tail -n1
fi
}

function cmd_update_snapshots() {
Expand Down Expand Up @@ -153,7 +154,7 @@ test)
cmd_test
;;
~~nocmd) # no command provided
echo "provide a command: lock"
echo "provide a command: lock, update-snapshots, github-update-snapshots, test"
exit 1
;;
*) # unknown command
Expand Down
Loading