tools/scripts/gitlab_release.sh
GnomeZworc b3c850eb7b
v1.2.0: release: first script for release on gitlab
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2024-03-21 15:56:14 +01:00

61 lines
No EOL
2.1 KiB
Bash

#!/bin/bash
exec_with_dry_run () {
if [[ ${1} -eq ${FLAGS_TRUE} ]]; then
echo "# ${2}"
else
eval "${2}" 2> /tmp/error || \
{
echo -e "failed with following error";
output=$(cat /tmp/error | sed -e "s/^/ error -> /g");
echo -e "${output}";
return 1;
}
fi
return 0
}
main () {
[[ -f ./libs/shflags ]] && . ./libs/shflags || eval "$(curl --silent https://gitlab.g3e.fr/h6n/tools/-/raw/main/libs/shflags)"
[[ -f ./.config/gitlab_release ]] && . ./.config/gitlab_release
DEFINE_string 'artifact_path' '' 'Path of artifact list' 'a'
DEFINE_boolean 'dryrun' false 'Enable dry-run mode' 'd'
DEFINE_string 'release_path' '' 'Release documentation path' 'r'
DEFINE_string 'skip_line' '2' 'Number of line to skip in release file' 's'
FLAGS "$@" || exit $?
eval set -- "${FLAGS_ARGV}"
[[ ${FLAGS_release_path} == "" ]] && \
{
echo "error release_path as to be filled"
return 1
}
NAME=$(cat ${FLAGS_release_path} | head -n 1 | cut -d\ -f 2)
VERSION=$(cat ${FLAGS_release_path} | head -n 1 | cut -d\ -f 3)
BODY=$(tail +${FLAGS_skip_line} ${FLAGS_release_path})
ASSET=$(ls ${FLAGS_artifact_path} | while read asset
do
asset_name=$(echo ${asset} | cut -d_ -f1)
echo -n " --assets-link '{\"name\":\"${asset}\",\"url\":\"${CI_API_V4_URL}/projects/${VERSION}/packages/generic/${asset_name}/${VERSION}/${asset}\",\"link_type\":\"package\"}'"
done
for docker in ${CONTAINER_LIST[@]}
do
echo -n " --assets-link '{\"name\":\"registry.g3e.fr/h6n/${docker}:${VERSION}\",\"url\":\"https://registry.g3e.fr/h6n/${docker}\",\"link_type\":\"image\"}'"
done)
echo "# ${NAME} ${VERSION}"
exec_with_dry_run ${FLAGS_dryrun} "release-cli create --name '${NAME}' --description '${BODY}' \
--tag-name '${VERSION}' --ref '${VERSION}' \
--milestone '${VERSION}' \
${ASSET}"
}
[[ "${BASH_SOURCE[0]}" == "${0}" ]] && (main "$@" || exit 1)
[[ "${BASH_SOURCE[0]}" == "" ]] && (main "$@" || exit 1)