Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] fixing script to generate metrics (fga-eps-mds/2024.2-ARANDU-DOC#23) #3

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 161 additions & 0 deletions scripts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
# Created by https://www.toptal.com/developers/gitignore/api/yarn,node
# Edit at https://www.toptal.com/developers/gitignore?templates=yarn,node

### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

### Node Patch ###
# Serverless Webpack directories
.webpack/

# Optional stylelint cache

# SvelteKit build / generate output
.svelte-kit

### yarn ###
# https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored

.yarn/*
!.yarn/releases
!.yarn/patches
!.yarn/plugins
!.yarn/sdks
!.yarn/versions

# if you are NOT using Zero-installs, then:
# comment the following lines
!.yarn/cache

# and uncomment the following lines
# .pnp.*

# End of https://www.toptal.com/developers/gitignore/api/yarn,node
26 changes: 26 additions & 0 deletions scripts/metrics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const REPO = '2024.2-ARANDU-APP';
const OWNER = 'fga-eps-mds';
const SONAR_ID = 'fga-eps-mds_2024.2-ARANDU-APP';

const METRIC_LIST = [
'files',
'functions',
'complexity',
'comment_lines_density',
'duplicated_lines_density',
'coverage',
'ncloc',
'tests',
'test_errors',
'test_failures',
'test_execution_time',
'security_rating'
];

const SONAR_URL = `https://sonarcloud.io/api/measures/component_tree?component=${SONAR_ID}&metricKeys=${METRIC_LIST.join(',')}&ps=500`;

module.exports = {
SONAR_URL,
REPO,
OWNER
};
13 changes: 13 additions & 0 deletions scripts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "scripts",
"version": "1.0.0",
"main": "index.js",
"license": "GPL-3.0 license",
"dependencies": {
"@octokit/core": "^5.0.1",
"axios": "^1.5.1",
"dotenv": "^16.3.1",
"fs": "0.0.1-security",
"gh-release-assets": "^2.0.1"
}
}
87 changes: 87 additions & 0 deletions scripts/release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
const { Octokit } = require('@octokit/core')
const ghReleaseAssets = require('gh-release-assets')
const axios = require('axios')
const fs = require('fs')
require('dotenv').config()

const { SONAR_URL, REPO, OWNER } = require('./metrics.js')

const { TOKEN, RELEASE_MAJOR, RELEASE_MINOR } = process.env

const octokit = new Octokit({ auth: TOKEN })

const now = new Date() // create a new Date object with the current date and time
const year = now.getFullYear().toString()
const month = (now.getMonth() + 1).toString().padStart(2, '0')
const day = now.getDate().toString().padStart(2, '0')
const hours = now.getHours().toString().padStart(2, '0')
const minutes = now.getMinutes().toString().padStart(2, '0')
const seconds = now.getSeconds().toString().padStart(2, '0')

const getLatestRelease = async () => {
const releases = await octokit.request('GET /repos/{owner}/{repo}/releases', {
owner: OWNER,
repo: REPO
})
if (releases?.data.length > 0) {
return releases?.data?.[0]?.tag_name
}
return '0.0.0'
}

const newTagName = async () => {
let oldTag = await getLatestRelease()
oldTag = oldTag.split('.')

if (RELEASE_MAJOR === 'true') {
const majorTagNum = parseInt(oldTag[0]) + 1
return majorTagNum + '.0.0'
} else if (RELEASE_MINOR === 'true') {
const minorTagNum = parseInt(oldTag[1]) + 1
return oldTag[0] + '.' + minorTagNum + '.0'
}
const fixTagNum = parseInt(oldTag[2]) + 1
return oldTag[0] + '.' + oldTag[1] + '.' + fixTagNum
}

const createRelease = async () => {
const tag = await newTagName()
const res = await octokit.request('POST /repos/{owner}/{repo}/releases', {
owner: OWNER,
repo: REPO,
tag_name: tag,
name: tag
})
return [res?.data?.upload_url, tag]
}

const saveSonarFile = async (tag) => {
const dirPath = './analytics-raw-data/'
fs.mkdirSync(dirPath)
const filePath = `${dirPath}fga-eps-mds-${REPO}-${month}-${day}-${year}-${hours}-${minutes}-${seconds}-${tag}.json`
await axios.get(SONAR_URL).then((res) => {
fs.writeFileSync(filePath, JSON.stringify(res?.data))
})
}

const uploadSonarFile = async (release) => {
await saveSonarFile(release[1])
ghReleaseAssets({
url: release[0],
token: [TOKEN],
assets: [
`./analytics-raw-data/fga-eps-mds-${REPO}-${month}-${day}-${year}-${hours}-${minutes}-${seconds}-${release[1]}.json`,
{
name: `fga-eps-mds-${REPO}-${month}-${day}-${year}-${hours}-${minutes}-${seconds}-${release[1]}.json`,
path: ''
}
]
})
}

const script = async () => {
const release = await createRelease()
await uploadSonarFile(release)
}

script()
Loading