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

#760-Updating Check Changelog and Update Changelog workflows to make it more robust. #816

Closed
Show file tree
Hide file tree
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
27 changes: 5 additions & 22 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,10 @@ on:
types: [opened, synchronize, edited, reopened]

jobs:
check-description:
check-pr-fields:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's technically no longer correct - but easier to leave this as check-description so that the required check value stays the same in the repository settings.

And technically we are still checking the PR description here, just in more detail than before.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok ....i agree then

runs-on: ubuntu-latest
steps:

- name: Check PR Description
id: check_description
run: |
description=$(jq -r ".pull_request.body" "$GITHUB_EVENT_PATH" | awk '/## Changelog/{flag=1; next} /##/{flag=0} flag' | grep -oP '(?<=- \*\*Description:\*\* ).*' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
echo "$description"
default_description="Summary of change(s)"
if [ -n "$description" ] && [ "$description" != "$default_description" ]; then
echo "containsChangelog=true" >> $GITHUB_OUTPUT
else
echo "containsChangelog=false" >> $GITHUB_OUTPUT
fi
- name: Results
run: |
if [[ "${{ steps.check_description.outputs.containsChangelog }}" == "true" || "${{ github.event.pull_request.user.login }}" == "dependabot[bot]" ]]; then
echo "PR contains Changelog section/ PR made by Dependabot"
exit 0
else
echo "Changelog section is missing or does not contain the required details"
exit 1
fi
- name: Check PR Fields
id: check_fields
run: .\.github\workflows\changelog_pr_fields.sh #run the script

98 changes: 98 additions & 0 deletions .github/workflows/changelog_pr_fields.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#Extracting the values for each field

pr_body=$(jq -r ".pull_request.body" "$GITHUB_EVENT_PATH")|

# mandatory changelog_start and changelog_end

changelog_start="<!-- [DO NOT REMOVE-USED BY GH ACTION] CHANGELOG START -->"
changelog_end="<!-- [DO NOT REMOVE-USED BY GH ACTION] CHANGELOG END -->"

if [[ "$pr_body" != *"$changelog_start"* ]]; then
echo "[DO NOT REMOVE-USED BY GH ACTION] CHANGELOG START is missing: $changelog_start"
exit 1
fi

if [[ "$pr_body" != *"$changelog_end"* ]]; then
echo "[DO NOT REMOVE-USED BY GH ACTION] CHANGELOG END is missing: $changelog_end"
exit 1
fi

# Extract and trim each field using pattern matching

description=$(echo "$pr_body" | awk '/## Changelog/{flag=1; next} /##/{flag=0} flag' | grep -oP '(?<=- \*\*Description:\*\* ).*' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') echo "$description"
product_impact=$(echo "$pr_body" | awk '/## Changelog/{flag=1; next} /##/{flag=0} flag' | grep -oP '(?<=- \*\*Product Impact:\*\* ).*' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') echo "$product_impact"
addresses=$(echo "$pr_body" | awk '/## Changelog/{flag=1; next} /##/{flag=0} flag' | grep -oP '(?<=- \*\*Addresses:\*\* ).*' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') echo "$addresses"
components=$(echo "$pr_body" | awk '/## Changelog/{flag=1; next} /##/{flag=0} flag' | grep -oP '(?<=- \*\*Components:\*\* ).*' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') echo "$components"
breaking=$(echo "$pr_body" | awk '/## Changelog/{flag=1; next} /##/{flag=0} flag' | grep -oP '(?<=- \*\*Breaking:\*\* ).*' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') echo "$breaking"
impact_a11y=$(echo "$pr_body" | awk '/## Changelog/{flag=1; next} /##/{flag=0} flag' | grep -oP '(?<=- \*\*Impact_a11y:\*\* ).*' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') echo "$impact_a11y"
guidance=$(echo "$pr_body" | awk '/## Changelog/{flag=1; next} /##/{flag=0} flag' | grep -oP '(?<=- \*\*Guidance:\*\* ).*' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') echo "$guidance"

# Default values for each field(According to PR template)

default_description="Summary of change(s)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we could read these values from the Github PR template instead? We could make the Python script used to generate the changelog reusable, and then use it here to parse the Github PR template, and extract the default values from there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok..as you said the python file is more maintainable ,it would make the code more dynamic .But i will need some days to work on it .

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem @RONAK-AI647, take your time. We appreciate it.

default_product_impact="Choose from - none (for internal updates) / bugfix / new API / updated API / removed API. If it's 'none', use "-" for all items below to indicate they are not relevant."
default_addresses="Link(s) to GH issue(s) addressed. Include KDS links as well as links to related issues in a consumer product repository too."
default_components=" Affected public KDS component. Do not include internal sub-components or documentation components."
default_breaking=" Will this change break something in a consumer? Choose from: yes / no"
default_impact_a11y="Does this change improve a11y or adds new features that can be used to improve it? Choose from: yes / no"
default_guidance=" Why and how to introduce this update to a consumer? Required for breaking changes, appreciated for changes with a11y impact, and welcomed for non-breaking changes when relevant."

# Checking each field with its default value

if [ -n "$description" ] && [ "$description" != "$default_description" ]; then
description_valid=true
else
description_valid=false
fi

if [ -n "$product_impact" ] && [ "$product_impact" != "$default_product_impact" ]; then
product_impact_valid=true
else
product_impact_valid=false
fi

if [ -n "$addresses" ] && [ "$addresses" != "$default_addresses" ]; then
addresses_valid=true
else
addresses_valid=false
fi

if [ -n "$components" ] && [ "$components" != "$default_components" ]; then
components_valid=true
else
components_valid=false
fi

if [ -n "$breaking" ] && [ "$breaking" != "$default_breaking" ]; then
breaking_valid=true
else
breaking_valid=false
fi

if [ -n "$impact_a11y" ] && [ "$impact_a11y" != "$default_impact_a11y" ]; then
impact_a11y_valid=true
else
impact_a11y_valid=false
fi
if [ -n "$guidance" ] && [ "$guidance" != "$default_guidance" ]; then
guidance_valid=true
else
guidance_valid=false
fi

# Results
echo "containsDescription=$description_valid" >> $GITHUB_OUTPUT
echo "containsProductImpact=$product_impact_valid" >> $GITHUB_OUTPUT
echo "containsAddresses=$addresses_valid" >> $GITHUB_OUTPUT
echo "containsComponents=$components_valid" >> $GITHUB_OUTPUT
echo "containsBreaking=$breaking_valid" >> $GITHUB_OUTPUT
echo "containsImpact_a11y=$impact_a11y_valid" >> $GITHUB_OUTPUT
echo "containsGuidance=$guidance_valid" >> $GITHUB_OUTPUT

# Final validation check
if [ "$description_valid" = true ] && [ "$product_impact_valid" = true ] && [ "$addresses_valid" = true ]&& [ "$component_impact_valid" = true ]&& [ "$breaking_valid" = true ]&& [ "$impact_a11y_valid" = true ]&& [ "$guidance_valid" = true ]; then
echo "All required fields are properly filled."
else
echo "Changelog section is missing or does not contain the required details."
exit 1
fi
25 changes: 25 additions & 0 deletions .github/workflows/update_changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,31 @@ jobs:

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

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

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

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

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

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

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

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

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

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

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

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

Expand Down
Loading