| 1 |
--- |
| 2 |
# Copyright (c) 2026 Emmanuel Jamet <[email protected]> |
| 3 |
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 4 |
# SPDX-License-Identifier: GPL-3.0-or-later |
| 5 |
|
| 6 |
name: changelog fragments |
| 7 |
on: |
| 8 |
pull_request: |
| 9 |
branches: |
| 10 |
- main |
| 11 |
|
| 12 |
jobs: |
| 13 |
changelog: |
| 14 |
name: "Check changelog fragments" |
| 15 |
runs-on: ubuntu-latest |
| 16 |
steps: |
| 17 |
- uses: actions/checkout@v6 |
| 18 |
with: |
| 19 |
persist-credentials: false |
| 20 |
sparse-checkout: | |
| 21 |
changelogs |
| 22 |
|
| 23 |
- name: Check fragments format |
| 24 |
shell: python |
| 25 |
env: |
| 26 |
PR_NUMBER: ${{ github.event.number }} |
| 27 |
run: | |
| 28 |
from os import getenv |
| 29 |
from sys import exit as sysexit |
| 30 |
from requests import get, RequestException |
| 31 |
from yaml import safe_load |
| 32 |
from re import search, DOTALL, compile |
| 33 |
|
| 34 |
if not getenv("PR_NUMBER"): |
| 35 |
print(f"PR_NUMBER is not set") |
| 36 |
sysexit(1) |
| 37 |
|
| 38 |
try: |
| 39 |
changed_files = get( |
| 40 |
f"https://api.github.com/repos/ansible-collections/community.proxmox/pulls/{getenv('PR_NUMBER')}/files", |
| 41 |
headers={ |
| 42 |
"Accept": "application/vnd.github+json", |
| 43 |
"X-GitHub-Api-Version": "2026-03-10" |
| 44 |
}).json() |
| 45 |
comments = get( |
| 46 |
f"https://api.github.com/repos/ansible-collections/community.proxmox/issues/{getenv('PR_NUMBER')}/comments", |
| 47 |
headers={ |
| 48 |
"Accept": "application/vnd.github+json", |
| 49 |
"X-GitHub-Api-Version": "2026-03-10" |
| 50 |
}).json() |
| 51 |
except (ValueError, TimeoutError, RequestException) as e: |
| 52 |
print(f"Error, getting PR files failed, {e}") |
| 53 |
sysexit(1) |
| 54 |
if not [item for item in changed_files if item["filename"].startswith("plugins/")]: |
| 55 |
print(f"No changes to ansible plugins, no changelog fragment required") |
| 56 |
sysexit(0) |
| 57 |
if any(search(r".*NO CHANGELOG.*", item["body"], flags=DOTALL) for item in comments if item["author_association"] == "COLLABORATOR"): |
| 58 |
print("This PR does not require a changelog fragment per contributor decision") |
| 59 |
sysexit(0) |
| 60 |
changelog_fragments = [item["filename"] for item in changed_files if item["filename"].startswith("changelogs/fragments/")] |
| 61 |
if not changelog_fragments: |
| 62 |
print("No changelog fragment was provided") |
| 63 |
sysexit(1) |
| 64 |
for changelog_fragment in changelog_fragments: |
| 65 |
if not changelog_fragment.endswith(("yml", "yaml")): |
| 66 |
print(f"{changelog_fragment}: extension is not valid for a yaml file") |
| 67 |
sysexit(1) |
| 68 |
try: |
| 69 |
with open(changelog_fragment, "r") as f: |
| 70 |
fragment = safe_load(f) |
| 71 |
for typ, changes in fragment.items(): |
| 72 |
if typ not in [ |
| 73 |
"breaking_changes", |
| 74 |
"major_changes", |
| 75 |
"minor_changes", |
| 76 |
"deprecated_features", |
| 77 |
"removed_features", |
| 78 |
"security_fixes", |
| 79 |
"bugfixes", |
| 80 |
"known_issues", |
| 81 |
"trivial", |
| 82 |
]: |
| 83 |
print(f"unrecognized change type: {typ}") |
| 84 |
sysexit(1) |
| 85 |
|
| 86 |
regex = compile(r".+ - [a-z].*\.") |
| 87 |
for change in changes: |
| 88 |
if not regex.fullmatch(change): |
| 89 |
print( |
| 90 |
"change does not follow principles defined here: " |
| 91 |
"https://github.com/ansible-collections/community.proxmox/blob/main/CONTRIBUTING.md#opening-pull-requests" |
| 92 |
) |
| 93 |
sysexit(1) |
| 94 |
except Exception as e: |
| 95 |
print(f"Exception raised while checking changelog fragment {changelog_fragment}: {e}") |
| 96 |
sysexit(1) |