diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9120aac50a..f48bb18ac6 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -14,6 +14,7 @@ variables: GIT_DEPTH: 3 GIT_CLEAN_FLAGS: -f CACHE_IMAGE_TAG: d7756444 + TAG_REGEX: '/^v[0-9]+\.[0-9]+\.[0-9]+$/' default: # https://docs.gitlab.com/ee/ci/pipelines/settings.html#auto-cancel-pending-pipelines diff --git a/.gitlab/CI/check.gitlab-ci.yml b/.gitlab/CI/check.gitlab-ci.yml index ad23e01a9e..a8a6b100ed 100644 --- a/.gitlab/CI/check.gitlab-ci.yml +++ b/.gitlab/CI/check.gitlab-ci.yml @@ -1,10 +1,11 @@ -# cargo clippy is a superset of cargo check, so we don't check manually code-quality: extends: .recompile-branch stage: check image: registry.gitlab.com/veloren/veloren-docker-ci/cache/quality:${CACHE_IMAGE_TAG} tags: ["veloren/veloren", "check"] script: + - echo $CI_COMMIT_TAG + - echo $TAG_REGEX - ln -s /dockercache/target target - cat ./.gitlab/scripts/code-quality.sh - source ./.gitlab/scripts/code-quality.sh diff --git a/.gitlab/CI/publish.gitlab-ci.yml b/.gitlab/CI/publish.gitlab-ci.yml index 212063a953..7b64cc065b 100644 --- a/.gitlab/CI/publish.gitlab-ci.yml +++ b/.gitlab/CI/publish.gitlab-ci.yml @@ -8,10 +8,6 @@ - when: never before_script: - source "$CI_PROJECT_DIR/.gitlab/scripts/utils.sh" - - publishtype PUBLISH_TYPE - - publishdockertag PUBLISH_DOCKER_TAG - - publishgittag PUBLISH_GIT_TAG - - echo "Publish detected '$PUBLISH_TYPE' Docker Tag '$PUBLISH_DOCKER_TAG' Git Tag '$PUBLISH_GIT_TAG'" docker: extends: .publish @@ -29,7 +25,8 @@ docker: - export container=docker - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json - | - if [[ ! -z "${PUBLISH_DOCKER_TAG}" ]]; then + publishdockertag PUBLISH_DOCKER_TAG + if [ "${PUBLISH_DOCKER_TAG}" != "" ]; then /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/server-cli/Dockerfile --destination "${CI_REGISTRY_IMAGE}/server-cli:${PUBLISH_DOCKER_TAG}" fi @@ -43,13 +40,16 @@ gittag: - git config --global http.postBuffer 52428800 - git remote set-url origin https://veloren-bot:${GITLAB_TOKEN_WRITE}@${CI_PROJECT_URL:8} - | - if [[ ! -z "${PUBLISH_GIT_TAG}" ]]; then + publishgittag PUBLISH_GIT_TAG + if [ "${PUBLISH_GIT_TAG}" != "" ]; then git tag -a "${PUBLISH_GIT_TAG}" -m '' -f; git push origin "${PUBLISH_GIT_TAG}" -f; fi pages: extends: .publish + rules: + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_PIPELINE_SOURCE != "schedule" image: registry.gitlab.com/veloren/veloren-docker-ci/cache/quality:${CACHE_IMAGE_TAG} tags: ["veloren/veloren", "publish"] artifacts: diff --git a/.gitlab/CI/release.yml b/.gitlab/CI/release.yml index f1b91ccaa5..680f6c2646 100644 --- a/.gitlab/CI/release.yml +++ b/.gitlab/CI/release.yml @@ -2,7 +2,7 @@ .optional-release: stage: check rules: - - if: $CI_PIPELINE_SOURCE != "merge_request_event" || $CI_PIPELINE_SOURCE == "schedule" || $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+/ + - if: $CI_PIPELINE_SOURCE != "merge_request_event" || $CI_PIPELINE_SOURCE == "schedule" || ( $CI_COMMIT_TAG != null && $CI_COMMIT_TAG =~ $TAG_REGEX ) when: never - when: manual allow_failure: true @@ -11,7 +11,7 @@ .release: stage: build rules: - - if: $CI_PIPELINE_SOURCE != "merge_request_event" && ($CI_PIPELINE_SOURCE == "schedule" || $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+/) + - if: $CI_PIPELINE_SOURCE != "merge_request_event" && ( $CI_PIPELINE_SOURCE == "schedule" || $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || ( $CI_COMMIT_TAG != null && $CI_COMMIT_TAG =~ $TAG_REGEX ) ) when: on_success - when: never retry: diff --git a/.gitlab/scripts/code-quality.sh b/.gitlab/scripts/code-quality.sh index 5e63fdffb0..60b7285084 100755 --- a/.gitlab/scripts/code-quality.sh +++ b/.gitlab/scripts/code-quality.sh @@ -1,4 +1,5 @@ #!/bin/bash +# cargo clippy is a superset of cargo check, so we don't check manually time cargo clippy --all-targets --locked --features="bin_cmd_doc_gen,bin_compression,bin_csv,bin_graphviz,bin_bot,bin_asset_migrate,asset_tweak" -- -D warnings && # Ensure that the veloren-voxygen default-publish feature builds as it excludes some default features time cargo clippy -p veloren-voxygen --locked --no-default-features --features="default-publish" -- -D warnings && diff --git a/.gitlab/scripts/util.sh b/.gitlab/scripts/util.sh index 28f9a54d0a..2ad34607cc 100755 --- a/.gitlab/scripts/util.sh +++ b/.gitlab/scripts/util.sh @@ -1,97 +1,49 @@ #!/bin/bash -### forbid setting SCHEDULE_CADENCE to v0.1.2 syntax -sanitize () { +### returns respective DOCKER TAG +### release-tag => (e.g. v1.2.3) +### schedule => (e.g. nightly) +### master => "master" +### else => "" +publishdockertag () { +# this stores the result in a variable defined by the caller local -n VAR=$1 -INPUT=$2 -if [[ "${INPUT}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+ ]]; then - echo "---WARN---SANITIZE---ACTIVE---" - VAR=""; - return 1; -fi -VAR="${INPUT}"; -} - -### returns the respective type of publish for the ci -### 0 => optional build/no publish -### 10 => master build -### 20 => scheduled build -### 30 => release build -publishtype () { -local -n VAR=$1 -if [[ "${CI_COMMIT_TAG}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+ ]]; then - VAR=30; +VAR=""; +if [[ "${CI_COMMIT_TAG}" =~ ${TAG_REGEX} ]]; then + VAR="${CI_COMMIT_TAG}"; return 0; fi if [[ -z "${SCHEDULE_CADENCE}" && ${CI_PIPELINE_SOURCE} == "schedule" ]]; then - VAR=20; + # sanitize check + if [[ "${SCHEDULE_CADENCE}" =~ ${TAG_REGEX} ]]; then + VAR="invalid_cadence"; + else + VAR="${SCHEDULE_CADENCE}"; + fi return 0; fi if [[ ${CI_COMMIT_BRANCH} == ${CI_DEFAULT_BRANCH} ]]; then - VAR=10; - return 0; -fi -VAR=0; -} - -### returns respective DOCKER TAG -### 0 => exit code 3 -### 10 => master -### 20 => -### 30 => -### else => exit code 7 - -publishdockertag () { -local -n VAR=$1 -INPUT=$2 -if [[ "${INPUT}" == "0" ]]; then - VAR=""; - return 3; -fi -if [[ "${INPUT}" == "10" ]]; then VAR="master"; return 0; fi -if [[ "${INPUT}" == "20" ]]; then - VAR="${SCHEDULE_CADENCE}"; - sanitize $1 "${VAR}"; - return 0; -fi -if [[ "${INPUT}" == "30" ]]; then - VAR="${CI_COMMIT_TAG}"; - return 0; -fi -VAR=""; -return 7; } ### returns respective GIT TAG -### 0 => exit code 3 -### 10 => exit code 4 -### 20 => -### 30 => exit code 6 -### else => exit code 7 - +### release-tag => "" (releases already have a tag) +### schedule => (e.g. nightly) +### master => "" (master doesn't need a tag) +### else => "" publishgittag () { local -n VAR=$1 -INPUT=$2 -if [[ "${INPUT}" == "0" ]]; then - VAR=""; - return 3; -fi -if [[ "${INPUT}" == "10" ]]; then - VAR=""; - return 4; -fi -if [[ "${INPUT}" == "20" ]]; then +if [[ -z "${SCHEDULE_CADENCE}" && ${CI_PIPELINE_SOURCE} == "schedule" ]]; then VAR="${SCHEDULE_CADENCE}"; - sanitize $1 "${VAR}"; - return 0; -fi -if [[ "${INPUT}" == "30" ]]; then - VAR="${CI_COMMIT_TAG}"; + # sanitize check + if [[ "${SCHEDULE_CADENCE}" =~ ${TAG_REGEX} ]]; then + VAR="invalid_cadence"; + else + VAR="${SCHEDULE_CADENCE}"; + fi return 0; fi VAR=""; -return 7; } \ No newline at end of file