2021-03-20 17:28:40 +00:00
#!/usr/bin/env bash
getVersionFromLatestRelease( ) {
2021-05-10 15:17:20 +00:00
repo = " ${ 1 -resoai/TileBoard } "
version = ` curl -s " https://api.github.com/repos/ $repo /releases/latest " \
2021-03-20 17:28:40 +00:00
| grep "tag_name" \
| cut -d '"' -f 4 \
| sed -e "s/v//" `
2021-05-10 15:17:20 +00:00
2021-03-20 17:28:40 +00:00
echo " $version "
}
2021-04-22 20:27:46 +00:00
getDownloadUrl( ) {
2021-05-10 15:17:20 +00:00
repo = " ${ 1 -resoai/TileBoard } "
url = ` curl -s " https://api.github.com/repos/ $repo /releases/latest " \
2021-03-20 17:28:40 +00:00
| grep "browser_download_url" \
| cut -d '"' -f 4`
2021-05-10 15:17:20 +00:00
2021-04-22 20:27:46 +00:00
echo " $url "
2021-03-20 17:28:40 +00:00
}
2021-05-10 15:17:20 +00:00
docker_tag_exists( ) {
repo = " ${ 1 -fbrinker/tileboard } "
tag = " ${ 2 -latest } "
curl --silent -f -lSL " https://hub.docker.com/v2/repositories/ $repo /tags/ $tag " > /dev/null 2>& 1
2021-04-21 21:39:23 +00:00
}
2021-05-10 15:17:20 +00:00
source_repo = " ${ 1 -resoai/TileBoard } "
2021-05-10 16:23:41 +00:00
docker_repo = " ${ 2 -fbrinker/tileboard } "
2021-05-10 15:17:20 +00:00
echo " Source repository: $source_repo . "
2021-05-10 16:23:41 +00:00
echo " Docker repository: $docker_repo . "
2021-05-10 15:17:20 +00:00
LATEST_RELEASE = ` getVersionFromLatestRelease $source_repo `
echo " Latest release is: $LATEST_RELEASE . "
2021-04-21 21:39:23 +00:00
2021-05-10 16:23:41 +00:00
if docker_tag_exists $docker_repo $LATEST_RELEASE ; then
2021-05-10 15:17:20 +00:00
echo "Nothing to do. Latest release tag already exists."
2021-04-22 20:28:49 +00:00
exit 78 # drone.io exit code to stop but success the pipeline
2021-04-21 21:39:23 +00:00
fi
SEMVER = ( ${ LATEST_RELEASE //./ } )
2021-03-20 17:28:40 +00:00
MAJOR = ${ SEMVER [0] }
MINOR = ${ SEMVER [0] } .${ SEMVER [1] }
2021-04-21 21:39:23 +00:00
PATCH = $LATEST_RELEASE
2021-03-20 17:28:40 +00:00
2021-03-20 17:41:30 +00:00
echo " latest, $MAJOR , $MINOR , $PATCH " > .tags
2021-03-20 17:28:40 +00:00
2021-04-22 20:27:46 +00:00
RELEASE_URL = ` getDownloadUrl`
2021-05-10 15:17:20 +00:00
echo " URL of release is: $RELEASE_URL . "
2021-03-20 17:28:40 +00:00
2021-05-10 15:17:20 +00:00
echo "Writing release URL into Dockerfile..."
2021-04-22 20:27:46 +00:00
sed -i " s|%RELEASE_URL%| $RELEASE_URL |g " ./Dockerfile