Skip to content

Create CI check for Release Notes #105

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

Merged
merged 40 commits into from
Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
577a03c
test CI check
sydneysugar Jun 21, 2023
a46a790
Create CI check for Release Notes
sydneysugar Jun 21, 2023
343ab54
Removed unnecessary code
sydneysugar Jun 21, 2023
4fa32c1
Access pull request number
sydneysugar Jun 21, 2023
7d2dd0c
Edit to access PR number
sydneysugar Jun 21, 2023
b4a759f
Edited PR number code
sydneysugar Jun 21, 2023
400521c
Try to access PR number
sydneysugar Jun 21, 2023
3021f4c
Try accessing PR URL
sydneysugar Jun 21, 2023
d99953b
Import sys for URL access
sydneysugar Jun 21, 2023
a23324f
Ignore PR instructions
sydneysugar Jun 22, 2023
d715747
Access PR number
sydneysugar Jun 22, 2023
30b9e02
Update for new PR template
sydneysugar Jun 22, 2023
a52a2d8
Rename workflow
sydneysugar Jun 22, 2023
16713b6
Update 'label' error message
sydneysugar Jun 22, 2023
e925ec6
Update 'release notes' error message
sydneysugar Jun 22, 2023
1ef5e20
Address PR template change
sydneysugar Jun 22, 2023
683d7c2
Modify description check
sydneysugar Jun 22, 2023
7cd9bd8
Check for labels in PR template
sydneysugar Jun 22, 2023
a9ccb73
Display messages on PR page
sydneysugar Jun 22, 2023
33d15b9
Add allowed labels to error message
nrichers Jun 23, 2023
91954db
Run check when label added or removed
sydneysugar Jun 23, 2023
ee7a804
Remove check passed message
sydneysugar Jun 23, 2023
bf47ca6
Remove check failed message
sydneysugar Jun 23, 2023
8abda70
Move .DS_Store to .gitignore
sydneysugar Jun 23, 2023
4f81dca
Combine error messages
sydneysugar Jun 23, 2023
77cf863
Fix combined error messages
sydneysugar Jun 23, 2023
19493ac
Fix 'internal' label error
sydneysugar Jun 23, 2023
f7e43f6
Run check when description edited
sydneysugar Jun 23, 2023
fd026df
Run check once
sydneysugar Jun 23, 2023
078fbf3
Fix CI check run
sydneysugar Jun 23, 2023
86e7282
Remove macOS file from PR
nrichers Jun 23, 2023
17ad26d
Merge branch 'main' of github.com:validmind/documentation into releas…
nrichers Jun 23, 2023
c3e61c2
Message edits, update template instructions
nrichers Jun 23, 2023
89ae0ef
Merge branch 'release-notes-ci-check' of github.com:validmind/documen…
nrichers Jun 23, 2023
5375ebf
Template tweak
nrichers Jun 23, 2023
f5a6ad3
Address error for empty comment
sydneysugar Jun 23, 2023
d262c07
Fix error message for empty root comment
sydneysugar Jun 23, 2023
3492241
Fix error message logic
sydneysugar Jun 23, 2023
f4a58e5
Address error when comment is empty
sydneysugar Jun 23, 2023
3d01a62
Define required labels
sydneysugar Jun 23, 2023
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
4 changes: 2 additions & 2 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ PR instructions for release notes:

1. Pick at least one label:

- `internal` (no release notes required)
- `internal` (skip Step 2, no release notes required)
- `highlight`
- `enhancement`
- `bug`
- `deprecation`
- `documentation`

2. In the next section, describe the changes so that an external user can understand them. Keep it simple and link to the docs with [Learn more ...](<relative-link>), if available.
2. In the next section, describe the changes so that an external user can understand them. Keep it simple and link to the docs with [Learn more ...](<relative-link>), if available.
-->

## External Release Notes
Expand Down
80 changes: 80 additions & 0 deletions .github/scripts/ci_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import os
import re
import json
import requests
from github import Github

def get_pull_request_number(pr_url):
response = requests.get(pr_url)
if response.status_code == 200:
pr_number = int(re.search(r'pull/(\d+)', response.url).group(1))
return pr_number
else:
raise ValueError("Failed to fetch pull request details.")

def ci_check(pr_number, access_token):
g = Github(access_token)
# Get repository, pull request, and labels
repo = g.get_repo(os.environ['GITHUB_REPOSITORY'])
pr = repo.get_pull(pr_number)
labels = [label.name for label in pr.labels]
description = pr.body

# Check for the presence of 'internal' label
if 'internal' in labels:
return True

required_labels = ['highlight', 'enhancement', 'bug', 'deprecation', 'documentation']

# Check if root comment is empty
if description is None or not description.strip():
if not any(label in labels for label in required_labels):
comment = "Pull requests must include at least one of the required labels: `internal`, `highlight`, `enhancement`, `bug`, `deprecation`, `documentation`. Except for `internal`, pull requests must also include a description in the release notes section."
pr.create_issue_comment(comment)
return False
comment = "Pull requests must include a description in the release notes section."
pr.create_issue_comment(comment)
return False

# Check for the presence of at least one label
if not any(label in labels for label in required_labels):
# Check for description of external change
release_notes_pattern = r'## External Release Notes[\n\r]+(.*?)(?:\n##|\Z)'
release_notes_match = re.search(release_notes_pattern, description, re.DOTALL)
if release_notes_match:
release_notes_text = release_notes_match.group(1).strip()
if release_notes_text and release_notes_text != '<!--- REPLACE THIS COMMENT WITH YOUR DESCRIPTION --->':
comment = "Pull requests must include at least one of the required labels: `internal` (no release notes required), `highlight`, `enhancement`, `bug`, `deprecation`, `documentation`."
pr.create_issue_comment(comment)
return False
# Pull request has neither a label nor a description
comment = "Pull requests must include at least one of the required labels: `internal`, `highlight`, `enhancement`, `bug`, `deprecation`, `documentation`. Except for `internal`, pull requests must also include a description in the release notes section."
pr.create_issue_comment(comment)
return False

# Check for description of external change
release_notes_pattern = r'## External Release Notes[\n\r]+(.*?)(?:\n##|\Z)'
release_notes_match = re.search(release_notes_pattern, description, re.DOTALL)
if release_notes_match:
release_notes_text = release_notes_match.group(1).strip()
if release_notes_text and release_notes_text != '<!--- REPLACE THIS COMMENT WITH YOUR DESCRIPTION --->':
return True

comment = "Pull requests must include a description in the release notes section."
pr.create_issue_comment(comment)
return False

if __name__ == '__main__':
event_path = os.environ['GITHUB_EVENT_PATH']
with open(event_path, 'r') as f:
event_payload = json.load(f)
pr_number = event_payload['pull_request']['number']

access_token = os.environ['GITHUB_TOKEN']

result = ci_check(pr_number, access_token)

if not result:
exit(1)

exit(0)
26 changes: 26 additions & 0 deletions .github/workflows/ci_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Release notes check

on:
pull_request:
types: [opened, synchronize, labeled, unlabeled, edited]

jobs:
ci_check:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.9'

- name: Install dependencies
run: pip install PyGithub pyyaml

- name: Run CI Check
run: python .github/scripts/ci_check.py ${{ github.event.pull_request.html_url }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@

/site/_source
/.luarc.json

site/.DS_Store
Binary file removed site/.DS_Store
Binary file not shown.