Created
October 3, 2022 17:35
-
-
Save eculver/ff83d81e09e5e030f817cf6212c6951f to your computer and use it in GitHub Desktop.
Consul changelog_checker v0.2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# changelog_checker.sh | |
# | |
# example: | |
# ./changelog_checker.sh release/1.11.x main 14828 | |
set -euo pipefail | |
function main { | |
local base_branch | |
local default_branch | |
local pr_number | |
base_ref=${1:-} | |
default_branch=${2:-} | |
pr_number=${3:-} | |
# the result will be 1 when there is equality (when the base branch is main), 0 otherwise | |
# pull_request_base_main=$(expr "${base_ref}" = "${default_branch") | |
# check if there is a diff in the .changelog directory | |
# for PRs against the main branch, the changelog file name should match the PR number | |
# as noted above, when ${pull_request_base_main} == 1 the base branch is "main" | |
echo "checking base" | |
if [ "${base_ref}" = "main" ]; then | |
echo "base is main" | |
enforce_matching_pull_request_number="matching this PR number " | |
changelog_file_path=".changelog/${pr_number}.txt" | |
else | |
echo "base is NOT main" | |
changelog_file_path=".changelog/*.txt" | |
fi | |
echo "getting changed changelog files" | |
changelog_files=$(git --no-pager diff --name-only HEAD "$(git merge-base HEAD "origin/main")" -- ${changelog_file_path}) | |
# If we do not find a file in .changelog/, we fail the check | |
if [ -z "$changelog_files" ]; then | |
# Fail status check when no .changelog entry was found on the PR | |
echo "Did not find a .changelog entry ${enforce_matching_pull_request_number}and the 'pr/no-changelog' label was not applied. Reference - https://github.com/hashicorp/consul/pull/8387" | |
exit 1 | |
else | |
echo "Found .changelog entry in PR!" | |
fi | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment