Skip to content

Commit 66e52bd

Browse files
#110 - Introduce GH actions for version tag check and release notes presence (#111)
* #110 - Introduce GH actions for version tag check and release notes presence - Switched to use new GH action. Simplified workflow files.
1 parent 655c2c0 commit 66e52bd

File tree

7 files changed

+54
-288
lines changed

7 files changed

+54
-288
lines changed

.github/workflows/check_pr_release_notes.yml

Lines changed: 9 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -21,67 +21,19 @@ on:
2121
types: [opened, synchronize, reopened, edited, labeled, unlabeled]
2222
branches: [ master ]
2323

24-
env:
25-
SKIP_LABEL: 'no RN'
26-
RLS_NOTES_TAG_REGEX: 'Release Notes:'
27-
2824
jobs:
2925
check-release-notes:
3026
runs-on: ubuntu-latest
3127

3228
steps:
33-
- name: Get Pull Request Info
34-
id: pr_info
35-
uses: actions/github-script@v7
29+
- uses: actions/setup-python@v5.1.1
3630
with:
37-
script: |
38-
const pr_number = context.payload.pull_request.number;
39-
const pr = await github.rest.pulls.get({
40-
owner: context.repo.owner,
41-
repo: context.repo.repo,
42-
pull_number: pr_number
43-
});
44-
const labels = pr.data.labels ? pr.data.labels.map(label => label.name) : [];
45-
46-
if (labels.includes("${{ env.SKIP_LABEL }}")) {
47-
console.log("Skipping release notes check because '${{ env.SKIP_LABEL }}' label is present.");
48-
core.setOutput("skip_check", 'true');
49-
core.setOutput("pr_body", "");
50-
return;
51-
}
52-
53-
const pr_body = pr.data.body;
54-
if (!pr_body) {
55-
core.setFailed("Pull request description is empty.");
56-
core.setOutput("pr_body", "");
57-
core.setOutput("skip_check", 'false');
58-
return;
59-
}
60-
core.setOutput("pr_body", pr_body);
61-
core.setOutput("skip_check", 'false');
62-
return;
63-
64-
- name: Skip check if SKIP_LABEL is present
65-
if: steps.pr_info.outputs.skip_check == 'true'
66-
run: echo "Skipping release notes validation."
31+
python-version: '3.11'
6732

68-
- name: Check for 'Release Notes:' and bullet list
69-
if: steps.pr_info.outputs.skip_check == 'false'
70-
run: |
71-
# Extract the body from the previous step
72-
PR_BODY="${{ steps.pr_info.outputs.pr_body }}"
73-
74-
# Check if "Release Notes:" exists
75-
if ! echo "$PR_BODY" | grep -q '${{ env.RLS_NOTES_TAG_REGEX }}'; then
76-
echo "Error: release notes tag not found in pull request description. Has to adhere to format '${{ env.RLS_NOTES_TAG_REGEX }}'."
77-
exit 1
78-
fi
79-
80-
# Extract text after "Release Notes:" line
81-
TEXT_BELOW_RELEASE_NOTES_TAG=$(echo "$PR_BODY" | sed -n '/${{ env.RLS_NOTES_TAG_REGEX }}/,$p' | tail -n +2)
82-
83-
# Check if there's a bullet list (lines starting with '-', '+' or '*')
84-
if ! echo "$TEXT_BELOW_RELEASE_NOTES_TAG" | grep -qE '^\s*[-+*]\s+.+$'; then
85-
echo "Error: No bullet list found under release notes tag."
86-
exit 1
87-
fi
33+
- name: Check presence of release notes in PR description
34+
uses: AbsaOSS/release-notes-presence-check@v0.1.0
35+
env:
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37+
with:
38+
github-repository: ${{ github.repository }}
39+
pr-number: ${{ github.event.number }}

.github/workflows/release_draft.yml

Lines changed: 10 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -23,64 +23,7 @@ on:
2323
required: true
2424

2525
jobs:
26-
check-tag:
27-
runs-on: ubuntu-latest
28-
steps:
29-
- uses: actions/checkout@v4
30-
with:
31-
fetch-depth: 0
32-
persist-credentials: false
33-
34-
- name: Validate format of received tag
35-
uses: actions/github-script@v7
36-
with:
37-
script: |
38-
const newTag = core.getInput('tag-name');
39-
const regex = /^v[0-9]+\.[0-9]+\.[0-9]+$/;
40-
41-
if (!regex.test(newTag)) {
42-
core.setFailed('Tag does not match the required format "v[0-9]+.[0-9]+.[0-9]+"');
43-
return;
44-
}
45-
tag-name: ${{ github.event.inputs.tag-name }}
46-
47-
# - name: Check tag's correct version increment
48-
# uses: actions/github-script@v7
49-
# with:
50-
# script: |
51-
# const newTag = core.getInput('tag-name');
52-
#
53-
# // get latest tag
54-
# const { data: refs } = await github.rest.git.listMatchingRefs({
55-
# owner: context.repo.owner,
56-
# repo: context.repo.repo,
57-
# ref: 'tags/'
58-
# });
59-
#
60-
# if (refs.length === 0) {
61-
# // No existing tags, so any new tag is valid
62-
# console.log('No existing tags found. Any new tag is considered valid.');
63-
# return;
64-
# }
65-
#
66-
# const latestTag = refs.sort((a, b) => new Date(b.object.date) - new Date(a.object.date))[0].ref.replace('refs/tags/', '');
67-
# const latestVersion = latestTag.replace('v', '').split('.').map(Number);
68-
# const newVersion = newTag.replace('v', '').split('.').map(Number);
69-
#
70-
# // check tag's correct version increase
71-
# const isValid = (latestVersion[0] === newVersion[0] && latestVersion[1] === newVersion[1] && newVersion[2] === latestVersion[2] + 1) ||
72-
# (latestVersion[0] === newVersion[0] && newVersion[1] === latestVersion[1] + 1 && newVersion[2] === 0) ||
73-
# (newVersion[0] === latestVersion[0] + 1 && newVersion[1] === 0 && newVersion[2] === 0);
74-
#
75-
# if (!isValid) {
76-
# core.setFailed('New tag is not one version higher than the latest tag');
77-
# return;
78-
# }
79-
#
80-
# tag-name: ${{ github.event.inputs.tag-name }}
81-
8226
release-draft:
83-
needs: check-tag
8427
runs-on: ubuntu-latest
8528
steps:
8629
- uses: actions/checkout@v4
@@ -92,6 +35,16 @@ jobs:
9235
with:
9336
python-version: '3.11'
9437

38+
- name: Check format of received tag
39+
id: check-version-tag
40+
uses: AbsaOSS/version-tag-check@v0.1.0
41+
env:
42+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43+
with:
44+
github-repository: ${{ github.repository }}
45+
branch: 'master'
46+
version-tag: ${{ github.event.inputs.tag-name }}
47+
9548
- name: Generate Release Notes
9649
id: generate_release_notes
9750
uses: AbsaOSS/generate-release-notes@master
@@ -117,8 +70,6 @@ jobs:
11770

11871
warnings: true
11972
print-empty-chapters: true
120-
chapters-to-pr-without-issue: true
121-
12273

12374
- name: Create and Push Tag
12475
uses: actions/github-script@v7

.github/workflows/test.yml

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -106,45 +106,5 @@ jobs:
106106
- name: Set PYTHONPATH environment variable
107107
run: echo "PYTHONPATH=${GITHUB_WORKSPACE}/release_notes_generator/release_notes_generator" >> $GITHUB_ENV
108108

109-
- name: Build and run unit tests
110-
run: pytest --cov=. --cov-report=html tests/ -vv
111-
112-
- name: Check overall coverage
113-
run: |
114-
coverage report --fail-under=80
115-
coverage xml -o coverage_overall.xml
116-
117-
- name: Check changed files coverage
118-
run: |
119-
# Get the list of changed Python files
120-
CHANGED_FILES=$(git diff --name-only --diff-filter=AMR ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep '.py$' || true)
121-
echo "Changed Python files: $CHANGED_FILES"
122-
123-
# If no Python files have changed, skip the coverage check
124-
if [ -z "$CHANGED_FILES" ]; then
125-
echo "No Python files have changed. Skipping coverage check for changed files."
126-
exit 0
127-
fi
128-
129-
# Convert list to comma-delimited string
130-
CHANGED_FILES=$(echo "$CHANGED_FILES" | awk '{printf "%s,", $0} END {print ""}' | sed 's/,$//')
131-
132-
# Generate coverage report for changed files
133-
coverage report --include="$CHANGED_FILES" > coverage_report.txt
134-
echo -e "\nChanged Python files report:\n\n"
135-
cat coverage_report.txt
136-
137-
# Fail if the coverage for changed files is below threshold
138-
COVERAGE_TOTAL=$(awk '/TOTAL/ {print $4}' coverage_report.txt)
139-
echo "Total coverage for changed files: $COVERAGE_TOTAL"
140-
141-
if (( $(echo "$COVERAGE_TOTAL < 80.0" | bc -l) )); then
142-
echo "Coverage is below 80%"
143-
exit 1
144-
fi
145-
146-
- name: Upload coverage report
147-
uses: actions/upload-artifact@v3
148-
with:
149-
name: coverage-report
150-
path: coverage_overall.xml
109+
- name: Check code coverage with Pytest
110+
run: pytest --cov=. -v tests/ --cov-fail-under=80

README.md

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
- [Run Black Tool Locally](#run-black-tool-locally)
2121
- [Run Unit Test](#running-unit-test)
2222
- [Run Action Locally](#run-action-locally)
23+
- [GitHub Workflow Examples](#github-workflow-examples)
24+
- [Create Release Tag & Draft Release - By Workflow Dispatch](#create-release-tag--draft-release---by-workflow-dispatch)
25+
- [Check Release Notes Presence - in Pull Request Description](#check-release-notes-presence---in-pull-request-description)
2326
- [Contribution Guidelines](#contribution-guidelines)
2427
- [How to Contribute](#how-to-contribute)
2528
- [License Information](#license-information)
@@ -246,14 +249,14 @@ By setting `duplicity-icon` you can customize the icon used to indicate duplicit
246249

247250
Clone the repository and navigate to the project directory:
248251

249-
```
252+
```shell
250253
git clone https://github.com/AbsaOSS/generate-release-notes.git
251254
cd generate-release-notes
252255
```
253256

254257
Install the dependencies:
255258

256-
```
259+
```shell
257260
pip install -r requirements.txt
258261
export PYTHONPATH=<your path>/generate-release-notes/src
259262
```
@@ -269,24 +272,20 @@ Pylint displays a global evaluation score for the code, rated out of a maximum s
269272
python3 -m venv venv
270273
source venv/bin/activate
271274
pip install -r requirements.txt
272-
273-
# run your commands
274-
275-
deactivate
276275
```
277276

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

280279
### Run Pylint
281280
Run Pylint on all files that are currently tracked by Git in the project.
282-
```
281+
```shell
283282
pylint $(git ls-files '*.py')
284283
```
285284

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

288287
Example:
289-
```
288+
```shell
290289
pylint release-notes-generator/generator.py
291290
```
292291

@@ -336,7 +335,7 @@ All done! ✨ 🍰 ✨
336335

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

339-
```
338+
```shell
340339
pytest tests/
341340
```
342341

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

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

349-
```
350-
pytest --cov=. --cov-report=html tests/
348+
```shell
349+
pytest --cov=. -v tests/ --cov-fail-under=80
351350
```
352351

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

355354
See the coverage report on the path:
356355

357-
```
358-
htmlcov/index.html
356+
```shell
357+
open htmlcov/index.html
359358
```
360359

361360
## Run Action Locally
@@ -397,8 +396,6 @@ See the [example of workflow](./examples/release_draft.yml).
397396

398397
### Check Release Notes Presence - in Pull Request Description
399398
This workflow checks that every pull request includes release notes in the description.
400-
- The check can be skipped by using the `skip-release-notes` label.
401-
- The check is searching a `[Rr]elease [Nn]otes:` strings in the PR description.
402399

403400
See the [example of workflow](./examples/check_pr_release_notes.yml).
404401

examples/check_pr_release_notes.yml

Lines changed: 10 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -11,64 +11,18 @@ env:
1111

1212
jobs:
1313
check-release-notes:
14+
# place your runner here
1415
runs-on: {your-runner}
1516

1617
steps:
17-
- name: Checkout code
18-
uses: actions/checkout@v4
19-
20-
- name: Get Pull Request Info
21-
id: pr_info
22-
uses: actions/github-script@v7
18+
- uses: actions/setup-python@v5.1.1
2319
with:
24-
script: |
25-
const pr_number = context.payload.pull_request.number;
26-
const pr = await github.rest.pulls.get({
27-
owner: context.repo.owner,
28-
repo: context.repo.repo,
29-
pull_number: pr_number
30-
});
31-
const labels = pr.data.labels ? pr.data.labels.map(label => label.name) : [];
32-
33-
if (labels.includes("${{ env.SKIP_LABEL }}")) {
34-
console.log("Skipping release notes check because '${{ env.SKIP_LABEL }}' label is present.");
35-
core.setOutput("skip_check", 'true');
36-
core.setOutput("pr_body", "");
37-
return;
38-
}
39-
40-
const pr_body = pr.data.body;
41-
if (!pr_body) {
42-
core.setFailed("Pull request description is empty.");
43-
core.setOutput("pr_body", "");
44-
core.setOutput("skip_check", 'false');
45-
return;
46-
}
47-
core.setOutput("pr_body", pr_body);
48-
core.setOutput("skip_check", 'false');
49-
return;
50-
51-
- name: Skip check if SKIP_LABEL is present
52-
if: steps.pr_info.outputs.skip_check == 'true'
53-
run: echo "Skipping release notes validation."
20+
python-version: '3.11'
5421

55-
- name: Check for 'Release Notes:' and bullet list
56-
if: steps.pr_info.outputs.skip_check == 'false'
57-
run: |
58-
# Extract the body from the previous step
59-
PR_BODY="${{ steps.pr_info.outputs.pr_body }}"
60-
61-
# Check if "Release Notes:" exists
62-
if ! echo "$PR_BODY" | grep -q '${{ env.RLS_NOTES_TAG_REGEX }}'; then
63-
echo "Error: release notes tag not found in pull request description. Has to adhere to format '${{ env.RLS_NOTES_TAG_REGEX }}'."
64-
exit 1
65-
fi
66-
67-
# Extract text after "Release Notes:" line
68-
TEXT_BELOW_RELEASE_NOTES_TAG=$(echo "$PR_BODY" | sed -n '/${{ env.RLS_NOTES_TAG_REGEX }}/,$p' | tail -n +2)
69-
70-
# Check if there's a bullet list (lines starting with '-', '+' or '*')
71-
if ! echo "$TEXT_BELOW_RELEASE_NOTES_TAG" | grep -qE '^\s*[-+*]\s+.+$'; then
72-
echo "Error: No bullet list found under release notes tag."
73-
exit 1
74-
fi
22+
- name: Check presence of release notes in PR description
23+
uses: AbsaOSS/release-notes-presence-check@v0.1.0
24+
env:
25+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26+
with:
27+
github-repository: ${{ github.repository }}
28+
pr-number: ${{ github.event.number }}

0 commit comments

Comments
 (0)