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

Some operations can fail if the date/time is not the expected one #96

Merged
merged 1 commit into from
May 30, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ function next_utc_time() {
local time="${1}" # Time in HH:MM:SS format.
local now # Current time in seconds.
local next # To calculate the next time in seconds.
now=$(date -u +%s)
next=$(date -u -d "$(date -u -d @"${now}" +"%Y-%m-%d $time")" +%s)
now=$(LC_ALL=C date -u +%s)
next=$(LC_ALL=C date -u -d "$(LC_ALL=C date -u -d @"${now}" +"%Y-%m-%d $time")" +%s)
if [ "${now}" -gt "${next}" ]; then # If the time has already passed today.
next=$(date -u -d "$(date -u -d @"${next}") +1 day" +%s)
next=$(LC_ALL=C date -u -d "$(LC_ALL=C date -u -d @"${next}") +1 day" +%s)
fi
echo "${next}" # Return the next time in seconds.
}
4 changes: 2 additions & 2 deletions prerelease.sh
Original file line number Diff line number Diff line change
Expand Up @@ -513,11 +513,11 @@ fi
# Before anything else, let's check if, right now, it's a good time to run this script.

# Calculate a few timestamps (unix seconds since epoch).
curr=$(date -u +%s) # Now
curr=$(LC_ALL=C date -u +%s) # Now
publ=$(next_utc_time "${PUBLISHING_TIME}") # Publishing time UTC.

# Calculate some local and interval times.
publlocal=$(date -d @"${publ}" +'%H:%M:%S %Z') # Publishing time in local time.
publlocal=$(LC_ALL=C date -d @"${publ}" +'%H:%M:%S %Z') # Publishing time in local time.
prevention=$((publ - PREVENT_MINUTES * 60)) # Begin of prevention time.

# If we are within the prevention time, let's prevent and exit.
Expand Down
6 changes: 3 additions & 3 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ for b in "${allbranches[@]}" ; do
# We very-rarely should face this, as far as the pre-release script already detects
# 99% of cases, but this is a last-resort check.
comm=$(git log -n1 --pretty=format:"%ct" origin/"${b}") # Last commit time in seconds.
curr=$(date -u +%s) # Now in seconds.
publ=$(date -u -d "${PUBLISHING_TIME}" +%s) # Publishing time in seconds.
publlocal=$(date -d @"${publ}" +'%H:%M:%S %Z') # Publishing time in local time.
curr=$(LC_ALL=C date -u +%s) # Now in seconds.
publ=$(LC_ALL=C date -u -d "${PUBLISHING_TIME}" +%s) # Publishing time in seconds.
publlocal=$(LC_ALL=C date -d @"${publ}" +'%H:%M:%S %Z') # Publishing time in local time.

if [ "${comm}" -lt "${publ}" ] && [ "${curr}" -gt "${publ}" ]; then
output " ${Y}Between the last commit and now, the packaging server${N}"
Expand Down