--- # Copyright (c) 2026 Emmanuel Jamet # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) # SPDX-License-Identifier: GPL-3.0-or-later name: changelog fragments on: pull_request: branches: - main jobs: changelog: name: "Check changelog fragments" runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 with: persist-credentials: false sparse-checkout: | changelogs - name: Check fragments format shell: python env: PR_NUMBER: ${{ github.event.number }} run: | from os import getenv from sys import exit as sysexit from requests import get, RequestException from yaml import safe_load from re import search, DOTALL, compile if not getenv("PR_NUMBER"): print(f"PR_NUMBER is not set") sysexit(1) try: changed_files = get( f"https://api.github.com/repos/ansible-collections/community.proxmox/pulls/{getenv('PR_NUMBER')}/files", headers={ "Accept": "application/vnd.github+json", "X-GitHub-Api-Version": "2026-03-10" }).json() comments = get( f"https://api.github.com/repos/ansible-collections/community.proxmox/issues/{getenv('PR_NUMBER')}/comments", headers={ "Accept": "application/vnd.github+json", "X-GitHub-Api-Version": "2026-03-10" }).json() except (ValueError, TimeoutError, RequestException) as e: print(f"Error, getting PR files failed, {e}") sysexit(1) if not [item for item in changed_files if item["filename"].startswith("plugins/")]: print(f"No changes to ansible plugins, no changelog fragment required") sysexit(0) if any(search(r".*NO CHANGELOG.*", item["body"], flags=DOTALL) for item in comments if item["author_association"] == "COLLABORATOR"): print("This PR does not require a changelog fragment per contributor decision") sysexit(0) changelog_fragments = [item["filename"] for item in changed_files if item["filename"].startswith("changelogs/fragments/")] if not changelog_fragments: print("No changelog fragment was provided") sysexit(1) for changelog_fragment in changelog_fragments: if not changelog_fragment.endswith(("yml", "yaml")): print(f"{changelog_fragment}: extension is not valid for a yaml file") sysexit(1) try: with open(changelog_fragment, "r") as f: fragment = safe_load(f) for typ, changes in fragment.items(): if typ not in [ "breaking_changes", "major_changes", "minor_changes", "deprecated_features", "removed_features", "security_fixes", "bugfixes", "known_issues", "trivial", ]: print(f"unrecognized change type: {typ}") sysexit(1) regex = compile(r".+ - [a-z].*\.") for change in changes: if not regex.fullmatch(change): print( "change does not follow principles defined here: " "https://github.com/ansible-collections/community.proxmox/blob/main/CONTRIBUTING.md#opening-pull-requests" ) sysexit(1) except Exception as e: print(f"Exception raised while checking changelog fragment {changelog_fragment}: {e}") sysexit(1)