Files
simple-laravel/gen-tag-list.sh
2024-08-26 13:42:10 +02:00

30 lines
740 B
Bash
Executable File

#!/usr/bin/env ash
# this script generates a tags_file for Buildx (https://woodpecker-ci.org/plugins/Docker%20Buildx)
# Check if a command-line argument is provided
if [ -z "$1" ]; then
echo "Please provide a version as a command-line argument."
exit 1
fi
# Example v2.0.1
version=$1
# Suffix
[[ -n $2 ]] && suffix="-$2" || suffix=""
# Check if the first character is "V" or "v" and remove it
if [[ "${version:0:1}" == "V" || "${version:0:1}" == "v" ]]; then
version="${version#?}"
fi
# Split the version into an array using the "." as a delimiter
# this sets $1 $2 and $3
IFS='.' set -- "$version"
echo "latest$suffix" > tags.txt
echo "$1$suffix" >> tags.txt
echo "$1.$2$suffix" >> tags.txt
echo "$1.$2.$3$suffix" >> tags.txt