Skip to content

Commit

Permalink
add valid labels and more function
Browse files Browse the repository at this point in the history
release test

wip

Version Packages (#14)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

improve cicd

Version Packages (#15)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

wip

Version Packages (#16)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

ignore build if image exists

wip

wip

wip

wip

wip

wip

Version Packages (#17)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

wip

Version Packages (#18)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

wip

Version Packages (#19)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

wip

Version Packages (#20)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

wip

Version Packages (#21)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

wip

wip

Version Packages (#22)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

wip

Version Packages (#23)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

wip

Version Packages (#24)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

wip

Version Packages (#25)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

wip

wip

Version Packages (#26)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

Version Packages (#27)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

wip

Version Packages (#28)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

wip

Version Packages (#29)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

wip

Version Packages (#30)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

wip

Version Packages (#31)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
diogoViana95 and github-actions[bot] committed Nov 25, 2023
1 parent 91f7a0a commit 1f64d33
Show file tree
Hide file tree
Showing 9 changed files with 199 additions and 39 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Publish Docker Image

# Trigger the workflow on tag creation wth format vx.x.x
on:
push:
tags:
- 'v**'

jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3
- name: Get Package Version
id: get-package-version
uses: stevenbenitez/get-package-version-action@v1
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_SECRET }}
- name: Build and push
uses: docker/build-push-action@v5
with:
push: true
tags: |
${{ secrets.DOCKER_USERNAME }}/report-metric-server:latest
${{ secrets.DOCKER_USERNAME }}/report-metric-server:${{ steps.get-package-version.outputs.version }}
24 changes: 0 additions & 24 deletions .github/workflows/push.yaml

This file was deleted.

24 changes: 13 additions & 11 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@ jobs:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3

- name: Setup Node.js 16.x
uses: actions/setup-node@v3
- uses: actions/checkout@v3
with:
token: ${{ secrets.PAT }}
- uses: pnpm/action-setup@v2
with:
version: 8.6.12
- uses: actions/setup-node@v3
with:
node-version: 18.16.0

- name: Install Dependencies
run: yarn

- name: Create Release Pull Request
cache: 'pnpm'
- run: pnpm install --frozen-lockfile
- name: Create Release Pull Request or Publish
id: changesets
uses: changesets/action@v1
with:
publish: pnpm run release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.PAT }}
109 changes: 109 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,114 @@
# @deadcow-enterprises/junit-prometheus-exporter

## 0.0.20

### Patch Changes

- 9d0fc14: wip

## 0.0.19

### Patch Changes

- 841e57e: wip

## 0.0.18

### Patch Changes

- f577d41: wip

## 0.0.17

### Patch Changes

- 23a7b46: wip

## 0.0.16

### Patch Changes

- 5b2df1b: wip

## 0.0.15

### Patch Changes

- e0b2896: wip

## 0.0.14

### Patch Changes

- a947b91: wip

## 0.0.13

### Patch Changes

- 8b3ca1b: wip

## 0.0.12

### Patch Changes

- 573f279: wip

## 0.0.11

### Patch Changes

- 759bea1: wip

## 0.0.10

### Patch Changes

- 6bf48f7: asdasddf

## 0.0.9

### Patch Changes

- ce37be4: wip

## 0.0.8

### Patch Changes

- ec01a2c: wip

## 0.0.7

### Patch Changes

- d77fdde: wip

## 0.0.6

### Patch Changes

- 2ec8f0b: wip

## 0.0.5

### Patch Changes

- 9f39697: wip

## 0.0.4

### Patch Changes

- b313824: improve cicd

## 0.0.3

### Patch Changes

- 375a391: Tweaks
- 883b4ad: Tweaks

## 0.0.2

### Patch Changes
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@deadcow-enterprises/junit-prometheus-exporter",
"version": "0.0.2",
"version": "0.0.20",
"description": "Convert test reports to metrics",
"author": "deadcow.enterprises",
"private": true,
Expand All @@ -13,7 +13,8 @@
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest --watch --coverage",
"test:ci": "jest --coverage",
"test:e2e": "jest --config ./test/jest-e2e.json --coverage"
"test:e2e": "jest --config ./test/jest-e2e.json --coverage",
"release": "changeset tag"
},
"dependencies": {
"@nestjs/common": "^10.0.0",
Expand Down
1 change: 1 addition & 0 deletions src/models/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface PropertySchema {
type: 'variable' | 'counter';
description: string;
value: string;
validLabels?: string[];
labelEquality: string;
labelEqualityResolution: 'replace' | 'add' | 'ignore';
}
13 changes: 13 additions & 0 deletions src/schemas/junit-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,47 @@
"total_test_runs": {
"type": "counter",
"description": "Total tests runs",
"validLabels": ["project", "team", "version"],
"labelEquality": "{currentLabels.project} == {newLabels.project} && {newLabels.team} == {currentLabels.team}",
"labelEqualityResolution": "replace"
},
"total_test_duration_ms": {
"type": "variable",
"description": "Total tests run duration",
"value": "{Round(testsuites.$.time)} * 1000",
"validLabels": ["project", "team", "version"],
"labelEquality": "{currentLabels.project} == {newLabels.project} && {newLabels.team} == {currentLabels.team}",
"labelEqualityResolution": "replace"
},
"total_tests": {
"type": "variable",
"description": "Total number of tests run",
"value": "{testsuites.$.tests}",
"validLabels": ["project", "team", "version"],
"labelEquality": "{currentLabels.project} == {newLabels.project} && {newLabels.team} == {currentLabels.team}",
"labelEqualityResolution": "replace"
},
"total_errors": {
"type": "variable",
"description": "Total number of tests failing",
"value": "{testsuites.$.failures}",
"validLabels": ["project", "team", "version"],
"labelEquality": "{currentLabels.project} == {newLabels.project} && {newLabels.team} == {currentLabels.team}",
"labelEqualityResolution": "replace"
},
"total_disabled": {
"type": "variable",
"description": "Total number of tests disabled",
"value": "{testsuites.$.disabled}",
"validLabels": ["project", "team", "version"],
"labelEquality": "{currentLabels.project} == {newLabels.project} && {newLabels.team} == {currentLabels.team}",
"labelEqualityResolution": "replace"
},
"total_success": {
"type": "variable",
"description": "Total number of tests passing",
"value": "$total_tests - $total_errors",
"validLabels": ["project", "team", "version"],
"labelEquality": "{currentLabels.project} == {newLabels.project} && {newLabels.team} == {currentLabels.team}",
"labelEqualityResolution": "replace"
}
Expand Down
17 changes: 15 additions & 2 deletions src/services/parsers/slurper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type PropertyParser<T> = {
type: PropertySchema['type'];
name: string;
pattern: Array<string | ((content: T, values: Labels, oldValue: any) => any)>;
validLabels?: PropertySchema['validLabels'];
equalityResolution?: PropertySchema['labelEqualityResolution'];
equality: Array<string | ((currentLabels: Labels, newLabels: Labels) => any)>;
};
Expand Down Expand Up @@ -50,6 +51,7 @@ export abstract class Slurper<T = any> {
type: curr.type,
name,
pattern,
validLabels: curr.validLabels,
equality: labelPattern,
equalityResolution: curr.labelEqualityResolution,
});
Expand Down Expand Up @@ -143,18 +145,29 @@ export abstract class Slurper<T = any> {
return;
}
if (g.equalityResolution === 'replace') {
curr.values[valueIndex].labels = labels;
curr.values[valueIndex].labels = this.getValidLabels(
labels,
g.validLabels,
);
curr.values[valueIndex].value = result;
return;
}
}

curr.values.push({
labels,
labels: this.getValidLabels(labels, g.validLabels),
value: result,
});
});
}

private getValidLabels(labels: Labels, validLabels?: string[]) {
const valid: Labels = {};
validLabels?.forEach((l) => {
valid[l] = labels[l];
});
return valid;
}
private getLabelIndex(
property: Property,
p: PropertyParser<T>,
Expand Down
12 changes: 12 additions & 0 deletions src/utils/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ const operationMap = {
Flat: (content: unknown) => (Array.isArray(content) ? content.flat() : []),
Keys: (content: unknown) => Object.keys(content || {}),
Values: (content: unknown) => Object.values(content || {}),
Max: (content: unknown) => {
if (!Array.isArray(content)) return 0;
return Math.max(...content);
},
Min: (content: unknown) => {
if (!Array.isArray(content)) return 0;
return Math.min(...content);
},
Avg: (content: unknown) => {
if (!Array.isArray(content)) return 0;
return content.reduce((acc, curr) => acc + curr, 0) / content.length;
},
};

type Operation = (content: unknown) => any;
Expand Down

0 comments on commit 1f64d33

Please sign in to comment.