cacti icon indicating copy to clipboard operation
cacti copied to clipboard

ci(custom-checks): add common package json fields check

Open outSH opened this issue 1 year ago • 1 comments

Is your feature request related to a problem? Please describe.

We have bunch of custom checks that verify content of package.json and we need to add new ones from time to time. Most recently, we want to verify that:

  • URLs point to new repository
  • Packages are public (https://github.com/hyperledger-cacti/cacti/issues/3666)

Describe the solution you'd like I don't want to add a new script each time a single field has to be checked, I want to have a simple template that will describe what parts of package.json should be assesed, and have a single script that will do the verification (and possibly a fix if applicable).

Example template I have in mind (don't mind the values, it's just an example):

{
  "name": "regexMatch(@hyperledger/.+)",
  "version": "eqal(2.1.0)", // TBD - must check if not causing problems on release
  "private": "eqal(false)",
  "description": "notEmpty()",
  "homepage": "eqal(https://github.com/hyperledger/cacti#readme)",
  "bugs": {
    "url": "eqal(https://github.com/hyperledger-cacti/cacti/issues)"
  },
  "repository": {
    "type": "eqal(git)",
    "url": "eqal(git+https://github.com/hyperledger/cacti.git)"
  },
  "license": "eqal(Apache-2.0)",
  "author": {
    "name": "eqal(Hyperledger Cacti Contributors)",
    "email": "eqal([email protected])",
    "url": "eqal(https://www.hyperledger.org/use/cacti)"
  },
  "scripts": "notEmpty()",
  "publishConfig": {
    "access": "eqal(public)"
  },
  // CUSTOM CHECKS
  "_checkNodeVersion": {
    "node": "18",
    "npm": "8"
  },
  "_checkPackageSorted": true
}

Describe alternatives you've considered Adding new script isn't hard but still a bit time consuming. Having template-based solution will allow adding new / modifying rules in a matter of minutes.

@petermetz thoughts?

outSH avatar Dec 03 '24 14:12 outSH

@outSH Agreed, 100%. It would be great to have a single custom-check script responsible for the bulk of the package.json validations that are easy to describe declaratively with a Joi 1 schema for example.

In the interest of time I would skip doing automatic corrections for now, but I also consider that a good idea of course.

petermetz avatar Dec 04 '24 19:12 petermetz