CI: Force changelog updates
Changelog updates are now required in MRs by default. If there is a match for "\<skip.\?changelog\>" in the commit message, this will be ignored. $CI_COMMIT_MESSAGE mangles newlines so it's not possible to require the string to be on its own line, that means it would also trigger within a wall of text, which makes it less obvious. Also, I wasn't able to find a CI variable which has the ref of the branch the MR is set against, to build a tree-ish than spans over the whole MR and not just HEAD. Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
ec72d71551
commit
bbbf522ca0
3 changed files with 62 additions and 0 deletions
40
.forgejo/workflows/check-changelog.py
Executable file
40
.forgejo/workflows/check-changelog.py
Executable file
|
|
@ -0,0 +1,40 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- encoding: utf-8 -*-
|
||||
# vim: set et ts=4 sts=4 sw=4
|
||||
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Skip this check if instructed
|
||||
if re.search(r'skip.?changelog', os.environ['CI_COMMIT_MESSAGE'], flags=re.I) is not None:
|
||||
print('Changelog skipped.')
|
||||
sys.exit(0)
|
||||
|
||||
treeish = 'main..'
|
||||
if os.environ['CI_PIPELINE_SOURCE'] == 'merge_request_event':
|
||||
treeish = '{}..'.format(os.environ['CI_MERGE_REQUEST_DIFF_BASE_SHA'])
|
||||
|
||||
diff=subprocess.run(
|
||||
['git', 'diff-tree', '--no-commit-id', '-r', treeish, '--'],
|
||||
capture_output=True,
|
||||
)
|
||||
|
||||
if diff.stderr:
|
||||
print(f'An error occured: {diff.stderr}')
|
||||
sys.exit(1)
|
||||
|
||||
print(f'Files in {treeish}:\n{diff.stdout}')
|
||||
|
||||
# Verify if at least a single changelog file has been added or edited
|
||||
if re.search(rb'[AM]\s+\S*changelog', diff.stdout, flags=re.I) is None:
|
||||
print(
|
||||
'Please update the Changelog. Use "skip-changelog" '
|
||||
'in the commit message to skip this check.',
|
||||
)
|
||||
sys.exit(1)
|
||||
|
||||
print('Changelog has been updated as expected.')
|
||||
Loading…
Reference in a new issue