From 3a26978408478b4c661b8400e544d5b1884c9155 Mon Sep 17 00:00:00 2001 From: Zachariah Dzielinski <dzielinski_zachariah@bah.com> Date: Tue, 19 Jan 2021 11:28:32 -0700 Subject: [PATCH] ci: added linting for changelog and version --- .gitlab-ci.yml | 23 +++++++++++++++++++---- CHANGELOG => CHANGELOG.md | 0 scripts/lint_changelog.sh | 21 +++++++++++++++++++++ scripts/lint_version.sh | 28 ++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 4 deletions(-) rename CHANGELOG => CHANGELOG.md (100%) create mode 100755 scripts/lint_changelog.sh create mode 100755 scripts/lint_version.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index fd188b803b..63e782707d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -37,15 +37,30 @@ variables: # Pre Stage Jobs # +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: + - ./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 + script: + - ./scripts/lint_version.sh + commitlint: image: registry.dsop.io/platform-one/big-bang/pipeline-templates/pipeline-templates/pre-envs:ubi8.3 stage: .pre allow_failure: true script: - - dnf module install -y nodejs - - npm install --only=dev - - git fetch --all - - ./scripts/commitlint.sh + - ./scripts/lint_version.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 0000000000..62df767edb --- /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 ${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/lint_version.sh b/scripts/lint_version.sh new file mode 100755 index 0000000000..af7af82590 --- /dev/null +++ b/scripts/lint_version.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +# obtain the default version +default_version=$(git show ${CI_DEFAULT_BRANCH}:${CHART_FILE} | ggrep -oP 'version: \K(.*)') + +# check for command error +if [ $? -ne 0 ]; then + echo "Error: An unknown error has occurred when attempting to retrieve the default version" + exit 1 +fi + +# obtain the local version +local_version=$(cat ${CHART_FILE} | ggrep -oP 'version: \K(.*)') + +# check for command error +if [ $? -ne 0 ]; then + echo "Error: An unknown error has occurred when attempting to retrieve the local version" + exit 1 +fi + +# debug print +echo "Default version: $default_version" +echo "Local version: $local_version" + +# error if the versions are not different +if [[ "$default_version" == "$local_version" ]]; then + echo "The version has not been updated in ${CHART_FILE}, please update this file" +fi \ No newline at end of file -- GitLab