forked from open-policy-agent/opa-idea-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_or_update_release_notes_pr.sh
executable file
·72 lines (56 loc) · 2.82 KB
/
create_or_update_release_notes_pr.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env bash
########################################################################################################################
# This script create or update the PR with the next release notes.
# It will generate the next release-notes thanks to script hack/generate_release_notes.sh and update the CHANGELOG.md.
# Then open or update PR. The branch used for the PR is "update-release-notes".
#
# This script is intended to be run in github action but can run in local.
# The following requirements must be satisfied:
# * same requirement as hack/generate_release_notes.sh
# * the github cli: gh must be installed (https://cli.github.com/)
########################################################################################################################
set -o errexit
set -o nounset
set -o pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"
source "${ROOT}/hack/util.sh"
util::require-gh
release_note_branch='update-release-notes'
base_branch='master'
pr_number="$(gh pr list -H update-release-notes --limit 1 --json number --jq '.[].number')"
if [[ -z "${pr_number}" ]]; then
pr_exist=false
echo "release notes pr does note already exist"
git checkout -b "${release_note_branch}"
else
pr_exist=true
echo "release notes pr already exist (pr_number=${pr_number})"
gh pr checkout "${pr_number}"
git reset --hard "${base_branch}"
fi
echo "=================================================================================================================="
echo "generating next release notes"
echo "=================================================================================================================="
"${ROOT}"/hack/generate_release_notes.sh
echo "=================================================================================================================="
echo "release notes successfully generated"
echo "merging next release notes with changelog"
echo "=================================================================================================================="
echo -e "\n" >> "${NEXT_RELEASE_NOTES_FILE}"
cat "${NEXT_RELEASE_NOTES_FILE}" CHANGELOG.md > tmp_changelog.md
mv tmp_changelog.md CHANGELOG.md
if ! git config user.name > /dev/null 2>&1; then
# this mean script is run by github action
echo "git user.name is not set. Setting git config user.name and user.email"
git config user.name 'GitHub Action'
git config user.email 'action@github.com'
fi
git add CHANGELOG.md
# commit must be signed to pass DTO check
git commit -s -m "update changelog with new version"
echo "push new changelog on branch ${release_note_branch}"
git push origin "${release_note_branch}" -f
if [[ "${pr_exist}" == false ]]; then
echo "create release note PR"
gh pr create --base master --head "${release_note_branch}" --body-file "${ROOT}/.github/release-notes-pr-description.md"
fi