Skip to content

Commit 18fda23

Browse files
authored
Update changelog validation action (#151)
1 parent fe5227f commit 18fda23

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

.github/actions/ansible_validate_changelog/action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ inputs:
1111
description: The pull request base ref.
1212
required: false
1313
default: ${{ github.event.pull_request.base.ref }}
14+
custom_paths:
15+
description: |
16+
A comma-separated list of custom paths from which any modified file
17+
will require a changelog.
18+
default: ""
1419

1520
runs:
1621
using: composite
@@ -29,5 +34,6 @@ runs:
2934
run: >-
3035
python3 ${{ github.action_path }}/validate_changelog.py
3136
--ref ${{ inputs.base_ref }}
37+
--custom-paths ${{ inputs.custom_paths }}
3238
shell: bash
3339
working-directory: ${{ inputs.path }}

.github/actions/ansible_validate_changelog/validate_changelog.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from collections import defaultdict
1111
from pathlib import Path
12+
from typing import Optional
1213

1314
import yaml
1415

@@ -71,6 +72,7 @@ def is_documentation_file(ref: str) -> bool:
7172
prefix_list = (
7273
"docs/",
7374
"plugins/doc_fragments",
75+
"examples",
7476
)
7577
return ref.startswith(prefix_list)
7678

@@ -96,10 +98,11 @@ def is_release_pr(changes: dict[str, list[str]]) -> bool:
9698
return True
9799

98100

99-
def is_changelog_needed(changes: dict[str, list[str]]) -> bool:
101+
def is_changelog_needed(changes: dict[str, list[str]], custom_paths: Optional[list[str]]) -> bool:
100102
"""Determine whether a changelog fragment is necessary.
101103
102104
:param changes: A dictionary keyed on change status (A, M, D, etc.) of lists of changed files
105+
:param custom_paths: additional paths to check changes in
103106
:returns: True if a changelog fragment is not required for this PR else False
104107
"""
105108
# Changes to existing plugins or modules require a changelog
@@ -108,6 +111,11 @@ def is_changelog_needed(changes: dict[str, list[str]]) -> bool:
108111
modifications = changes["M"] + changes["D"]
109112
if any(is_module_or_plugin(x) for x in modifications):
110113
return True
114+
# check any file from the custom paths
115+
if custom_paths:
116+
for ref in modifications + changes["A"]:
117+
if any(ref.startswith(x) for x in custom_paths):
118+
return True
111119

112120
return False
113121

@@ -205,10 +213,11 @@ def list_files(ref: str) -> dict[str, list[str]]:
205213
return changes
206214

207215

208-
def main(ref: str) -> None:
216+
def main(ref: str, custom_paths: Optional[list[str]]) -> None:
209217
"""Run the script.
210218
211219
:param ref: The pull request base ref
220+
:param custom_paths: additional paths to check changes in
212221
"""
213222
changes = list_files(ref)
214223
if changes:
@@ -219,7 +228,7 @@ def main(ref: str) -> None:
219228
changelog = [x for x in changes["A"] if is_changelog_file(x)]
220229
logger.info("changelog files -> %s", changelog)
221230
if not changelog:
222-
if is_changelog_needed(changes):
231+
if is_changelog_needed(changes, custom_paths):
223232
logger.error(
224233
"Missing changelog fragment. This is not required"
225234
" only if PR adds new modules and plugins or contain"
@@ -241,9 +250,19 @@ def main(ref: str) -> None:
241250
sys.exit(0)
242251

243252

253+
def comma_separated_list(arg: str) -> list[str]:
254+
"""Parse a string into a list of string.
255+
256+
:param arg: The string list to parse
257+
:returns: A list of string
258+
"""
259+
return [x for x in arg.split(",") if x]
260+
261+
244262
if __name__ == "__main__":
245263
parser = argparse.ArgumentParser(description="Validate changelog file from new commit")
246264
parser.add_argument("--ref", required=True, help="Pull request base ref")
265+
parser.add_argument("--custom-paths", type=comma_separated_list)
247266

248267
args = parser.parse_args()
249-
main(args.ref)
268+
main(args.ref, args.custom_paths)

.github/workflows/changelog.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
name: Changelog required
22
on:
33
workflow_call:
4+
inputs:
5+
custom_paths:
6+
description: |
7+
A comma-separated list of custom paths from which any modified file
8+
will require a changelog.
9+
required: false
10+
type: string
11+
default: ""
412
jobs:
513
changelog:
614
runs-on: ubuntu-latest
@@ -15,3 +23,5 @@ jobs:
1523

1624
- name: Validate changelog
1725
uses: ansible-network/github_actions/.github/actions/ansible_validate_changelog@main
26+
with:
27+
custom_paths: ${{ inputs.custom_paths }}

0 commit comments

Comments
 (0)