-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.js
126 lines (104 loc) · 3.72 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
const axios = require('axios')
const yaml = require('js-yaml')
const fs = require('fs')
require('process')
const chartRepos = [
'DeployHubProject/charts',
'ortelius/ms-compitem-crud',
'ortelius/ms-dep-pkg-cud',
'ortelius/ms-dep-pkg-r',
'ortelius/ms-postgres',
'ortelius/ms-sbom-export',
'ortelius/ms-scorecard',
'ortelius/ms-textfile-crud',
'ortelius/ms-validate-user',
'ortelius/scec-arangodb',
'ortelius/scec-deppkg',
'ortelius/scec-vulnerability'
]
// Helper functions
async function getChartEntries () {
let sha = ''
await axios.get('https://api.github.com/repos/DeployHubProject/DeployHub-Pro/commits/main').then(response => {
sha = response.data.sha
})
const url = 'https://raw.githubusercontent.com/DeployHubProject/DeployHub-Pro/' + sha + '/charts/deployhub/Chart.yaml'
let parts = []
let latest = ''
let ver = ''
await axios.get(url).then(response => {
const parsedYaml = yaml.load(response.data)
chartVersion = parsedYaml.version
parts = chartVersion.split('.')
ver = parseInt(parts[2]) + 1
parts[2] = ver.toString()
chartVersion = parts.join('.')
})
const latestChart = []
for (let i = 0; i < chartRepos.length; i++) {
await axios.get('https://api.github.com/repos/' + chartRepos[i] + '/commits/gh-pages').then(response => {
sha = response.data.sha
})
const repoUrl = 'https://raw.githubusercontent.com/' + chartRepos[i] + '/' + sha + '/index.yaml'
await axios.get(repoUrl).then(response => {
const parsedYaml = yaml.load(response.data)
const entries = parsedYaml.entries
Object.keys(entries).forEach(key => {
latest = null
Object.entries(entries[key]).forEach(entry => {
if (latest == null) { latest = entry } else if (latest.created < entry.created) { latest = entry }
})
latest = latest[1]
if (latest.name !== 'dh-jwt' && latest.name !== 'dh-postgres' && latest.name !== 'dh-ms-ui' && latest.name !== 'dh-ms-nginx' && latest.name !== 'dh-ms-general') {
const dep = {}
dep.name = latest.name
dep.version = latest.version
if (key === 'ms-ui' || key === 'ms-nginx' || key === 'ms-general') {
key = 'charts'
dep.repository = 'https://deployhubproject.github.io/' + key + '/'
} else { dep.repository = 'https://ortelius.github.io/' + key + '/' }
if (key === 'ms-postgres') { dep.condition = 'global.postgresql.enabled' }
latestChart.push(dep)
}
// chartEntries[key] = entries[key]
// console.log(entries[key]);
})
})
}
chartEntries = latestChart
return latestChart
}
function createYamlOutput () {
const output = yaml.dump({
apiVersion: 'v2',
name: 'deployhub',
description: 'DeployHub Pro',
home: 'https://www.deployhub.com',
icon: 'https://deployhubproject.github.io/DeployHub-Pro/deployhub.svg',
keywords: ['Service Catalog', 'Microservices', 'SBOM'],
type: 'application',
version: chartVersion,
appVersion: '10.0.0',
dependencies: chartEntries
}, { noArrayIndent: true })
fs.readFile('./charts/deployhub/README.md', 'utf8', function (err, data) {
if (err) {
return console.log(err)
}
const result = data.replace(/DEPLOYHUB_VERSION=\d+\.\d+\.\d+/g, 'DEPLOYHUB_VERSION=' + chartVersion)
fs.writeFile('./charts/deployhub/README.md', result, 'utf8', function (err) {
if (err) return console.log(err)
})
})
return output
}
// -----------------
let chartEntries = []
let chartVersion = ''
getChartEntries().then(() => {
const yamlOutput = createYamlOutput()
console.log(yamlOutput)
fs.writeFileSync('./charts/deployhub/Chart.yaml', yamlOutput, 'utf8', (err) => {
console.log(err)
})
})