Merge branch '7-issue' into 'main'

add release script gitlab-ci

Closes #7

See merge request h6n/tools!3
This commit is contained in:
Nicolas Boufidjeline 2024-03-21 17:35:42 +00:00
commit c51c50d261
3 changed files with 88 additions and 1 deletions

View file

@ -44,3 +44,15 @@ release_tag:
- build
only:
- tags
release_job:
stage: release
image: registry.gitlab.com/gitlab-org/release-cli:latest
rules:
- if: $CI_COMMIT_TAG
before_script:
- apk update && apk add --no-cache bash curl
script:
- bash ./scripts/gitlab_release.sh -r ./docs/release/$CI_COMMIT_TAG* -a ./bin/
needs:
- build

View file

@ -0,0 +1,7 @@
# Nicolas v0.3.0
## Release feature
- toto
- tata
- arno

68
scripts/gitlab_release.sh Normal file
View file

@ -0,0 +1,68 @@
#!/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} "/usr/local/bin/release-cli create --name '${NAME}' --description '${BODY}' \
--tag-name '${VERSION}' --ref '${VERSION}' \
--milestone '${VERSION}' \
${ASSET}"
return 0
}
[[ "${BASH_SOURCE[0]}" == "${0}" ]] && \
{
main "$@" && exit 0 || exit 1
}
[[ "${BASH_SOURCE[0]}" == "" ]] && \
{
main "$@" && exit 0 || exit 1
}