Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
EduardoPicolo committed Aug 23, 2022
2 parents 914f2a3 + 2b4e23a commit 34dffaa
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 1 deletion.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

# testing
/coverage
/metrics

# next.js
/.next/
Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/metrics.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Generate Metrics Release

on:
release:
types: [published]

jobs:
send-release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Use Node.js 16.x
uses: actions/setup-node@v2
with:
node-version: 16.x

- name: Create Metrics SonarCloud
run: node metrics/sonar-metrics.ts.mjs ${{ github.event.repository.name }} ${{ github.ref_name }}

- name: Commit Metrics SonarCloud File
run: |
git config --global user.email "${{ secrets.USER_EMAIL }}"
git config --global user.name "${{ secrets.USER_USERNAME }}"
git clone --single-branch --branch main "https://x-access-token:${{ secrets.REPO_TOKEN }}@github.com/fga-eps-mds/2022-1-schedula-doc" docs
mkdir -p docs/analytics-raw-data
cp -R fga-eps-mds*.json docs/analytics-raw-data
cd docs
git add .
git commit -m "Métricas SonarCloud - ${{ github.event.repository.name }} ${{ github.ref_name }}"
git push
echo "Metrics File Generated Successfully."
51 changes: 51 additions & 0 deletions metrics/sonar-metrics.ts.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import fs from "fs"
import https from "https"

const base_url =
"https://sonarcloud.io/api/measures/component_tree?component=fga-eps-mds_"
const file_name = "fga-eps-mds"
const metrics = [
"files",
"functions",
"complexity",
"comment_lines_density",
"duplicated_lines_density",
"coverage",
"ncloc",
"tests",
"test_errors",
"test_failures",
"test_execution_time",
"security_rating"
]

console.log(process.argv.slice(2))

const [repository, version] = process.argv.slice(2)

https
.get(base_url + repository + `&metricKeys=${metrics.join(",")}`, (res) => {
let data = ""
res.on("data", (chunk) => {
data += chunk
})
res.on("end", () => {
const date = new Date()
const formatedDate = `${
date.getMonth() + 1
}-${date.getDate()}-${date.getFullYear()}-${date.getHours()}-${date.getMinutes()}-${date.getSeconds()}`
fs.writeFile(
`${file_name}-${repository}-${formatedDate}-${version}.json`,
data,
function (err) {
if (err) return console.log(err)
console.log(err)
}
)

return data
})
})
.on("error", (err) => {
console.log(err.message)
})
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"out",
"bin",
".lintstagedrc.js",
"coverage"
"coverage",
"metrics/sonar-metrics.ts.mjs"
],
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"]
}

1 comment on commit 34dffaa

@vercel
Copy link

@vercel vercel bot commented on 34dffaa Aug 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.