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

Bug/fix wrong return codes #7

Merged
merged 2 commits into from
Jan 7, 2025
Merged
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
66 changes: 9 additions & 57 deletions .github/workflows/check_pr_release_notes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,67 +21,19 @@ on:
types: [opened, synchronize, reopened, edited, labeled, unlabeled]
branches: [ master ]

env:
SKIP_LABEL: 'no RN'
RLS_NOTES_TAG_REGEX: 'Release Notes:'

jobs:
check-release-notes:
runs-on: ubuntu-latest

steps:
- name: Get Pull Request Info
id: pr_info
uses: actions/github-script@v7
- uses: actions/[email protected]
with:
script: |
const pr_number = context.payload.pull_request.number;
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr_number
});
const labels = pr.data.labels ? pr.data.labels.map(label => label.name) : [];

if (labels.includes("${{ env.SKIP_LABEL }}")) {
console.log("Skipping release notes check because '${{ env.SKIP_LABEL }}' label is present.");
core.setOutput("skip_check", 'true');
core.setOutput("pr_body", "");
return;
}

const pr_body = pr.data.body;
if (!pr_body) {
core.setFailed("Pull request description is empty.");
core.setOutput("pr_body", "");
core.setOutput("skip_check", 'false');
return;
}
core.setOutput("pr_body", pr_body);
core.setOutput("skip_check", 'false');
return;

- name: Skip check if SKIP_LABEL is present
if: steps.pr_info.outputs.skip_check == 'true'
run: echo "Skipping release notes validation."
python-version: '3.11'

- name: Check for 'Release Notes:' and bullet list
if: steps.pr_info.outputs.skip_check == 'false'
run: |
# Extract the body from the previous step
PR_BODY="${{ steps.pr_info.outputs.pr_body }}"

# Check if "Release Notes:" exists
if ! echo "$PR_BODY" | grep -q '${{ env.RLS_NOTES_TAG_REGEX }}'; then
echo "Error: release notes tag not found in pull request description. Has to adhere to format '${{ env.RLS_NOTES_TAG_REGEX }}'."
exit 1
fi

# Extract text after "Release Notes:" line
TEXT_BELOW_RELEASE_NOTES_TAG=$(echo "$PR_BODY" | sed -n '/${{ env.RLS_NOTES_TAG_REGEX }}/,$p' | tail -n +2)

# Check if there's a bullet list (lines starting with '-', '+' or '*')
if ! echo "$TEXT_BELOW_RELEASE_NOTES_TAG" | grep -qE '^\s*[-+*]\s+.+$'; then
echo "Error: No bullet list found under release notes tag."
exit 1
fi
- name: Check presence of release notes in PR description
uses: AbsaOSS/release-notes-presence-check@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
github-repository: ${{ github.repository }}
pr-number: ${{ github.event.number }}
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ def run(self) -> None:
pr_body = pr_data.get("body", "")
if len(pr_body.strip()) == 0:
logger.error("Error: Pull request description is empty.")
sys.exit(0)
sys.exit(1)

# Check if release notes tag is present
if not re.search(self.title, pr_body):
logger.error("Error: Release notes title '%s' not found in pull request body.", self.title)
sys.exit(0)
sys.exit(1)

# Get line index of the release notes tag
lines = pr_body.split("\n")
Expand Down
Loading