This repository has been archived on 2021-06-21. You can view files and clone it, but cannot push or open issues or pull requests.
fbrinker-tileboard/build.sh
dev-docker f46f79bd4e feat(RELEASE): allow overriding build.sh
* add `ARG` for `RELEASE_URL`
* make `build.sh` prepare `.tags` even if tag exists
* add outputs to be used by github workflows
2021-05-20 20:19:36 +00:00

59 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env bash
getVersionFromLatestRelease() {
repo="${1-resoai/TileBoard}"
version=`curl -s "https://api.github.com/repos/$repo/releases/latest" \
| grep "tag_name" \
| cut -d '"' -f 4 \
| sed -e "s/v//"`
echo "$version"
}
getDownloadUrl() {
repo="${1-resoai/TileBoard}"
url=`curl -s "https://api.github.com/repos/$repo/releases/latest" \
| grep "browser_download_url" \
| cut -d '"' -f 4`
echo "$url"
}
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
}
source_repo="${1-resoai/TileBoard}"
docker_repo="${2-fbrinker/tileboard}"
echo "Source repository: $source_repo."
echo "Docker repository: $docker_repo."
LATEST_RELEASE=`getVersionFromLatestRelease $source_repo`
echo "Latest release is: $LATEST_RELEASE."
echo "::set-output name=latest_release::$LATEST_RELEASE"
SEMVER=( ${LATEST_RELEASE//./ } )
MAJOR=${SEMVER[0]}
MINOR=${SEMVER[0]}.${SEMVER[1]}
PATCH=$LATEST_RELEASE
echo "::set-output name=major::$MAJOR"
echo "::set-output name=minor::$MINOR"
echo "::set-output name=patch::$PATCH"
echo "latest,$MAJOR,$MINOR,$PATCH" > .tags
echo "::set-output name=tags::$(cat .tags)"
RELEASE_URL=`getDownloadUrl`
echo "URL of release is: $RELEASE_URL."
echo "::set-output name=release_url::$RELEASE_URL"
if docker_tag_exists $docker_repo $LATEST_RELEASE; then
echo "Nothing to do. Latest release tag already exists."
exit 78 # drone.io exit code to stop but success the pipeline
fi
echo "Writing release URL into Dockerfile..."
sed -i "s|%RELEASE_URL%|$RELEASE_URL|g" ./Dockerfile