Skip to content

Commit

Permalink
Merge pull request #1 from wizsolucoes/feature/save-more-analysis-det…
Browse files Browse the repository at this point in the history
…ails

Feature/save more analysis details
  • Loading branch information
toureholder authored Sep 4, 2020
2 parents 1990fc4 + c8ea62f commit dd0383b
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 28 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,6 @@ dist
# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# End of https://www.toptal.com/developers/gitignore/api/node
# End of https://www.toptal.com/developers/gitignore/api/node

.vscode/
57 changes: 42 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
<!-- omit in toc -->
# SYZ Analyzer

Ferramenta CLI para analisar adesão de uma aplicação ao design system SYZ.

- [Uso](#uso)
- [Desenvolvimento, por onde começar](#desenvolvimento-por-onde-começar)
- [Como funciona](#como-funciona)
- [Parâmetros](#parâmetros)
- [`--app`](#--app)
- [`--src`](#--src)
- [`--gateway`](#--gateway)
- [`--break-build`](#--break-build)
- [Exemplo completo](#exemplo-completo)
- [Variáveis de ambiente](#variáveis-de-ambiente)
- [OpenAPI Specification do serviço de componentes](#openapi-specification-do-serviço-de-componentes)

## Uso
```bash
# Install
Expand All @@ -11,14 +24,26 @@ npm i -g @wizsolucoes/syz-analyzer
syz-analyzer
```

## Desenvolvimento, por onde começar
```bash
# Install
npm install

# Run tests
npm test

# Run
npm start
```

## Como funciona
A analizador segue os seguintes passos:
A analisador segue os seguintes passos:
1. Busca uma lista dos components do SYZ esperados para a aplicação sob análise,
2. Procura por tags html que correspondem aos componentes SYZ,
3. Publica a porcentagem dos components do SYZ esperados que foram encontrados para um repostório de dados,
4. Opcionalmente termina seu processo com código de erro se a porcentagem estiver abaixo de um treshold especificado, o que provocaria a quebra do build em um pipeline de CI.
4. Opcionalmente termina seu processo com código de erro se a porcentagem estiver abaixo de um threshold especificado, o que provocaria a quebra do build em um pipeline de CI.

## Options
## Parâmetros
### `--app`
**(Required)** Nome do respositório da aplicação a ser analisada.

Expand All @@ -27,21 +52,21 @@ $ syz-analyzer --app speed-web
```

### `--src`
Caminho para a pasta do código fonte a ser analizado. Default: "src"
Caminho para a pasta do código fonte a ser analisado. **Default: "src"**

```sh
$ syz-analyzer --src projects/speed-web/src
```

### `--gateway`
Porcentagem dos components do SYZ esperados que devem ser encontrados nos arquivos html para evitar a quebra do build. Default: 100
Porcentagem dos components do SYZ esperados que devem ser encontrados nos arquivos html para evitar a quebra do build. **Default: 100**

```sh
$ syz-analyzer --gateway 70
```

### `--break-build`
Booleano que determina se o build de CI deve se quebrar quando o `gateway` de adesão ao SYZ não for atingido. Default: false
Booleano que determina se o build de CI deve se quebrar quando o `gateway` de adesão ao SYZ não for atingido. **Default: false**

```sh
$ syz-analyzer --break-build
Expand All @@ -65,26 +90,28 @@ Você deve prover a url base para o serviço que vá buscar a lista de component

## OpenAPI Specification do serviço de componentes

<!-- omit in toc -->
### /

<!-- omit in toc -->
#### POST
<!-- omit in toc -->
##### Description

Get list of compomonents by repository name

Get list of components by repository name
<!-- omit in toc -->
##### Parameters

| Name | Located in | Description | Required | Schema |
| ---- | ---------- | ----------- | -------- | ---- |
| body | body | Object with name of repository | Yes | [compomonentsListRequest](#compomonentslistrequest) |
| body | body | Object with name of repository | Yes | [componentsListRequest](#componentslistrequest) |

Example value
```json
{
"repository": "speed-web"
}
```

<!-- omit in toc -->
##### Responses

| Code | Description | Schema |
Expand All @@ -103,10 +130,10 @@ Example value
]

```

<!-- omit in toc -->
### Models

#### compomonentsListRequest
<!-- omit in toc -->
#### componentsListRequest

| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
Expand All @@ -118,7 +145,7 @@ Example value
"repository": "speed-web"
}
```

<!-- omit in toc -->
#### componentObj

| Name | Type | Description | Required |
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wizsolucoes/syz-analyzer",
"version": "1.0.0",
"version": "1.1.0",
"description": "",
"main": "index.js",
"bin": {
Expand Down
4 changes: 2 additions & 2 deletions src/components-list-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var exports = module.exports;
exports.fetch = async function (appId) {
if (!baseUrl) {
console.log('ERROR: Component service base url not provided. Aborting analysis.');
process.exit(1);
process.exit();
}

try {
Expand All @@ -20,7 +20,7 @@ exports.fetch = async function (appId) {
return response.data.map(extractComponentName);
} catch (error) {
console.error('ERROR:', error);
process.exit(1);
process.exit();
}
}

Expand Down
20 changes: 16 additions & 4 deletions src/syz-analysis-publisher.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,23 @@ var tableSvc;
var appId;
var analysisValue;
var callerCallBack;
var componentsFoundList;
var componentsNotFoundList;

var exports = module.exports;

exports.publish = function(appName, value, callBack) {
exports.publish = function (
appName,
value,
componentsFound,
componentsNotFound,
callBack
) {
appId = appName;
analysisValue = value;
callerCallBack = callBack
callerCallBack = callBack;
componentsFoundList = componentsFound;
componentsNotFoundList = componentsNotFound;

if (!areAzureStorageParamsValid()) {
callBack();
Expand Down Expand Up @@ -52,7 +62,9 @@ function onAppEntityInserted(error, result, response) {
var analysisEntity = {
PartitionKey: entGen.String(appId),
RowKey: entGen.String(`${new Date().getTime()}`),
value: entGen.Double(analysisValue)
value: entGen.Double(analysisValue),
componentsFound: entGen.String(componentsFoundList.toString()),
componentsNotFound: entGen.String(componentsNotFoundList.toString()),
};

tableSvc.insertOrMergeEntity(tableName, analysisEntity, onAnalysisEntityInserted);
Expand All @@ -66,7 +78,7 @@ function onAnalysisEntityInserted(error, result, response) {

function handleError(error) {
if (error) {
process.exit(1)
process.exit()
}
}

Expand Down
20 changes: 16 additions & 4 deletions src/syz-analyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@ exports.runAnalysis = async function (appName, expectedCoverage, breakBuild, src

printHeader();
const expectedComponents = await fetchExpectedComponentsList(appName);
const coverage = await calculateCoverage(expectedComponents, srcPath);
publisher.publish(appName, coverage, onResultsPublished);
const { coverage, componentsFound, componentsNotFound } = await calculateCoverage(expectedComponents, srcPath);

publisher.publish(
appName,
coverage,
componentsFound,
componentsNotFound,
onResultsPublished
);
}

function printHeader() {
Expand Down Expand Up @@ -88,7 +95,12 @@ async function calculateCoverage(expectedComponents, srcPath) {
coverage = ((compareResult.found.length / expectedComponents.length) * 100).toFixed(2)

console.log('INFO: SYZ Coverage:', coverage);
return coverage;

return {
coverage,
componentsFound: compareResult.found,
componentsNotFound: compareResult.notFound,
};
}

function onResultsPublished() {
Expand All @@ -102,6 +114,6 @@ function onResultsPublished() {
function abortIfNoName(appName) {
if (!appName) {
console.log('ERROR: No app name provided. Aborting analysis.');
process.exit(1);
process.exit();
}
}

0 comments on commit dd0383b

Please sign in to comment.