nim-libp2p/tools/pinner.nim
Tanguy 1e7e95f5fd
Pin dependencies for CI (#677)
Adds a pin-file for CI. When a dependency break something in the libp2p, we don't want for the CI to be
broken on every branch, just on a "bump" branch that will update the pin-file & fix the eventual interop issue.
2021-12-16 18:00:10 +00:00

39 lines
1.1 KiB
Nim

import os
import strscans
import algorithm
import tables
import sequtils
import strutils
import json
import osproc
const PinFile = ".pinned"
removeDir("nimbledeps")
createDir("nimbledeps")
discard execCmd("nimble install -dy")
var allDeps: Table[string, string]
for (_, dependency) in walkDir("nimbledeps/pkgs"):
let fileContent = parseJson(readFile(dependency & "/nimblemeta.json"))
let url = fileContent.getOrDefault("url").getStr("")
var version = fileContent.getOrDefault("vcsRevision").getStr("")
var packageName = dependency.split('/')[^1].split('-')[0]
if version.len == 0:
version = execCmdEx("git ls-remote " & url).output.split()[0]
if version.len > 0 and url.len > 0:
let fullPackage = url & "@#" & version
if packageName in allDeps and allDeps[packageName] != fullPackage:
echo "Warning: duplicate package " & packageName & ":"
echo allDeps[packageName]
echo fullPackage
echo ""
allDeps[packageName] = fullPackage
else:
echo "Failed to get url & version for ", dependency
let asString = toSeq(allDeps.pairs).mapIt(it[0] & ";" & it[1]).sorted().join("\n")
writeFile(PinFile, asString)
echo asString