diff options
author | Ander Conselvan de Oliveira <ander.deoliveira@mapbox.com> | 2019-03-04 15:13:31 +0200 |
---|---|---|
committer | Ander Conselvan de Oliveira <ander.deoliveira@mapbox.com> | 2019-03-13 15:06:56 +0200 |
commit | 7bac0c7cbac6333b36a91387e2cf2751b048c869 (patch) | |
tree | 8ed1f8f42af317c5cf2ec3bd8d0cf8a56dbcfff3 /scripts/publish_doxygen_coverage.js | |
parent | 3c4d41559a1e1b4d53a9fc089d3f6919441298d0 (diff) | |
download | qtlocation-mapboxgl-7bac0c7cbac6333b36a91387e2cf2751b048c869.tar.gz |
[build] Check documentation coverage on CI
Add a CI target that checks documentation coverage and reports back to
github. While at it, change the output of doxy-coverage to a json file
so it is easy to consume.
Diffstat (limited to 'scripts/publish_doxygen_coverage.js')
-rwxr-xr-x | scripts/publish_doxygen_coverage.js | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/scripts/publish_doxygen_coverage.js b/scripts/publish_doxygen_coverage.js new file mode 100755 index 0000000000..e3e564a3e1 --- /dev/null +++ b/scripts/publish_doxygen_coverage.js @@ -0,0 +1,64 @@ +#!/usr/bin/env node + +const jwt = require('jsonwebtoken'); +const github = require('@octokit/rest')(); +const fs = require('fs'); + +const SIZE_CHECK_APP_ID = 14028; +const SIZE_CHECK_APP_INSTALLATION_ID = 229425; + +var coverage; + +try { + coverage = JSON.parse(fs.readFileSync(process.argv[2])); + if (typeof coverage.documented !== 'number' || typeof coverage.total !== 'number' || + coverage.documented > coverage.total) { + throw new Error('Invalid coverage.json file'); + } +} catch (error) { + console.log('Failed to parse json file with coverage data: ', error); + process.exit(1); +} + +process.on('unhandledRejection', error => { + console.log(error); + process.exit(1); +}); + +const pk = process.env['SIZE_CHECK_APP_PRIVATE_KEY']; +if (!pk) { + console.log('Fork PR; not publishing size.'); + process.exit(0); +} + +const key = Buffer.from(pk, 'base64').toString('binary'); +const payload = { + exp: Math.floor(Date.now() / 1000) + 60, + iat: Math.floor(Date.now() / 1000), + iss: SIZE_CHECK_APP_ID +}; + +const token = jwt.sign(payload, key, {algorithm: 'RS256'}); +github.authenticate({type: 'app', token}); + +github.apps.createInstallationToken({installation_id: SIZE_CHECK_APP_INSTALLATION_ID}) + .then(({data}) => { + github.authenticate({type: 'token', token: data.token}); + const percentage = coverage.documented * 100 / coverage.total; + const title = `${percentage.toFixed(2)}%`; + + return github.checks.create({ + owner: 'mapbox', + repo: 'mapbox-gl-native', + name: 'Doxygen coverage', + head_branch: process.env['CIRCLE_BRANCH'], + head_sha: process.env['CIRCLE_SHA1'], + status: 'completed', + conclusion: 'success', + completed_at: new Date().toISOString(), + output: { + title, + summary: `There is doxygen documentation for ${percentage}% of the public symbols (${coverage.documented} out of ${coverage.total})` + } + }); + }); |