mozilla / html5-lint

HTML Validation using Mozilla's HTML5 Validator instance
199 stars 72 forks source link

Integrate HTML5 Validator with GitLab CI/CD using NodeJS #33

Closed khoipro closed 5 years ago

khoipro commented 5 years ago

I wish to integrate this package into my GitLab CI/CD. However, when displaying with GitLab CI/CD, it has a result of success.

Screenshot at Sep 25 10-38-59

Do you know the best way to output error to command and stop pipeline display as success?

Thanks.

Here is my sources:

Test HTML5 Validation:
 stage: test
 script:
 - npm run test:html5

In package.json

"scripts": {
  "test:html5": "node html5-lint.js"
}

In html5-lint.js

const fs = require('fs')
const html5Lint = require('html5-lint')

console.log('Start HTML5 lint checking')

fs.readFile('index.html', 'utf8', function (err, html) {
  if (err) { throw err }

  console.log('Running...')

  html5Lint(html, (err, results) => {
    results.messages.forEach(function (msg) {
      var type = msg.type
      var message = msg.message

      console.log('HTML5 Lint [%s]: %s', type, message)
    })
  })
})
khoipro commented 5 years ago

I resolved it by adding process.exit(0) or process.exit(1).