tools/scripts/release.sh
GnomeZworc c4cb5506fa
1.4.0: script: add correct script
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2025-09-28 16:37:01 +02:00

85 lines
No EOL
3.2 KiB
Bash
Executable file

#!/bin/bash
SED_PARAM=""
unameOut="$(uname -s)"
case "${unameOut}" in
Linux*) SED_PARAM=" -i ";;
Darwin*) SED_PARAM=" -i '' ";;
*) exit 1
esac
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
}
edit_file () {
dryrun=${1}
cmd=${2}
file=${3}
exec_with_dry_run "${1}" "${2}" || return 1
exec_with_dry_run "${1}" "git add ${3}" || return 1
return 0
}
main () {
[[ -f ./libs/shflags ]] && . ./libs/shflags || eval "$(curl --silent https://git.g3e.fr/H6N/tools/raw/branch/main/libs/shflags)"
DEFINE_string 'tag' 'v0.0.0' 'Version' 't'
DEFINE_string 'name' 'totor' 'Nom de la version' 'n'
DEFINE_boolean 'create_branch' false 'Creation de la branch' 'c'
DEFINE_boolean 'dryrun' false 'Enable dry-run mode' 'd'
DEFINE_string 'release_path' './docs/release' 'Release path' 'p'
DEFINE_string 'doc_path' './docs/release.md' 'Documentation path' 'u'
DEFINE_string 'regex_version' 'v[0-9]*.[0-9]*.[0-9]*' 'Version Regex' 'r'
FLAGS "$@" || exit $?
eval set -- "${FLAGS_ARGV}"
NAME=${FLAGS_name}
VERSION=${FLAGS_tag}
# Creation de la branch
# . -c -t (version) -n (name)
if [[ ${FLAGS_create_branch} -eq ${FLAGS_TRUE} ]]; then
echo "Create Release ${NAME} - ${VERSION}"
exec_with_dry_run "${FLAGS_dryrun}" "git checkout -b release-${VERSION}" || exit 1
exec_with_dry_run "${FLAGS_dryrun}" "sed -e 's/NAME VERSION/${NAME} ${VERSION}/' ${FLAGS_release_path}/.template.md > ${FLAGS_release_path}/next_release.md" || return 1
exit 0
fi
NAME=$(cat ${FLAGS_release_path}/next_release.md | head -n 1 | cut -d\ -f 2)
VERSION=$(cat ${FLAGS_release_path}/next_release.md | head -n 1 | cut -d\ -f 3)
LOWER_NAME=$(echo ${NAME} | tr '[:upper:]' '[:lower:]')
# Release standard
BRANCH=$(git branch --show-current)
if [[ "${BRANCH}" == "release-${VERSION}" ]]; then
echo "Release ${NAME} - ${VERSION}"
echo "Edit README file"
edit_file "${FLAGS_dryrun}" "sed ${SED_PARAM} 's/^${FLAGS_regex_version}: [A-Z|a-z| ]*$/${VERSION}: ${NAME}/' ./README.md" "./README.md" || return 1
edit_file "${FLAGS_dryrun}" "sed ${SED_PARAM} '/^## Release list$/a\\
- [${VERSION} ${NAME}](${FLAGS_release_path}/${VERSION}_${LOWER_NAME}.md)' ${FLAGS_doc_path}" "${FLAGS_doc_path}" || return 1
edit_file "${FLAGS_dryrun}" "mv '${FLAGS_release_path}/next_release.md' '${FLAGS_release_path}/${VERSION}_${LOWER_NAME}.md'" "${FLAGS_release_path}/${VERSION}_${LOWER_NAME}.md" || return 1
exec_with_dry_run "${FLAGS_dryrun}" "git commit -s -S -m 'release-${VERSION}'" || return 1
exec_with_dry_run "${FLAGS_dryrun}" "git tag '${VERSION}' -s -m 'Release ${VERSION} ${NAME}'" || return 1
fi
}
[[ "${BASH_SOURCE[0]}" == "${0}" ]] && (main "$@" || exit 1)
[[ "${BASH_SOURCE[0]}" == "" ]] && (main "$@" || exit 1)