plugins/tools/test_plugin_ci_policy.py
unimatrixgit cd4d04b7f8
Some checks failed
Lobby Account Provisioning Build / lobby-account (push) Has been cancelled
DuneRealms Plugin CI / plugins (push) Has been cancelled
Provision accounts from authenticated first Lobby joins
2026-12-02 11:33:41 +01:00

89 lines
4.7 KiB
Python

"""Guard the real push status required before merging plugin changes.
Intentionally checks the committed workflow without a third-party YAML loader.
The restricted trigger form makes exclusions and event/job renames fail closed.
"""
from pathlib import Path
import re
import unittest
WORKFLOW = Path(__file__).resolve().parents[1] / '.forgejo/workflows/plugins.yml'
CHECKS = (
'test_plugin_ci_policy.py', 'test_plugin_pillager_profile.py', 'test_plugin_pillager_art.py', 'test_plugin_fleet_install.py',
'test_plugin_menu_pack.py', 'test_plugin_backend_abi.py',
'test_plugin_fleet_rollback.py', 'test_plugin_resource_pack.py',
'test_plugin_vanilla_art.py', 'test_plugin_pack_properties.py',
'test_gameplay_resourcepack.py',
)
def validate(text):
lines = [line for line in text.splitlines() if line.strip() and not line.lstrip().startswith('#')]
normalized = '\n'.join(lines)
expected = "name: DuneRealms Plugin CI\non:\n workflow_dispatch:\n push:\n branches: ['**']\njobs:\n plugins:\n runs-on: dune-ci\n steps:"
if not normalized.startswith(expected + '\n'):
raise ValueError('Keep the plugins push check on every branch, without path/event/job exclusions')
for command in ('fetch --depth=1', '"$GITHUB_SHA"', 'git checkout --detach FETCH_HEAD',
'gradle --no-daemon -p "$module" test jar'):
if command not in text:
raise ValueError('Missing exact-source build: ' + command)
modules = re.search(r'^\s*modules=\(([^)]+)\)', text, re.M)
if not modules or set(modules[1].split()) != {
'DuneEss', 'DuneLobby', 'DuneLobbyAccount', 'DuneNPC', 'DuneRealms-minecraft-only',
'DuneRealmsGUI', 'DuneTerrain', 'JarvisConnector', 'DuneMenus',
}:
raise ValueError('All nine source modules must retain tests and compilation')
for script in CHECKS:
if 'python3 tools/' + script + ' -v' not in text:
raise ValueError('Missing release regression check: ' + script)
for command in ('python3 tools/plugin_navigator_transition.py --stage-pillager-baseline',
'\n python3 tools/plugin_navigator_transition.py\n'):
if command not in text:
raise ValueError('Missing Navigator transition check: ' + command.strip())
if re.search(r'^\s*(continue-on-error|if):', text, re.M):
raise ValueError('Do not skip or ignore required build steps')
# Both shell groups must propagate a failed test/build to the commit status.
if text.count('set -euo pipefail') != 3:
raise ValueError('Exact checkout and both validation groups must fail on errors')
class PluginCIPolicyTests(unittest.TestCase):
def setUp(self):
self.text = WORKFLOW.read_text(encoding='utf-8')
def test_committed_workflow_covers_feature_and_documentation_pushes(self):
validate(self.text)
def test_main_only_and_path_filtered_pushes_are_rejected(self):
for replacement in ('branches: [main]', "branches: ['**']\n paths: ['Dune*/**']",
"branches: ['**']\n paths-ignore: ['docs/**']"):
with self.subTest(replacement=replacement), self.assertRaises(ValueError):
validate(self.text.replace("branches: ['**']", replacement))
def test_status_context_renames_and_dispatch_only_are_rejected(self):
for old, new in (('name: DuneRealms Plugin CI', 'name: Renamed'),
(' plugins:', ' build:'), (' push:', ' pull_request:')):
with self.subTest(new=new), self.assertRaises(ValueError):
validate(self.text.replace(old, new, 1))
def test_regression_check_removal_and_ignored_failures_are_rejected(self):
for script in CHECKS:
with self.subTest(script=script), self.assertRaises(ValueError):
validate(self.text.replace('python3 tools/' + script + ' -v', 'true'))
with self.assertRaises(ValueError):
validate(self.text.replace(' runs-on:', ' continue-on-error: true\n runs-on:', 1))
def test_missing_module_and_unpinned_checkout_are_rejected(self):
for old, new in ((' DuneMenus)', ')'), ('git checkout --detach FETCH_HEAD', 'git checkout main')):
with self.subTest(old=old), self.assertRaises(ValueError):
validate(self.text.replace(old, new))
def test_legacy_baseline_and_navigator_candidate_both_remain_checked(self):
for command in ('python3 tools/plugin_navigator_transition.py --stage-pillager-baseline',
'\n python3 tools/plugin_navigator_transition.py\n'):
with self.subTest(command=command), self.assertRaises(ValueError):
validate(self.text.replace(command, ''))
if __name__ == '__main__':
unittest.main()