diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index fd188b803b35354004729b23712171c9ef2448ab..b91a8b2b04e2d0b957e2f8b8ba16dc6504eb247a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -37,7 +37,28 @@ variables: # Pre Stage Jobs # -commitlint: +changelog: + image: registry.dsop.io/platform-one/big-bang/pipeline-templates/pipeline-templates/pre-envs:ubi8.3 + stage: .pre + allow_failure: true + variables: + CHANGELOG_FILE: CHANGELOG.md + script: + - git fetch --all + - ./scripts/lint_changelog.sh + +version: + image: registry.dsop.io/platform-one/big-bang/pipeline-templates/pipeline-templates/pre-envs:ubi8.3 + stage: .pre + allow_failure: true + variables: + CHART_FILE: chart/Chart.yaml + BASEGIT_FILE: base/gitrepository.yaml + script: + - git fetch --all + - ./scripts/lint_version.sh + +commits: image: registry.dsop.io/platform-one/big-bang/pipeline-templates/pipeline-templates/pre-envs:ubi8.3 stage: .pre allow_failure: true @@ -45,7 +66,7 @@ commitlint: - dnf module install -y nodejs - npm install --only=dev - git fetch --all - - ./scripts/commitlint.sh + - ./scripts/lint_commits.sh pre vars: image: registry.dsop.io/platform-one/big-bang/pipeline-templates/pipeline-templates/pre-envs:ubi8.3 diff --git a/CHANGELOG b/CHANGELOG.md similarity index 100% rename from CHANGELOG rename to CHANGELOG.md diff --git a/scripts/lint_changelog.sh b/scripts/lint_changelog.sh new file mode 100755 index 0000000000000000000000000000000000000000..cd5278654805985acd427649c423bdc265dc2f09 --- /dev/null +++ b/scripts/lint_changelog.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +# diff the file silently, while still printing errors +git diff --exit-code origin/${CI_DEFAULT_BRANCH}:${CHANGELOG_FILE} ${CHANGELOG_FILE} >/dev/null + +# exit code of 0 indicates non changed file +if [ $? -eq 0 ]; then + echo "No changes were detected in ${CHANGELOG_FILE}, please update this file" + exit 1 +fi + +# exit code other than 0 and 1 is an error +# IE - different file names between branches +# check for this and fail accordingly +if [ $? -ne 1 ]; then + echo "Error: An unknown error has occurred while linting ${CHANGELOG_FILE}" + exit 1 +fi + +# default to success +exit 0 \ No newline at end of file diff --git a/scripts/commitlint.sh b/scripts/lint_commits.sh similarity index 100% rename from scripts/commitlint.sh rename to scripts/lint_commits.sh diff --git a/scripts/lint_version.sh b/scripts/lint_version.sh new file mode 100755 index 0000000000000000000000000000000000000000..4d5d53f3c33f2c8c0fcdc1fe2e3fad4596efbb16 --- /dev/null +++ b/scripts/lint_version.sh @@ -0,0 +1,64 @@ +#!/usr/bin/env bash + +# obtain the default chart version +chart_default_version=$(git show origin/${CI_DEFAULT_BRANCH}:${CHART_FILE} | grep -oP 'version: \K(.*)') + +# check for command error +if [ $? -ne 0 ]; then + echo "Error: An unknown error has occurred while attempting to retrieve the default version from ${CHART_FILE}" + exit 1 +fi + +# obtain the local chart version +chart_local_version=$(cat ${CHART_FILE} | grep -oP 'version: \K(.*)') + +# check for command error +if [ $? -ne 0 ]; then + echo "Error: An unknown error has occurred while attempting to retrieve the local version from ${CHART_FILE}" + exit 1 +fi + +# obtain the default base git repository tag +basegit_default_tag=$(git show origin/${CI_DEFAULT_BRANCH}:${BASEGIT_FILE} | grep -oP 'tag: \K(.*)') + +# check for command error +if [ $? -ne 0 ]; then + echo "Error: An unknown error has occurred while attempting to retrieve the default tag from ${BASEGIT_FILE}" + exit 1 +fi + +# obtain the local base git repository tag +basegit_local_tag=$(cat ${BASEGIT_FILE} | grep -oP 'tag: \K(.*)') + +# check for command error +if [ $? -ne 0 ]; then + echo "Error: An unknown error has occurred while attempting to retrieve the local tag from ${BASEGIT_FILE}" + exit 1 +fi + +# debug print +echo "Default branch chart version (${CHART_FILE}): $chart_default_version" +echo "Local branch chart version (${CHART_FILE}): $chart_local_version" + +# assume success +exit_code=0 + +# error if the versions are not different +if [[ "$chart_default_version" == "$chart_local_version" ]]; then + echo "The version has not been updated in ${CHART_FILE}, please update this file" + exit_code=1 +fi + +echo "--------------------------------------------------------" + +echo "Default branch base git repository tag (${BASEGIT_FILE}): $basegit_default_tag" +echo "Local branch base git repository tag (${BASEGIT_FILE}): $basegit_local_tag" + +# error if the versions are not different +if [[ "$chart_default_version" == "$chart_local_version" ]]; then + echo "The tag has not been updated in ${BASEGIT_FILE}, please update this file" + exit_code=1 +fi + +# exit with stored code +exit $exit_code \ No newline at end of file