From 7acbe3d55ee2ebd18f354b000cf1ed703e2c4e75 Mon Sep 17 00:00:00 2001 From: Florian Brinker Date: Mon, 10 May 2021 22:03:02 +0200 Subject: [PATCH] Fix date handling for ISO8601 dates --- check-master-for-changes.sh | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/check-master-for-changes.sh b/check-master-for-changes.sh index 8f3c77d..b8c860e 100755 --- a/check-master-for-changes.sh +++ b/check-master-for-changes.sh @@ -1,13 +1,23 @@ #!/usr/bin/env bash -commitdate=$(curl -sL "https://api.github.com/repos/resoai/TileBoard/commits/master" | jq -r ".commit.author.date") -commitdays=$(( ( $(date --utc +%s) - $(date --utc -d $commitdate +%s) ) / 86400 )) -echo "Last commit was $commitdays days ago." +docker_tag_exists() { + repo="${1-fbrinker/tileboard}" + tag="${2-nightly}" + curl --silent -f -lSL "https://hub.docker.com/v2/repositories/$repo/tags/$tag" > /dev/null 2>&1 +} -if [ $commitdays -lt 2 ] ; then - echo "There ARE recent changes in the repository." +commitdate=$(curl -sL "https://api.github.com/repos/resoai/TileBoard/commits/master" | jq -r ".commit.author.date" | sed 's/T/ /; s/Z//') +commitdays=$(( ( $(date --utc +%s) - $(date --utc -d "$commitdate" +%s) ) / 86400 )) +echo "Last commit was $commitdate and is $commitdays days ago." + +if [ $commitdays -lt 2 ]; then + echo "Found recent commits in the repository." + echo "Continuing with pipeline..." +elif [ !docker_tag_exists ]; then + echo "Missing an nightly build." + echo "Continuing with pipeline..." else - echo "There are NO recent changes in the repository." + echo "No recent commits found." echo "Aborting pipeline." exit 78 # drone.io exit code to stop but success the pipeline fi \ No newline at end of file