-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.mjs
139 lines (120 loc) · 3.83 KB
/
index.mjs
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
127
128
129
130
131
132
133
134
135
136
137
138
139
// @ts-check
import dotenv from 'dotenv'
import fetch from 'node-fetch'
import { writeFileSync } from 'fs'
// Load .env files
dotenv.config()
// Environment settings
const api_base = process.env.API_BASE
const wallet_token = process.env.WALLET_TOKEN
const hub_token = process.env.HUB_TOKEN
const keyguard_token = process.env.KEYGUARD_TOKEN
/**
* @typedef {{
* message: string,
* name: string,
* protected: boolean,
* release: string | null,
* target: string,
* commit: {
* author_email: string,
* author_name: string,
* authored_date: string,
* committed_date: string,
* committer_email: string,
* committer_name: string,
* created_at: string,
* id: string,
* message: string,
* parent_ids: string[],
* short_id: string,
* title: string,
* web_url: string,
* },
* }} Tag
*/
/**
* @typedef {{
* app: 'Wallet' | 'Hub' | 'Keyguard',
* version: string,
* date: string,
* message: string,
* env: 'main' | 'test',
* }} Release
*/
/**
*
* @param {string} project_path
* @param {string} token
* @returns {Promise<Tag[]>}
*/
async function get_tags(project_path, token) {
return fetch(`${api_base}/api/v4/projects/${encodeURIComponent(project_path)}/repository/tags`, {
headers: {
'Authorization': `Bearer ${token}`,
},
})
.then(async response => {
if (!response.ok) throw new Error(await response.text())
return response.json()
})
.catch(error => console.error(error))
}
/**
*
* @param {Tag} tag
* @param {'Wallet' | 'Hub' | 'Keyguard'} app
* @returns {Release}
*/
function toRelease(tag, app) {
const version = tag.name.split('-').find(part => part.startsWith('v'))
const date = new Date(tag.commit.authored_date).toJSON()
const message = tag.commit.message.split('\n').filter(line => !line.startsWith('Nimiq ')).join('\n')
const env = tag.name.includes('test') ? 'test' : 'main'
return {
app,
version,
date,
message,
env,
}
}
const IGNORED_TAGS = [
"v2.0.3-1-main-soeren", // Hub
"v3.0.5-1-main-soeren", // Wallet
]
async function main() {
console.log('Fetching Wallet tags...')
const wallet_releases = (await get_tags('deployment/wallet', wallet_token))
.filter(tag => !IGNORED_TAGS.includes(tag.name))
.map(tag => toRelease(tag, 'Wallet'))
console.log('Fetching Hub tags...')
const hub_releases = (await get_tags('deployment/hub', hub_token))
.filter(tag => !IGNORED_TAGS.includes(tag.name))
.map(tag => toRelease(tag, 'Hub'))
console.log('Fetching Keyguard tags...')
const keyguard_releases = (await get_tags('deployment/keyguard', keyguard_token))
.filter(tag => !IGNORED_TAGS.includes(tag.name))
.map(tag => toRelease(tag, 'Keyguard'))
/** @type {Release[]} */
const mainnet_releases = []
/** @type {Release[]} */
const testnet_releases = []
for (const release of [...wallet_releases, ...hub_releases, ...keyguard_releases]) {
if (release.message.includes('[exclude-release]')) continue
if (release.env === 'test') {
testnet_releases.push(release)
} else {
mainnet_releases.push(release)
}
}
// Sort newest first
mainnet_releases.sort((a, b) => a.date > b.date ? -1 : a.date === b.date ? 0 : 1)
testnet_releases.sort((a, b) => a.date > b.date ? -1 : a.date === b.date ? 0 : 1)
console.log('Writing Mainnet release JSON...')
writeFileSync('./public/mainnet_releases.json', JSON.stringify(mainnet_releases))
console.log('Writing Testnet release JSON...')
writeFileSync('./public/testnet_releases.json', JSON.stringify(testnet_releases))
console.log('FINISHED')
}
main()