-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.mjs
executable file
·104 lines (83 loc) · 3.06 KB
/
generate.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
#!/usr/bin/env zx
import * as aur from './src/aur.mjs'
if(!argv.v){
console.log("-v flag required")
process.exit()
}
function semverRegex() {
return /(?<=^v?|\sv?)(?:(?:0|[1-9]\d{0,9}?)\.){2}(?:0|[1-9]\d{0,9})(?:-(?:--+)?(?:0|[1-9]\d*|\d*[a-z]+\d*)){0,100}(?=$| |\+|\.)(?:(?<=-\S+)(?:\.(?:--?|[\da-z-]*[a-z-]\d*|0|[1-9]\d*)){1,100}?)?(?!\.)(?:\+(?:[\da-z]\.?-?){1,100}?(?!\w))?(?!\+)/gi;
}
const fileTooSmall = (filename) => {
return fs.statSync(filename).size < 1024*1024
}
export const downloadAndHashPackage = async ({version, download_url, filename}) => {
console.log(download_url)
fs.ensureDirSync("temp")
await $`curl -L '${download_url}' > ./temp/${filename}`.quiet()
if(fileTooSmall("temp/"+filename)) {
throw "error: downloaded empty package"
}
const version_hash = (await $`b2sum ./temp/${filename}`).stdout.split(" ")[0]
return {
version,
download_url,
version_hash,
filename,
}
}
export const getLatestVersion = async ()=>{
const payload = await (await fetch("https://api.github.com/repos/erigontech/erigon/releases")).json()
const version = payload[0].tag_name.replace("v","")
return version
}
const main = async ()=>{
// remove tmp dir
try {
fs.rmSync("temp", {recursive: true})
}catch{
}
let version = argv.v
if(version === "latest") {
version = await getLatestVersion("latest")
}
console.log(chalk.green(`using latest version: ${version}`))
if(!semverRegex().test(version)) {
console.error(`version ${version} failed regex for semver`)
process.exit(1)
}
const aurBin = async ()=> {
const pkgPath = await aur.formBinPackage(await downloadAndHashPackage({
filename: `bin-v${version}.tar.gz`,
download_url: `https://github.com/erigontech/erigon/releases/download/v${version}/erigon_v${version}_linux_amd64.tar.gz`,
version
}))
await $`git clone [email protected]:erigon-bin.git ./temp/erigon-bin`
await $`find ${pkgPath} -type f | xargs mv -t ./temp/erigon-bin`
if(argv.publish === true || argv.publish === "true") {
await $`cd ./temp/erigon-bin && git add -A && git commit -m "update to ${version}" && git push`.catch(console.log)
} else {
console.log(chalk.green("dry run success. run with flag --publish to publish"))
}
}
const aurSrc = async ()=> {
const pkgPath = await aur.formSourcePackage(await downloadAndHashPackage({
filename: `src-v${version}.tar.gz`,
download_url: `https://github.com/erigontech/erigon/archive/refs/tags/v${version}.tar.gz`,
version,
}))
await $`git clone [email protected]:erigon.git ./temp/erigon`
await $`find ${pkgPath} -type f | xargs mv -t ./temp/erigon`
if(argv.publish === true || argv.publish === "true") {
await $`cd ./temp/erigon && git add -A && git commit -m "update to ${version}" && git push`.catch(console.log)
} else {
console.log(chalk.green("dry run success. run with flag --publish to publish"))
}
}
await aurBin()
await aurSrc()
process.exit(0)
}
main().catch((e)=>{
console.error(chalk.red(e))
process.exit(1)
})