Skip to content

Commit

Permalink
Merge pull request #7 from AbsaOSS/bug/fix-wrong-return-codes
Browse files Browse the repository at this point in the history
Bug/fix wrong return codes
  • Loading branch information
miroslavpojer authored Jan 7, 2025
2 parents 1e37ce9 + dac8eec commit 79c8fa7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 59 deletions.
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/setup-python@v5.1.1
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

0 comments on commit 79c8fa7

Please sign in to comment.