From faa767ee08b921ab35931f9504a764c4d77c5624 Mon Sep 17 00:00:00 2001 From: GnomeZworc Date: Tue, 2 Apr 2024 23:53:24 +0200 Subject: [PATCH] v1.2.0: script: add a gitlab-ci script Signed-off-by: GnomeZworc --- config-ci/.gitlab-ci.yml.j2 | 58 +++++++++++++++++++++++++++++++++++ config/params.json | 2 ++ scripts/update_ci.sh | 60 +++++++++++++++++++++++++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 config-ci/.gitlab-ci.yml.j2 create mode 100644 config/params.json create mode 100755 scripts/update_ci.sh diff --git a/config-ci/.gitlab-ci.yml.j2 b/config-ci/.gitlab-ci.yml.j2 new file mode 100644 index 0000000..172757e --- /dev/null +++ b/config-ci/.gitlab-ci.yml.j2 @@ -0,0 +1,58 @@ +default: + image: debian:11 + +stages: + - build + - publish + - release + +build: + stage: build + image: golang:1.21-alpine + before_script: + - apk update && apk add --no-cache make git + script: + - make build_password + artifacts: + paths: + - ./bin/* + +publish_main: + stage: publish + image: golang:1.21-alpine + variables: + VER: latest + before_script: + - apk update && apk add --no-cache make git curl + script: + - make publish_password + needs: + - build + only: + - main + +release_tag: + stage: publish + image: golang:1.21-alpine + variables: + VER: ${CI_COMMIT_TAG} + before_script: + - apk update && apk add --no-cache make git curl + script: + - make publish_password + needs: + - 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 \ No newline at end of file diff --git a/config/params.json b/config/params.json new file mode 100644 index 0000000..7a73a41 --- /dev/null +++ b/config/params.json @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file diff --git a/scripts/update_ci.sh b/scripts/update_ci.sh new file mode 100755 index 0000000..4cec188 --- /dev/null +++ b/scripts/update_ci.sh @@ -0,0 +1,60 @@ +#!/bin/sh + +#list="build deploy latest release test" + +#for elem in ${list} +#do +# echo "Build ${elem}" +# j2 -f json \ +# .gitlab/templates/${elem}.yml.j2 \ +# .gitlab/templates/.container_list.json \ +# -o .gitlab/ci/${elem}.yml +#done + +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)" + + DEFINE_boolean 'dryrun' false 'Enable dry-run mode' 'd' + DEFINE_string 'output_path' '' 'Release documentation path' 'o' + DEFINE_string 'template_path' '' 'Path of artifact list' 't' + DEFINE_string 'params_path' '' 'Path of artifact list' 'p' + + FLAGS "$@" || exit $? + eval set -- "${FLAGS_ARGV}" + + exec_with_dry_run ${FLAGS_dryrun} "pip install j2cli" > /dev/null + + ls -a ${FLAGS_template_path} | while read TEMPLATE + do + file=$(echo ${TEMPLATE} | grep -Ev '^[\.]*$') + [[ ${file} != "" ]] && \ + { + basename=$(echo ${file%.*}) + exec_with_dry_run ${FLAGS_dryrun} "j2 -f json ${FLAGS_template_path}/${file} ${FLAGS_params_path} -o ${FLAGS_output_path}/${basename}" + } + done +} + +[[ "${BASH_SOURCE[0]}" == "${0}" ]] && \ + { + main "$@" && exit 0 || exit 1 + } +[[ "${BASH_SOURCE[0]}" == "" ]] && \ + { + main "$@" && exit 0 || exit 1 + } \ No newline at end of file