Skip to content

Commit 1e37ce9

Browse files
Merge pull request #6 from AbsaOSS/bugfix/typos
After Release fix
2 parents cab7783 + dae7acc commit 1e37ce9

File tree

7 files changed

+115
-142
lines changed

7 files changed

+115
-142
lines changed

README.md

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,6 @@ This action is designed to help maintainers and contributors ensure that release
5757
- **Required**: No
5858
- **Default**: ``
5959

60-
### `fails-on-error`
61-
- **Description**: Whether the action should fail if an error occurs.
62-
- **Required**: No
63-
- **Default**: `true`
64-
65-
## Outputs
66-
67-
### `valid`
68-
- **Description**: Whether the release notes are present.
69-
- **Value**: `true` or `false`
70-
7160
## Usage
7261

7362
### Adding the Action to Your Workflow
@@ -85,12 +74,11 @@ See the default action step definition:
8574
env:
8675
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8776
with:
88-
github-repository: "{ org }/{ repo }"
89-
pr-numer: 109
77+
github-repository: "{ org }/{ repo }" # e.g. ${{ github.repository }}
78+
pr-number: 109 # e.g. ${{ github.event.number }}
9079
location: "body"
9180
title: "[Rr]elease [Nn]otes:"
9281
skip-labels: "skip-release-notes,no-release-notes"
93-
fails-on-error: "false"
9482
```
9583
9684
## Running Static Code Analysis
@@ -218,20 +206,9 @@ export INPUT_GITHUB_REPOSITORY="AbsaOSS/generate-release-notes"
218206
export INPUT_LOCATION="body"
219207
export INPUT_TITLE="[Rr]elease notes:"
220208
export INPUT_SKIP_LABELS="skip-release-notes,another-skip-label"
221-
export INPUT_FAILS_ON_ERROR="true"
222-
export GITHUB_OUTPUT="output.txt" # File to capture outputs
223-
224-
# Remove existing output file if it exists
225-
if [ -f "$GITHUB_OUTPUT" ]; then
226-
rm "$GITHUB_OUTPUT"
227-
fi
228209

229210
# Run the main script
230211
python main.py
231-
232-
# Display the outputs
233-
echo "Action Outputs:"
234-
cat "$GITHUB_OUTPUT"
235212
```
236213

237214
## Contribution Guidelines

action.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,6 @@ inputs:
3535
description: 'A comma-separated list of labels that will cause the action to skip the check.'
3636
required: false
3737
default: ''
38-
fails-on-error:
39-
description: 'Set to "true" to fail the action if validation errors are found.'
40-
required: false
41-
default: 'true'
42-
43-
outputs:
44-
valid:
45-
description: 'Indicates whether the release notes are present in the PR.'
46-
value: ${{ steps.release-notes-presence-check.outputs.valid }}
4738

4839
branding:
4940
icon: 'book'
@@ -84,7 +75,6 @@ runs:
8475
INPUT_LOCATION: ${{ inputs.location }}
8576
INPUT_TITLE: ${{ inputs.title }}
8677
INPUT_SKIP_LABELS: ${{ inputs.skip-labels }}
87-
INPUT_FAILS_ON_ERROR: ${{ inputs.fails-on-error }}
8878
run: |
8979
source .venv/bin/activate
9080
python ${{ github.action_path }}/main.py

release_notes_presence_check/release_notes_presence_check_action.py

Lines changed: 21 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ def __init__(self) -> None:
4343
self.location: str = os.environ.get("INPUT_LOCATION", default="body")
4444
self.title: str = os.environ.get("INPUT_TITLE", default="[Rr]elease [Nn]otes:")
4545
self.skip_labels: list[str] = os.environ.get("INPUT_SKIP_LABELS", default="")
46-
self.fails_on_error: bool = os.environ.get("INPUT_FAILS_ON_ERROR", "true").lower() == "true"
4746

4847
self.__validate_inputs()
4948

@@ -65,19 +64,18 @@ def run(self) -> None:
6564
labels: list[str] = [label.get("name", "") for label in pr_data.get("labels", [])]
6665
if self.skip_labels in labels:
6766
logger.info("Skipping release notes check because '%s' label is present.", self.skip_labels)
68-
self.write_output("true")
6967
sys.exit(0) # Exiting with code 0 indicates success but the action is skipped.
7068

7169
# check release notes presence in defined location
7270
pr_body = pr_data.get("body", "")
7371
if len(pr_body.strip()) == 0:
7472
logger.error("Error: Pull request description is empty.")
75-
self.handle_failure()
73+
sys.exit(0)
7674

7775
# Check if release notes tag is present
7876
if not re.search(self.title, pr_body):
7977
logger.error("Error: Release notes title '%s' not found in pull request body.", self.title)
80-
self.handle_failure()
78+
sys.exit(0)
8179

8280
# Get line index of the release notes tag
8381
lines = pr_body.split("\n")
@@ -90,81 +88,62 @@ def run(self) -> None:
9088
# Check if there is content after the release notes tag
9189
if release_notes_start_index is None or release_notes_start_index >= len(lines):
9290
logger.error("Error: No content found after the release notes tag.")
93-
self.handle_failure()
91+
sys.exit(1)
9492

9593
# Check if there is a bullet list directly under the release notes tag
9694
text_below_release_notes = lines[release_notes_start_index:]
9795
if not text_below_release_notes or not text_below_release_notes[0].strip().startswith(("-", "+", "*")):
9896
logger.error("Error: No bullet list found directly under release notes tag.")
99-
self.handle_failure()
97+
sys.exit(1)
10098

101-
self.write_output("true")
10299
logger.info("Release Notes detected.")
103100
sys.exit(0)
104101

105-
def write_output(self, valid_value: str) -> None:
106-
"""
107-
Write the output to the file specified by the GITHUB_OUTPUT environment variable.
108-
109-
@param valid_value: The value to write to the output file.
110-
@return: None
111-
"""
112-
output_file = os.environ.get("GITHUB_OUTPUT", default="output.txt")
113-
with open(output_file, "a", encoding="utf-8") as fh:
114-
print(f"valid={valid_value}", file=fh)
115-
116-
def handle_failure(self) -> None:
117-
"""
118-
Handle the failure of the action.
119-
120-
@return: None
121-
"""
122-
self.write_output("false")
123-
if self.fails_on_error:
124-
sys.exit(1)
125-
else:
126-
sys.exit(0)
127-
128102
def __validate_inputs(self) -> None:
129103
"""
130104
Validate the required inputs. When the inputs are not valid, the action will fail.
131105
132106
@return: None
133107
"""
108+
error_detected = False
109+
134110
if len(self.github_token) == 0:
135111
logger.error("Failure: GITHUB_TOKEN is not set correctly.")
136-
self.handle_failure()
112+
error_detected = True
137113

138114
value = os.environ.get("INPUT_PR_NUMBER", default="")
139115
if len(value) == 0:
140116
logger.error("Failure: PR_NUMBER is not set correctly.")
141-
self.handle_failure()
117+
error_detected = True
142118

143119
if not value.isdigit():
144120
logger.error("Failure: PR_NUMBER is not a valid number.")
145-
self.handle_failure()
121+
error_detected = True
146122

147123
value = os.environ.get("INPUT_GITHUB_REPOSITORY", default="")
148124
if len(value) == 0:
149125
logger.error("Failure: GITHUB_REPOSITORY is not set correctly.")
150-
self.handle_failure()
126+
error_detected = True
151127

152128
if value.count("/") != 1:
153129
logger.error("Failure: GITHUB_REPOSITORY is not in the correct format.")
154-
self.handle_failure()
155-
156-
if len(value.split("/")[0]) == 0 or len(value.split("/")[1]) == 0:
157-
logger.error("Failure: GITHUB_REPOSITORY is not in the correct format.")
158-
self.handle_failure()
130+
error_detected = True
131+
else:
132+
if len(value.split("/")[0]) == 0 or len(value.split("/")[1]) == 0:
133+
logger.error("Failure: GITHUB_REPOSITORY is not in the correct format.")
134+
error_detected = True
159135

160136
if len(self.location) == 0:
161137
logger.error("Failure: LOCATION is not set correctly.")
162-
self.handle_failure()
138+
error_detected = True
163139

164140
if self.location not in ["body"]:
165141
logger.error("Failure: LOCATION is not one of the supported values.")
166-
self.handle_failure()
142+
error_detected = True
167143

168144
if len(self.title) == 0:
169145
logger.error("Failure: TITLE is not set correctly.")
170-
self.handle_failure()
146+
error_detected = True
147+
148+
if error_detected:
149+
sys.exit(1)

tests/conftest.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#
2+
# Copyright 2024 ABSA Group Limited
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
import pytest
18+
19+
@pytest.fixture
20+
def mock_logging_setup(mocker):
21+
"""Fixture to mock the basic logging setup using pytest-mock."""
22+
mock_log_config = mocker.patch("logging.basicConfig")
23+
yield mock_log_config
24+
25+
@pytest.fixture()
26+
def mock_exit(code) -> list:
27+
"""Fixture to mock the exit function using pytest-mock."""
28+
exit_calls = []
29+
exit_calls.append(code)
30+
return exit_calls

0 commit comments

Comments
 (0)