simply scripts alot, not the null check is necessray because gitlab ci regex with variables is weird and would contain errors otherwise.

limit pages to master run only, as we dont export scheduled pages
This commit is contained in:
Marcel Märtens 2022-04-06 21:08:29 +02:00
parent 203fe7ad47
commit 618d4b2340
6 changed files with 39 additions and 84 deletions

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -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:

View File

@ -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 &&

View File

@ -1,97 +1,49 @@
#!/bin/bash
### forbid setting SCHEDULE_CADENCE to v0.1.2 syntax
sanitize () {
### returns respective DOCKER TAG
### release-tag => <release-tag> (e.g. v1.2.3)
### schedule => <SCHEDULE_CADENCE> (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 => <SCHEDULE_CADENCE>
### 30 => <tag>
### 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 => <SCHEDULE_CADENCE>
### 30 => exit code 6
### else => exit code 7
### release-tag => "" (releases already have a tag)
### schedule => <SCHEDULE_CADENCE> (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;
}