Skip to content

Commit b1c0027

Browse files
committed
- Removed fail on error input.
- Removed valid output.
1 parent 6ccc8ec commit b1c0027

File tree

4 files changed

+21
-140
lines changed

4 files changed

+21
-140
lines changed

README.md

Lines changed: 0 additions & 23 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
@@ -90,7 +79,6 @@ See the default action step definition:
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/test_release_notes_presence_check_action.py

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ def test_validate_inputs_invalid(monkeypatch, caplog, env_name, env_value, error
7878
"INPUT_LOCATION": "body",
7979
"INPUT_TITLE": "[Rr]elease [Nn]otes:",
8080
"INPUT_SKIP_LABELS": "",
81-
"INPUT_FAILS_ON_ERROR": "true",
8281
}
8382

8483
# Update or remove the environment variable for the tested scenario
@@ -136,14 +135,10 @@ def test_run_successful(mocker):
136135
"labels": [{"name": "bug"}, {"name": "enhancement"}]
137136
}
138137

139-
# Mock the output writing method
140-
mock_output = mocker.patch("release_notes_presence_check.release_notes_presence_check_action.ReleaseNotesPresenceCheckAction.write_output")
141-
142138
# Run the action
143139
action = ReleaseNotesPresenceCheckAction()
144140
action.run()
145141

146-
mock_output.assert_called_once_with("true")
147142
mock_exit.assert_called_once_with(0)
148143

149144

@@ -174,9 +169,6 @@ def test_run_skip_by_label(mocker):
174169
"labels": [{"name": "bug"}, {"name": "enhancement"}, {"name": "skip-release-notes-check"}]
175170
}
176171

177-
# Mock the output writing method
178-
mock_output = mocker.patch("release_notes_presence_check.release_notes_presence_check_action.ReleaseNotesPresenceCheckAction.write_output")
179-
180172
# Run the action
181173
with pytest.raises(SystemExit) as exit_info:
182174
action = ReleaseNotesPresenceCheckAction()
@@ -185,8 +177,6 @@ def test_run_skip_by_label(mocker):
185177
assert SystemExit == exit_info.type
186178
assert 0 == exit_info.value.code
187179

188-
mock_output.assert_called_once_with("true")
189-
190180

191181
def test_run_fail_no_body(mocker):
192182
# Set environment variables
@@ -214,9 +204,6 @@ def test_run_fail_no_body(mocker):
214204
"labels": [{"name": "bug"}, {"name": "enhancement"}]
215205
}
216206

217-
# Mock the output writing method
218-
mock_output = mocker.patch("release_notes_presence_check.release_notes_presence_check_action.ReleaseNotesPresenceCheckAction.write_output")
219-
220207
# Run the action
221208
with pytest.raises(SystemExit) as exit_info:
222209
action = ReleaseNotesPresenceCheckAction()
@@ -225,8 +212,6 @@ def test_run_fail_no_body(mocker):
225212
assert SystemExit == exit_info.type
226213
assert 1 == exit_info.value.code
227214

228-
mock_output.assert_called_once_with("false")
229-
230215
def test_run_fail_empty_body(mocker):
231216
# Set environment variables
232217
env_vars = {
@@ -254,9 +239,6 @@ def test_run_fail_empty_body(mocker):
254239
"labels": [{"name": "bug"}, {"name": "enhancement"}]
255240
}
256241

257-
# Mock the output writing method
258-
mock_output = mocker.patch("release_notes_presence_check.release_notes_presence_check_action.ReleaseNotesPresenceCheckAction.write_output")
259-
260242
# Run the action
261243
with pytest.raises(SystemExit) as exit_info:
262244
action = ReleaseNotesPresenceCheckAction()
@@ -265,8 +247,6 @@ def test_run_fail_empty_body(mocker):
265247
assert SystemExit == exit_info.type
266248
assert 1 == exit_info.value.code
267249

268-
mock_output.assert_called_once_with("false")
269-
270250
def test_run_fail_title_not_found(mocker):
271251
# Set environment variables
272252
env_vars = {
@@ -294,9 +274,6 @@ def test_run_fail_title_not_found(mocker):
294274
"labels": [{"name": "bug"}, {"name": "enhancement"}]
295275
}
296276

297-
# Mock the output writing method
298-
mock_output = mocker.patch("release_notes_presence_check.release_notes_presence_check_action.ReleaseNotesPresenceCheckAction.write_output")
299-
300277
# Run the action
301278
with pytest.raises(SystemExit) as exit_info:
302279
action = ReleaseNotesPresenceCheckAction()
@@ -305,8 +282,6 @@ def test_run_fail_title_not_found(mocker):
305282
assert SystemExit == exit_info.type
306283
assert 1 == exit_info.value.code
307284

308-
mock_output.assert_called_once_with("false")
309-
310285
def test_run_fail_release_notes_lines_not_found(mocker):
311286
# Set environment variables
312287
env_vars = {
@@ -334,9 +309,6 @@ def test_run_fail_release_notes_lines_not_found(mocker):
334309
"labels": [{"name": "bug"}, {"name": "enhancement"}]
335310
}
336311

337-
# Mock the output writing method
338-
mock_output = mocker.patch("release_notes_presence_check.release_notes_presence_check_action.ReleaseNotesPresenceCheckAction.write_output")
339-
340312
# Run the action
341313
with pytest.raises(SystemExit) as exit_info:
342314
action = ReleaseNotesPresenceCheckAction()
@@ -345,8 +317,6 @@ def test_run_fail_release_notes_lines_not_found(mocker):
345317
assert SystemExit == exit_info.type
346318
assert 1 == exit_info.value.code
347319

348-
mock_output.assert_called_once_with("false")
349-
350320
def test_run_fail_no_lines_after_title(mocker):
351321
# Set environment variables
352322
env_vars = {
@@ -374,45 +344,10 @@ def test_run_fail_no_lines_after_title(mocker):
374344
"labels": [{"name": "bug"}, {"name": "enhancement"}]
375345
}
376346

377-
# Mock the output writing method
378-
mock_output = mocker.patch("release_notes_presence_check.release_notes_presence_check_action.ReleaseNotesPresenceCheckAction.write_output")
379-
380347
# Run the action
381348
with pytest.raises(SystemExit) as exit_info:
382349
action = ReleaseNotesPresenceCheckAction()
383350
action.run()
384351

385352
assert SystemExit == exit_info.type
386353
assert 1 == exit_info.value.code
387-
388-
mock_output.assert_called_once_with("false")
389-
390-
# handle_failure
391-
392-
def test_handle_failure_fails_on_error_false(mocker):
393-
# Set environment variables with 'INPUT_FAILS_ON_ERROR' set to 'false'
394-
env_vars = {
395-
"INPUT_GITHUB_TOKEN": "fake_token",
396-
"INPUT_PR_NUMBER": "109",
397-
"INPUT_GITHUB_REPOSITORY": "owner/repo",
398-
"INPUT_LOCATION": "body",
399-
"INPUT_TITLE": "[Rr]elease [Nn]otes:",
400-
"INPUT_SKIP_LABELS": "",
401-
"INPUT_FAILS_ON_ERROR": "false", # Set to 'false' to test else branch
402-
}
403-
mocker.patch.dict(os.environ, env_vars)
404-
405-
# Mock sys.exit to raise SystemExit exception
406-
def mock_exit(code):
407-
raise SystemExit(code)
408-
mocker.patch("sys.exit", mock_exit)
409-
410-
# Instantiate the action
411-
action = ReleaseNotesPresenceCheckAction()
412-
413-
# Call handle_failure and expect SystemExit
414-
with pytest.raises(SystemExit) as e:
415-
action.handle_failure()
416-
417-
# Assert that sys.exit was called with exit code 0
418-
assert e.value.code == 0

0 commit comments

Comments
 (0)