Skip to content

Instantly share code, notes, and snippets.

Created October 3, 2022 17:35
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Consul changelog_checker v0.2
# example:
# ./ release/1.11.x main 14828
set -euo pipefail
function main {
local base_branch
local default_branch
local pr_number
# 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 "
echo "base is NOT main"
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 -"
exit 1
echo "Found .changelog entry in PR!"
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment