Skip to main content

CI-Police-adding-rules

Intro​

CI Police is a FED tool that allows users (us) to enforce rules on builds (modules' builds).
This solution should eventually replace our current solution - relying on the modules to configure a linter that will enforce our rules.
The basic idea is the same, we're still running a linter, but now it is running on the builds without the need to configure it on old or new modules.
NOTE: the rule is being run in two steps, running the rule and later reading the result, this is a limitation of the infra and is somewhat limiting rules' creation.

The environment​

Repo: mobile-ci-police-rules
Main logic file: eslintConfig
Our deprecations folder: uilib-deprecations
Noteworthy files:

Actual rules are located here, to create a new rule you can: use yarn create-rule (but it'll be created in the root folder and not the correct place) or simply copy an existing rule and modify the following:

  1. Change folder name
  2. package.json -> name (cannot have a . in the name)
  3. package.json -> wix->artifact->artifactId (cannot have a . in the id)
  4. Modify src/index - this should be relatively simple since the heavy lifting is done in our eslint-rules
    Most rules should ignore non @wix/wix-react-native-ui-lib users (using the isWixUILibUser method).
  5. Modify one or more of the above infra rules as needed
  6. Add tests as needed (might be in the infra folders)
  7. Verify by running yarn --> yw <rule_name> build --> yarn test (testing everything can take a while, you can run only the tests you've added)

Enforcement​

The rules (all the rules, including FED's) can be viewed in the CI Police Station.
If you go to the developer section you'll be able to see the some details on all the rules and if you're the owner of a rule (decided by ownership tag, ours is wix-react-native-ui-lib) you'll see them under My Rules and be able to edit them.

Add Rule​

After merging the rule into the CI-Police library, we need to add the rule to the CI Police Station. In the developers section we can find My Rules and + button. Click on the + button and register your new rule:

  • Rule Type should be Standard
  • Rule Name should be the name of the rule from the package.json file, without the @wix/ci-police-rule- prefix.
  • Ownership tag should be set to wix-react-native-ui-lib
  • Support channel is #mads-support.

Rule stages​

development - testing your rule, make sure to remove filters and verify that there are no unexpected DISABLED (crash?) or IGNORE rules
Once you've finished testing and you think you're rule is ready, request approval (make sure you have documented your rule, there are no crashes and so on)
NOTE: an IGNORE without an explanation (hover over it) is probably ok (PASS) and is a result of running on the master branch which does not run the rule properly
promoted - the rule is running but does not break builds
enforced - the rule is running and is breaking builds

Adding a new rules to the eslint library​

We are still using our own (public) lint rules, which we are still maintaining, but now they are running in CI Police.
Most rules should use the existing rules and adding new rules should be (extremely) rare.

Component prop deprecation​

When starting a prop deprecation process we should add the component and the prop to the end of the json in the uilib-deprecate-component-prop file. When adding a prop to this file, you should add the release version of this deprecation to the top of the file const UILIB_VERSION_5_XX_0 = '[UILIB 5.XX.0]'; and add this version in the deprecation message.