Files
Packer-Cn/scripts/prepare_changelog.sh
hashicorp-copywrite[bot] 19055df3ec [COMPLIANCE] License changes (#12568)
* Updating the license from MPL to Business Source License

Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at https://hashi.co/license-faq, and details of the license at www.hashicorp.com/bsl.

* Update copyright file headers to BUSL-1.1

---------

Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
2023-08-10 15:53:29 -07:00

82 lines
2.4 KiB
Bash
Executable File

#!/bin/zsh
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: BUSL-1.1
LAST_RELEASE=$1
DO_PR_CHECK=1
set -o pipefail
is_doc_or_tech_debt_pr(){
if ! (($+commands[jq])); then
DO_PR_CHECK=0
echo "jq not found"
return 1
fi
out=$(python3 -m json.tool < pull.json \
| jq '[.labels[].name == "docs" or .labels[].name == "tech-debt" or .labels[].name == "website"] | any')
grep -q true <<< $out
return $?
}
if [ -z $LAST_RELEASE ]; then
echo "you need to give the previous release version. prepare_changelog.sh v<version>"
exit 1
fi
get_prs(){
# git log v0.10.2...c3861d167533fb797b0fae0c380806625712e5f7 |
git log HEAD...${LAST_RELEASE} --first-parent --oneline --grep="Merge pull request #[0-9]\+" --grep="(#[0-9]\+)$" |
grep -o "#\([0-9]\+\)" | awk -F\# '{print $2}' | while read line
do
grep -q "GH-${line}" CHANGELOG.md
if [ $? -ne 0 ]; then
echo $line
fi
done | while read PR_NUM
do
if [[ -z "${GITHUB_TOKEN}" ]] || [[ -z "${GITHUB_USERNAME}" ]] ; then
out=$(curl -fsS "https://api.github.com/repos/hashicorp/packer/issues/${PR_NUM}" -o pull.json)
else
# authenticated call
out=$(curl -u ${GITHUB_USERNAME}:${GITHUB_TOKEN} -fsS "https://api.github.com/repos/hashicorp/packer/issues/${PR_NUM}" -o pull.json)
fi
exy="$?"
if [ $exy -ne 0 ]; then
echo "bad response from github: manually check PR ${PR_NUM}"
continue
fi
if (($DO_PR_CHECK)) && is_doc_or_tech_debt_pr; then
echo "Skipping PR ${PR_NUM}: labeled as tech debt, docs or website. (waiting a second so we don't get rate-limited...)"
continue
fi
echo "$(python3 -m json.tool < pull.json | jq -r '.title') - [GH-${PR_NUM}](https://github.com/hashicorp/packer/pull/${PR_NUM})"
done
}
#is_doc_or_tech_debt_pr 52061111
# is_doc_or_tech_debt_pr 5206 # non-doc pr
#is_doc_or_tech_debt_pr 5434 # doc pr
#echo $?
#exit
# prpid=$!
# trap 'kill -9 ${prpid}; exit' INT TERM
get_prs | while read line; do
echo $line
if [[ "$line" =~ "bad" ]]; then
exit 1
elif [[ "$line" =~ "Skipping" ]]; then
sleep 1 # GH will rate limit us if we have several in a row
continue
fi
rm -f pull.json
vared -ch ok
done
#TODO: just generate it automatically using PR titles and tags