Other: Improve check-drone-drift script (#5925)

* Improve check-drone-drift script

Instead of checking the line count of the current branch an main, run
`make drone` and check if there are changes to the target
`.drone/drone.yml` file.

Signed-off-by: Christian Haudum <christian.haudum@gmail.com>

* Generate .drone/drone.yml using `make drone`

Signed-off-by: Christian Haudum <christian.haudum@gmail.com>

* fixup! Generate .drone/drone.yml using `make drone`

Signed-off-by: Christian Haudum <christian.haudum@gmail.com>
This commit is contained in:
Christian Haudum
2022-04-19 15:22:18 +05:30
committed by GitHub
parent 6bdecd6a50
commit b3bc8d3063
3 changed files with 26 additions and 14 deletions
+2 -2
View File
@@ -12,7 +12,7 @@ steps:
from_secret: docker_password
repo: grafana/loki-build-image
tags:
- 0.20.2
- 0.20.3
username:
from_secret: docker_username
when:
@@ -1118,6 +1118,6 @@ kind: secret
name: deploy_config
---
kind: signature
hmac: 2f47de5e61231501593c473c31c46c695edabd18e6dd5e06817d272720c144f8
hmac: 64871d70248fbe43acab816fe107dc657442ded224b48779ac15f4559143a2c6
...
+1 -1
View File
@@ -576,7 +576,7 @@ else
endif
check-drone-drift:
./tools/check-drone-drift.sh main
./tools/check-drone-drift.sh $(BUILD_IMAGE_VERSION)
# support go modules
+23 -11
View File
@@ -4,18 +4,30 @@ set -uo pipefail
command -v drone >/dev/null 2>&1 || { echo "drone is not installed"; exit 1; }
TARGET_BRANCH="$1"
DRONE_JSONNET_FILE=".drone/drone.jsonnet"
DRONE_CONFIG_FILE=".drone/drone.yml"
DRONE_ACTUAL_CONFIG_FILE="$(mktemp)"
DRONE_EXPECTED_CONFIG_FILE="$(mktemp)"
# Check for a drift between the jsonnet and the resulting file consumed by Drone
modified_drone_jsonnet=$(git diff "${TARGET_BRANCH}" -- "${DRONE_JSONNET_FILE}" | wc -l)
if [[ "${modified_drone_jsonnet}" -gt "0" ]]; then
modified_drone_config=$(git diff "${TARGET_BRANCH}" -- "${DRONE_CONFIG_FILE}" | wc -l)
if [[ "${modified_drone_config}" -lt "1" ]]; then
echo "There is a drift between ${DRONE_JSONNET_FILE} and ${DRONE_CONFIG_FILE}"
echo "You can fix it by running:"
echo "make drone"
exit 1
fi
fi
drone jsonnet \
--stream \
--stdout \
--format \
-V __build-image-version="${1:-latest}" \
--source "${DRONE_JSONNET_FILE}" \
> "${DRONE_EXPECTED_CONFIG_FILE}"
# remove last 5 lines which contain the signature
head -n -5 "${DRONE_CONFIG_FILE}" > "${DRONE_ACTUAL_CONFIG_FILE}"
diff "${DRONE_EXPECTED_CONFIG_FILE}" "${DRONE_ACTUAL_CONFIG_FILE}"
EXIT_STATUS=$?
if [[ "${EXIT_STATUS}" -eq 1 ]]; then
echo "There is a drift between ${DRONE_JSONNET_FILE} and ${DRONE_CONFIG_FILE}"
echo "You can fix it by running:"
echo "make drone"
else
echo "${DRONE_CONFIG_FILE} is up to date"
fi
exit "${EXIT_STATUS}"