We are looking for a way to enforce few validation checks(UT, Security scanners and etc....) before submitting code in Perforce.
Our requirement is
• Prevent users from submitting code unless all checks pass.
• Ensure other static analysis (e.g., linting, security scans) are performed before submission.
Could you provide best practices or recommended methods to achieve this?
Additionally, is there any built-in features or integrations with Helix perforce or swarm to help enforce these checks?
Perforce's standard solution for CI and code review is Swarm: https://www.perforce.com/products/helix-swarm
If you're not using Swarm, then what you want is to define a change-content
trigger: https://help.perforce.com/helix-core/server-apps/p4sag/current/Content/P4SAG/scripting.triggers.submits.content.html
In a nutshell, your trigger is an executable (that you have to supply, probably in the form of writing a script) that would do the following:
pull the contents of the change into a workspace (via p4 unshelve
or p4 print @= change
or similar)
run your tests
return success or failure depending on the result of the tests
If the trigger returns a failure code, the submit will be blocked.