Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update update_changelog.yml #15

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 31 additions & 20 deletions .github/workflows/update_changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,41 @@ jobs:

- name: Extract and update Changelog
id: modify-changelog
shell: python
run: |
if [ "${{ github.event.pull_request.user.login }}" == "dependabot[bot]" ]; then
changelog="- **Description:** ${{ github.event.pull_request.title }}\n - **Products impact:** Dev Dependency upgrade\n - **Addresses:** -\n - **Components:** -\n - **Breaking:** -\n - **Impacts a11y:** -\n - **Guidance:** -"
else
description=$(jq -r ".pull_request.body" "$GITHUB_EVENT_PATH")
changelog_section=$(echo "$description" | awk '/<!-- \[DO NOT REMOVE-USED BY GH ACTION\] CHANGELOG START -->/{flag=1; next} /<!-- \[DO NOT REMOVE-USED BY GH ACTION\] CHANGELOG END -->/{flag=0} flag' | sed '/<!--/,/-->/d')
changelog="${changelog_section}"
fi
if "${{ github.event.pull_request.user.login }}" == "dependabot[bot]":
changelog = " - **Description:** ${{ github.event.pull_request.title }}\n - **Products impact:** Dev Dependency upgrade\n - **Addresses:** -\n - **Components:** -\n - **Breaking:** -\n - **Impacts a11y:** -\n - **Guidance:** -"
else:
description = """${{ github.event.pull_request.body }}"""
capture = re.compile("<!-- \[DO NOT REMOVE-USED BY GH ACTION\] CHANGELOG START -->\s+<!--(\n|.)+?(?=- \*\*Description)(?P<body>(\n|.)+?(?=<!-- \[DO NOT REMOVE-USED BY GH ACTION\] CHANGELOG END -->))")
match = capture.search(description)
changelog = match.groupsdict()["body"].strip()

pr_number=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH")
pr_link="[#${pr_number}]"
pr_link_ref="[#${pr_number}]: ${{ github.event.pull_request.html_url }}"
final_changelog = "<!-- [DO NOT REMOVE-USED BY GH ACTION] PASTE CHANGELOG -->\n\n"

while IFS= read -r entry; do
if [[ $entry == *"- **Description:"* ]]; then
echo -e "- ${pr_link}\n"
fi
echo -e "\t${entry}"
if [[ $entry == *"- **Guidance:"* ]]; then
echo -e "\n${pr_link_ref}\n"
fi
done <<< "$changelog_section" > pr_info.txt
pr_number = "${{ github.event.pull_request.number }}"
pr_link = "[#{}]".format(pr_number)
pr_link_ref = pr_link + ": ${{ github.event.pull_request.html_url }}"

awk '/<!-- \[DO NOT REMOVE-USED BY GH ACTION\] PASTE CHANGELOG -->/{print; system("cat pr_info.txt"); next} 1' CHANGELOG.md > tmpfile && mv tmpfile CHANGELOG.md
for changeline in changelog.splitlines():
if not changeline:
continue

if changeline.startswith("- **Description:**"):
final_changelog += "\n" + "- " + pr_link + "\n"

final_changelog += " " + changeline + "\n"

if changeline.startwith("- **Guidance:**"):
final_changelog += "\n" + pr_link_ref + "\n"

with open("CHANGELOG.md", "r") as f:
current_changelog = f.read()

new_changelog = current_changelog.replace("<!-- [DO NOT REMOVE-USED BY GH ACTION] PASTE CHANGELOG -->", final_changelog)

with open("CHANGELOG.md", "w") as f:
f.write(new_changelog)

- uses: tibdex/github-app-token@v1
id: generate-token
Expand Down
Loading