forked from ccxt/ccxt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcleanup-old-tags.js
94 lines (63 loc) · 2.29 KB
/
cleanup-old-tags.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
"use strict"
const { execSync } = require ('child_process')
const log = require ('ololog').noLocate
const { groupBy } = require ('../ccxt.js')
const { values } = Object
const assert = require ('assert')
function cleanupOldTags () {
const tags = execSync ('git tag').toString ().split ('\n').filter (s => s).map (t => {
const [major, minor, patch] = t.replace ('v', '').split ('.').map (Number)
assert (major < 100)
assert (minor < 100)
return {
key: (major * 100) + minor,
tag: t,
major,
minor,
patch,
}
})
const tagsByMajorMinor = values (groupBy (tags, 'key')).sort ((a, b) => a[0].key - b[0].key)
// Preserve all tags for first 5 minor versions
for (let i = 0; i < 5; i++) {
const tags = tagsByMajorMinor.pop ()
if (tags) {
log.green.bright ('Preserving', tags[0].tag, '...', tags[tags.length - 1].tag)
}
}
// For older versions, leave only "round" numbered versions (1/10th)
let tagsToDelete = []
for (const tags of tagsByMajorMinor) {
for (const { tag, patch } of tags) {
if (patch === 1) {
log.green ('Preserving', tag)
} else {
tagsToDelete.push (tag)
}
}
}
log.bright.red ('Deleting', tagsToDelete.length, 'tags...')
if (!process.argv.includes ('--paper')) {
/* If it happens on a CI server, we don't want it to fail the build because of a super
long execution time (one tag deletion takes ~5 sec...), hence that limit here */
if (process.argv.includes ('--limit')) {
tagsToDelete = tagsToDelete.slice (-500)
}
for (const tag of tagsToDelete) {
log.dim ('Deleting', tag)
execSync (`git tag -d ${tag} && git push origin :refs/tags/${tag}`)
}
}
}
// ============================================================================
// main entry point
if (require.main === module) {
// if called directly like `node module`
cleanupOldTags ()
} else {
// do nothing if required as a module
}
// ============================================================================
module.exports = {
cleanupOldTags,
}