From b3c850eb7b812e7d7302340421d5fc9a0a7f2a7f Mon Sep 17 00:00:00 2001 From: GnomeZworc Date: Thu, 21 Mar 2024 13:59:37 +0100 Subject: [PATCH] v1.2.0: release: first script for release on gitlab Signed-off-by: GnomeZworc --- .gitlab-ci.yml | 14 +++++++- docs/release/v0.3.0_nicolas.md | 7 ++++ scripts/gitlab_release.sh | 61 ++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 docs/release/v0.3.0_nicolas.md create mode 100644 scripts/gitlab_release.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6f51382..172757e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -43,4 +43,16 @@ release_tag: needs: - build only: - - tags \ No newline at end of file + - 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 \ No newline at end of file diff --git a/docs/release/v0.3.0_nicolas.md b/docs/release/v0.3.0_nicolas.md new file mode 100644 index 0000000..1884b8d --- /dev/null +++ b/docs/release/v0.3.0_nicolas.md @@ -0,0 +1,7 @@ +# Nicolas v0.3.0 + +## Release feature + +- toto +- tata +- arno diff --git a/scripts/gitlab_release.sh b/scripts/gitlab_release.sh new file mode 100644 index 0000000..ecc5f88 --- /dev/null +++ b/scripts/gitlab_release.sh @@ -0,0 +1,61 @@ +#!/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) \ No newline at end of file