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

#110 - Introduce GH actions for version tag check and release notes presence #111

Merged
Show file tree
Hide file tree
Changes from 7 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/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
github-repository: ${{ github.repository }}
pr-number: ${{ github.event.number }}
69 changes: 10 additions & 59 deletions .github/workflows/release_draft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,64 +23,7 @@ on:
required: true

jobs:
check-tag:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false

- name: Validate format of received tag
uses: actions/github-script@v7
with:
script: |
const newTag = core.getInput('tag-name');
const regex = /^v[0-9]+\.[0-9]+\.[0-9]+$/;

if (!regex.test(newTag)) {
core.setFailed('Tag does not match the required format "v[0-9]+.[0-9]+.[0-9]+"');
return;
}
tag-name: ${{ github.event.inputs.tag-name }}

# - name: Check tag's correct version increment
# uses: actions/github-script@v7
# with:
# script: |
# const newTag = core.getInput('tag-name');
#
# // get latest tag
# const { data: refs } = await github.rest.git.listMatchingRefs({
# owner: context.repo.owner,
# repo: context.repo.repo,
# ref: 'tags/'
# });
#
# if (refs.length === 0) {
# // No existing tags, so any new tag is valid
# console.log('No existing tags found. Any new tag is considered valid.');
# return;
# }
#
# const latestTag = refs.sort((a, b) => new Date(b.object.date) - new Date(a.object.date))[0].ref.replace('refs/tags/', '');
# const latestVersion = latestTag.replace('v', '').split('.').map(Number);
# const newVersion = newTag.replace('v', '').split('.').map(Number);
#
# // check tag's correct version increase
# const isValid = (latestVersion[0] === newVersion[0] && latestVersion[1] === newVersion[1] && newVersion[2] === latestVersion[2] + 1) ||
# (latestVersion[0] === newVersion[0] && newVersion[1] === latestVersion[1] + 1 && newVersion[2] === 0) ||
# (newVersion[0] === latestVersion[0] + 1 && newVersion[1] === 0 && newVersion[2] === 0);
#
# if (!isValid) {
# core.setFailed('New tag is not one version higher than the latest tag');
# return;
# }
#
# tag-name: ${{ github.event.inputs.tag-name }}

release-draft:
needs: check-tag
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -92,6 +35,16 @@ jobs:
with:
python-version: '3.11'

- name: Check format of received tag
id: check-version-tag
uses: AbsaOSS/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
github-repository: ${{ github.repository }}
branch: 'master'
version-tag: ${{ github.event.inputs.tag-name }}

- name: Generate Release Notes
id: generate_release_notes
uses: AbsaOSS/generate-release-notes@master
Expand All @@ -117,8 +70,6 @@ jobs:

warnings: true
print-empty-chapters: true
chapters-to-pr-without-issue: true


- name: Create and Push Tag
uses: actions/github-script@v7
Expand Down
44 changes: 2 additions & 42 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,45 +106,5 @@ jobs:
- name: Set PYTHONPATH environment variable
run: echo "PYTHONPATH=${GITHUB_WORKSPACE}/release_notes_generator/release_notes_generator" >> $GITHUB_ENV

- name: Build and run unit tests
run: pytest --cov=. --cov-report=html tests/ -vv

- name: Check overall coverage
run: |
coverage report --fail-under=80
coverage xml -o coverage_overall.xml

- name: Check changed files coverage
run: |
# Get the list of changed Python files
CHANGED_FILES=$(git diff --name-only --diff-filter=AMR ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep '.py$' || true)
echo "Changed Python files: $CHANGED_FILES"

# If no Python files have changed, skip the coverage check
if [ -z "$CHANGED_FILES" ]; then
echo "No Python files have changed. Skipping coverage check for changed files."
exit 0
fi

# Convert list to comma-delimited string
CHANGED_FILES=$(echo "$CHANGED_FILES" | awk '{printf "%s,", $0} END {print ""}' | sed 's/,$//')

# Generate coverage report for changed files
coverage report --include="$CHANGED_FILES" > coverage_report.txt
echo -e "\nChanged Python files report:\n\n"
cat coverage_report.txt

# Fail if the coverage for changed files is below threshold
COVERAGE_TOTAL=$(awk '/TOTAL/ {print $4}' coverage_report.txt)
echo "Total coverage for changed files: $COVERAGE_TOTAL"

if (( $(echo "$COVERAGE_TOTAL < 80.0" | bc -l) )); then
echo "Coverage is below 80%"
exit 1
fi

- name: Upload coverage report
uses: actions/upload-artifact@v3
with:
name: coverage-report
path: coverage_overall.xml
- name: Check code coverage with Pytest
run: pytest --cov=. -v tests/ --cov-fail-under=80
25 changes: 12 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
- [Run Black Tool Locally](#run-black-tool-locally)
- [Run Unit Test](#running-unit-test)
- [Run Action Locally](#run-action-locally)
- [GitHub Workflow Examples](#github-workflow-examples)
- [Create Release Tag & Draft Release - By Workflow Dispatch](#create-release-tag--draft-release---by-workflow-dispatch)
- [Check Release Notes Presence - in Pull Request Description](#check-release-notes-presence---in-pull-request-description)
- [Contribution Guidelines](#contribution-guidelines)
- [How to Contribute](#how-to-contribute)
- [License Information](#license-information)
Expand Down Expand Up @@ -246,14 +249,14 @@ By setting `duplicity-icon` you can customize the icon used to indicate duplicit

Clone the repository and navigate to the project directory:

```
```shell
git clone https://github.com/AbsaOSS/generate-release-notes.git
cd generate-release-notes
```

Install the dependencies:

```
```shell
pip install -r requirements.txt
export PYTHONPATH=<your path>/generate-release-notes/src
```
Expand All @@ -269,24 +272,20 @@ Pylint displays a global evaluation score for the code, rated out of a maximum s
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

# run your commands

deactivate
```

This command will also install a Pylint tool, since it is listed in the project requirements.

### Run Pylint
Run Pylint on all files that are currently tracked by Git in the project.
```
```shell
pylint $(git ls-files '*.py')
```

To run Pylint on a specific file, follow the pattern `pylint <path_to_file>/<name_of_file>.py`.

Example:
```
```shell
pylint release-notes-generator/generator.py
```

Expand Down Expand Up @@ -336,7 +335,7 @@ All done! ✨ 🍰 ✨

Unit tests are written using pytest. To run the tests, use the following command:

```
```shell
pytest tests/
```

Expand All @@ -346,16 +345,16 @@ This will execute all tests located in the tests directory.

Code coverage is collected using pytest-cov coverage tool. To run the tests and collect coverage information, use the following command:

```
pytest --cov=. --cov-report=html tests/
```shell
pytest --cov=. -v tests/ --cov-fail-under=80
```

This will execute all tests located in the tests directory and generate a code coverage report.

See the coverage report on the path:

```
htmlcov/index.html
```shell
open htmlcov/index.html
```

## Run Action Locally
Expand Down
65 changes: 9 additions & 56 deletions examples/check_pr_release_notes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,61 +14,14 @@ jobs:
runs-on: {your-runner}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would add a comment here, so it highlights where user is supposed to make a change. Should do the same change in other example.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.


steps:
- name: Checkout code
uses: actions/checkout@v4

- 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/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
github-repository: ${{ github.repository }}
pr-number: ${{ github.event.number }}
Loading