From abef65cce45fa885cbfa85eb2205626019f55552 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Sat, 18 Jan 2025 22:31:05 -0700 Subject: [PATCH 01/42] rename publishTags to publishVersions and add tests --- src/nimble.nim | 4 +- src/nimblepkg/options.nim | 22 ++-- src/nimblepkg/publish.nim | 43 ++++--- tests/tester.nim | 1 + tests/tpublish.nim | 237 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 279 insertions(+), 28 deletions(-) create mode 100644 tests/tpublish.nim diff --git a/src/nimble.nim b/src/nimble.nim index ba1c3f83..c0db5bdb 100644 --- a/src/nimble.nim +++ b/src/nimble.nim @@ -2382,9 +2382,9 @@ proc doAction(options: var Options) = of actionPublish: var pkgInfo = getPkgInfo(getCurrentDir(), options) publish(pkgInfo, options) - of actionPublishTags: + of actionPublishVersions: var pkgInfo = getPkgInfo(getCurrentDir(), options) - publishTags(pkgInfo, options) + publishVersions(pkgInfo, options) of actionDump: dump(options) of actionTasks: diff --git a/src/nimblepkg/options.nim b/src/nimblepkg/options.nim index cf18e14b..afee297d 100644 --- a/src/nimblepkg/options.nim +++ b/src/nimblepkg/options.nim @@ -71,7 +71,7 @@ type actionUninstall, actionCompile, actionDoc, actionCustom, actionTasks, actionDevelop, actionCheck, actionLock, actionRun, actionSync, actionSetup, actionClean, actionDeps, actionShellEnv, actionShell, actionAdd, actionManual, - actionPublishTags + actionPublishVersions DevelopActionType* = enum datAdd, datRemoveByPath, datRemoveByName, datInclude, datExclude @@ -125,8 +125,8 @@ type depsAction*: string of actionPublish: publishAction*: string - of actionPublishTags: - onlyListTags*: bool + of actionPublishVersions: + createTags*: bool of actionShellEnv, actionShell: discard @@ -180,9 +180,9 @@ Commands: publish Publishes a package on nim-lang/packages. The current working directory needs to be the top level directory of the Nimble package. - publishTags Finds and publishes new tags based on the - commits where a package's Nimble file changed. - [-l, --listOnly] Only list the tags and versions which are found without + publishVersions Finds package versions based on commits + where the package's Nimble version changed. + [-c, --create] Only list the tags and versions which are found without actually performing tag or publishing them. uninstall [pkgname, ...] Uninstalls a list of packages. [-i, --inclDeps] Uninstalls package and dependent package(s). @@ -338,8 +338,8 @@ proc parseActionType*(action: string): ActionType = result = actionUninstall of "publish": result = actionPublish - of "publishtags": - result = actionPublishTags + of "publishversions": + result = actionPublishVersions of "upgrade": result = actionUpgrade of "tasks": @@ -773,10 +773,10 @@ proc parseFlag*(flag, val: string, result: var Options, kind = cmdLongOption) = result.action.publishAction = "tags" else: wasFlagHandled = false - of actionPublishTags: + of actionPublishVersions: case f - of "l", "listonly": - result.action.onlyListTags = true + of "c", "create": + result.action.createTags = true else: wasFlagHandled = false of actionDeps: diff --git a/src/nimblepkg/publish.nim b/src/nimblepkg/publish.nim index b48d607f..55467dc8 100644 --- a/src/nimblepkg/publish.nim +++ b/src/nimblepkg/publish.nim @@ -7,7 +7,7 @@ import system except TResult import httpclient, strutils, json, os, browsers, times, uri import common, tools, cli, config, options, packageinfotypes, sha1hashes, version, download -import strformat, sequtils, pegs, sets +import strformat, sequtils, pegs, sets, tables {.warning[UnusedImport]: off.} from net import SslCVerifyMode, newContext @@ -285,7 +285,7 @@ proc createTag*(tag: string, commit: Sha1Hash, message, repoDir, nimbleFile: str proc findVersions(commits: seq[(Sha1Hash, string)], projdir, nimbleFile: string, downloadMethod: DownloadMethod, options: Options) = ## parse the versions var - versions: HashSet[Version] + versions: OrderedTable[Version, tuple[commit: Sha1Hash, message: string]] existingTags: HashSet[Version] for tag in getTagsList(projdir, downloadMethod): let tag = tag.strip(leading=true, chars={'v'}) @@ -301,20 +301,33 @@ proc findVersions(commits: seq[(Sha1Hash, string)], projdir, nimbleFile: string, for line in diffs: var matches: array[0..MaxSubpatterns, string] if line.find(peg"'+version' \s* '=' \s* {[\34\39]} {@} $1", matches) > -1: - let version = newVersion(matches[1]) - if version notin versions: - versions.incl(version) - if version in existingTags: - displayInfo(&"Found existing tag for version {version} at commit {commit}", HighPriority) + let ver = newVersion(matches[1]) + if ver notin versions: + versions[ver] = (commit: commit, message: message) + if ver in existingTags: + displayInfo(&"Found existing tag for version {ver} at commit {commit}", HighPriority) else: - displayInfo(&"Found new version {version} at {commit}", HighPriority) - if not options.action.onlyListTags: - displayWarning(&"Creating tag for new version {version} at {commit}", HighPriority) - let res = createTag(&"v{version}", commit, message, projdir, nimbleFile, downloadMethod) - if not res: - displayError(&"Unable to create tag {version}", HighPriority) - -proc publishTags*(p: PackageInfo, options: Options) = + displayInfo(&"Found new version {ver} at {commit}", HighPriority) + + if versions.len() >= 2: + let versions = versions.pairs().toSeq() + var badVersions: seq[int] + var prev = versions[0] + for idx in 1 ..< versions.len() - 1: + let + (ver, info) = versions[idx] + + if ver <= prev[0]: + displayError(&"bad version found at tags {ver}@{info.commit} and previous tag at {prev[0]}@{prev[1]}", HighPriority) + + for (version, info) in versions.pairs: + if options.action.createTags: + displayWarning(&"Creating tag for new version {version} at {info.commit}", HighPriority) + let res = createTag(&"v{version}", info.commit, info.message, projdir, nimbleFile, downloadMethod) + if not res: + displayError(&"Unable to create tag {version}", HighPriority) + +proc publishVersions*(p: PackageInfo, options: Options) = displayInfo(&"Searcing for new tags for {$p.basicInfo.name} @{$p.basicInfo.version}", HighPriority) let (projdir, file, ext) = p.myPath.splitFile() let nimblefile = file & ext diff --git a/tests/tester.nim b/tests/tester.nim index 9091a49e..21632fdb 100644 --- a/tests/tester.nim +++ b/tests/tester.nim @@ -12,6 +12,7 @@ import tdevelopfeature import tissues import tlocaldeps import tlockfile +import tpublish import tmisctests import tmoduletests import tmultipkgs diff --git a/tests/tpublish.nim b/tests/tpublish.nim new file mode 100644 index 00000000..7a461b29 --- /dev/null +++ b/tests/tpublish.nim @@ -0,0 +1,237 @@ +# Copyright (C) Dominik Picheta. All rights reserved. +# BSD License. Look at license.txt for more info. + +{.used.} + +import unittest, os, strformat, json, strutils, sequtils + +import testscommon + +import nimblepkg/displaymessages +import nimblepkg/sha1hashes +import nimblepkg/paths +import nimblepkg/vcstools + +from nimblepkg/common import cd, dump, cdNewDir +from nimblepkg/tools import tryDoCmdEx, doCmdEx +from nimblepkg/packageinfotypes import DownloadMethod +from nimblepkg/lockfile import LockFileJsonKeys +from nimblepkg/options import defaultLockFileName +from nimblepkg/developfile import ValidationError, ValidationErrorKind, + developFileName, getValidationErrorMessage + +suite "publish": + const + tempDir = getTempDir() / "tpublish" + + originsDirName = "origins" + originsDirPath = tempDir / originsDirName + + nimbleFileTemplate = """ + +version = "$1" +author = "Ivan Bobev" +description = "A new awesome nimble package" +license = "MIT" +requires "nim >= 1.5.1" +""" + + proc newNimbleFileContent(pkgName, fileTemplate: string, + deps: seq[string]): string = + result = fileTemplate % pkgName + if deps.len == 0: + return + result &= "requires " + for i, dep in deps: + result &= &"\"{dep}\"" + if i != deps.len - 1: + result &= "," + + proc addFiles(files: varargs[string]) = + var filesStr = "" + for file in files: + filesStr &= file & " " + tryDoCmdEx("git add " & filesStr) + + proc commit(msg: string) = + tryDoCmdEx("git commit -am " & msg.quoteShell) + + proc push(remote: string) = + tryDoCmdEx( + &"git push --set-upstream {remote} {vcsTypeGit.getVcsDefaultBranchName}") + + proc pull(remote: string) = + tryDoCmdEx("git pull " & remote) + + proc addRemote(remoteName, remoteUrl: string) = + tryDoCmdEx(&"git remote add {remoteName} {remoteUrl}") + + proc configUserAndEmail = + tryDoCmdEx("git config user.name \"John Doe\"") + tryDoCmdEx("git config user.email \"john.doe@example.com\"") + + proc initRepo(isBare = false) = + let bare = if isBare: "--bare" else: "" + tryDoCmdEx("git init " & bare) + configUserAndEmail() + + proc clone(urlFrom, pathTo: string) = + tryDoCmdEx(&"git clone {urlFrom} {pathTo}") + cd pathTo: configUserAndEmail() + + proc branch(branchName: string) = + tryDoCmdEx(&"git branch {branchName}") + + proc checkout(what: string) = + tryDoCmdEx(&"git checkout {what}") + + proc createBranchAndSwitchToIt(branchName: string) = + if branchName.len > 0: + branch(branchName) + checkout(branchName) + + proc initNewNimbleFile(dir: string, deps: seq[string] = @[]): string = + let pkgName = dir.splitPath.tail + let nimbleFileName = pkgName & ".nimble" + let nimbleFileContent = newNimbleFileContent( + pkgName, nimbleFileTemplate, deps) + writeFile(nimbleFileName, nimbleFileContent) + return nimbleFileName + + proc initNewNimblePackage(dir, clonePath: string, deps: seq[string] = @[]) = + cdNewDir dir: + initRepo() + let nimbleFileName = dir.initNewNimbleFile(deps) + addFiles(nimbleFileName) + commit("Initial commit") + + clone(dir, clonePath) + + proc addAdditionalFileToTheRepo(fileName, fileContent: string) = + writeFile(fileName, fileContent) + addFiles(fileName) + commit("Add additional file") + + proc testLockedVcsRevisions(deps: seq[tuple[name, path: string]], lockFileName = defaultLockFileName) = + check lockFileName.fileExists + + let json = lockFileName.readFile.parseJson + for (depName, depPath) in deps: + let expectedVcsRevision = depPath.getVcsRevision + check depName in json{$lfjkPackages} + let lockedVcsRevision = + json{$lfjkPackages}{depName}{$lfjkPkgVcsRevision}.str.initSha1Hash + check lockedVcsRevision == expectedVcsRevision + + proc testLockFile(deps: seq[tuple[name, path: string]], isNew: bool, lockFileName = defaultLockFileName) = + ## Generates or updates a lock file and tests whether it contains + ## dependencies with given names at given repository paths and whether their + ## VCS revisions match the written in the lock file ones. + ## + ## `isNew` - indicates whether it is expected a new lock file to be + ## generated if its value is `true` or already existing lock file to be + ## updated otherwise. + + if isNew: + check not fileExists(lockFileName) + else: + check fileExists(lockFileName) + + let (output, exitCode) = if lockFileName == defaultLockFileName: + execNimbleYes("lock") + else: + execNimbleYes("--lock-file=" & lockFileName, "lock") + + check exitCode == QuitSuccess + + var lines = output.processOutput + if isNew: + check lines.inLinesOrdered(generatingTheLockFileMsg) + check lines.inLinesOrdered(lockFileIsGeneratedMsg) + else: + check lines.inLinesOrdered(updatingTheLockFileMsg) + check lines.inLinesOrdered(lockFileIsUpdatedMsg) + + testLockedVcsRevisions(deps, lockFileName) + + template filesAndDirsToRemove() = + removeFile pkgListFilePath + removeDir installDir + removeDir tempDir + + template cleanUp() = + filesAndDirsToRemove() + defer: filesAndDirsToRemove() + + proc writePackageListFile(path: string, content: PackagesListFileContent) = + let dir = path.splitPath.head + createDir dir + writeFile(path, (%content).pretty) + + template withPkgListFile(body: untyped) = + writePackageListFile( + pkgListFilePath, @[dep1PkgListFileRecord, dep2PkgListFileRecord]) + usePackageListFile pkgListFilePath: + body + + proc getRepoRevision: string = + result = tryDoCmdEx("git rev-parse HEAD").replace("\n", "") + + proc getRevision(dep: string, lockFileName = defaultLockFileName): string = + result = lockFileName.readFile.parseJson{$lfjkPackages}{dep}{$lfjkPkgVcsRevision}.str + + proc addAdditionalFileAndPushToRemote( + repoPath, remoteName, remotePath, fileContent: string) = + cdNewDir remotePath: + initRepo(isBare = true) + cd repoPath: + # Add commit to the dependency. + addAdditionalFileToTheRepo("dep1.nim", fileContent) + addRemote(remoteName, remotePath) + # Push it to the newly added remote to be able to lock. + push(remoteName) + + proc testDepsSync = + let (output, exitCode) = execNimbleYes("sync") + check exitCode == QuitSuccess + let lines = output.processOutput + check lines.inLines( + pkgWorkingCopyIsSyncedMsg(dep1PkgName, dep1PkgRepoPath)) + check lines.inLines( + pkgWorkingCopyIsSyncedMsg(dep2PkgName, dep2PkgRepoPath)) + + cd mainPkgRepoPath: + # After successful sync the revisions written in the lock file must + # match those in the lock file. + testLockedVcsRevisions(@[(dep1PkgName, dep1PkgRepoPath), + (dep2PkgName, dep2PkgRepoPath)]) + + test "test publishVersions": + cleanUp() + cd "nimdep": + removeFile "nimble.develop" + removeFile "nimble.lock" + removeDir "Nim" + + check execNimbleYes("-y", "develop", "nim").exitCode == QuitSuccess + cd "Nim": + let (_, exitCode) = execNimbleYes("-y", "install") + check exitCode == QuitSuccess + + # check if the compiler version will be used when doing build + testLockFile(@[("nim", "Nim")], isNew = true) + removeFile "nimble.develop" + removeDir "Nim" + + let (output, exitCodeInstall) = execNimbleYes("-y", "build") + check exitCodeInstall == QuitSuccess + let usingNim = when defined(Windows): "nim.exe for compilation" else: "bin/nim for compilation" + check output.contains(usingNim) + + # check the nim version + let (outputVersion, _) = execNimble("version") + check outputVersion.contains(getRevision("nim")) + + let (outputGlobalNim, exitCodeGlobalNim) = execNimbleYes("-y", "--use-system-nim", "build") + check exitCodeGlobalNim == QuitSuccess + check not outputGlobalNim.contains(usingNim) From 5fbdfde759f931fd2f86fba6c9b829e777376eee Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Sat, 18 Jan 2025 22:58:09 -0700 Subject: [PATCH 02/42] adding check for monotonicity --- src/nimblepkg/publish.nim | 19 +++++++++++------ tests/tpublish.nim | 45 +-------------------------------------- 2 files changed, 14 insertions(+), 50 deletions(-) diff --git a/src/nimblepkg/publish.nim b/src/nimblepkg/publish.nim index 55467dc8..51170bce 100644 --- a/src/nimblepkg/publish.nim +++ b/src/nimblepkg/publish.nim @@ -7,7 +7,7 @@ import system except TResult import httpclient, strutils, json, os, browsers, times, uri import common, tools, cli, config, options, packageinfotypes, sha1hashes, version, download -import strformat, sequtils, pegs, sets, tables +import strformat, sequtils, pegs, sets, tables, algorithm {.warning[UnusedImport]: off.} from net import SslCVerifyMode, newContext @@ -309,16 +309,23 @@ proc findVersions(commits: seq[(Sha1Hash, string)], projdir, nimbleFile: string, else: displayInfo(&"Found new version {ver} at {commit}", HighPriority) + var nonMonotonicVers: Table[Version, Sha1Hash] if versions.len() >= 2: let versions = versions.pairs().toSeq() - var badVersions: seq[int] - var prev = versions[0] + var monotonics: seq[Version] for idx in 1 ..< versions.len() - 1: let + prev = versions[idx-1] (ver, info) = versions[idx] - - if ver <= prev[0]: - displayError(&"bad version found at tags {ver}@{info.commit} and previous tag at {prev[0]}@{prev[1]}", HighPriority) + prevMonotonicsOk = monotonics.mapIt(ver < it).all(proc (x: bool): bool = x) + + if ver < prev[0] and prevMonotonicsOk: + displayDetails(&"versions ok at tags {ver}@{info.commit} and previous tag of {prev[0]}@{prev[1]}", HighPriority) + else: + if prev[0] notin nonMonotonicVers: + monotonics.add(prev[0]) # track last largest monotonic so we can check, e.g. 0.2, 3.0, 0.3 and not 0.2, 3.0, 0.2 + nonMonotonicVers[ver] = info.commit + displayError(&"bad version found with tag {ver}@{info.commit} and previous tag at {prev[0]}@{prev[1]}", HighPriority) for (version, info) in versions.pairs: if options.action.createTags: diff --git a/tests/tpublish.nim b/tests/tpublish.nim index 7a461b29..c169325e 100644 --- a/tests/tpublish.nim +++ b/tests/tpublish.nim @@ -123,37 +123,6 @@ requires "nim >= 1.5.1" json{$lfjkPackages}{depName}{$lfjkPkgVcsRevision}.str.initSha1Hash check lockedVcsRevision == expectedVcsRevision - proc testLockFile(deps: seq[tuple[name, path: string]], isNew: bool, lockFileName = defaultLockFileName) = - ## Generates or updates a lock file and tests whether it contains - ## dependencies with given names at given repository paths and whether their - ## VCS revisions match the written in the lock file ones. - ## - ## `isNew` - indicates whether it is expected a new lock file to be - ## generated if its value is `true` or already existing lock file to be - ## updated otherwise. - - if isNew: - check not fileExists(lockFileName) - else: - check fileExists(lockFileName) - - let (output, exitCode) = if lockFileName == defaultLockFileName: - execNimbleYes("lock") - else: - execNimbleYes("--lock-file=" & lockFileName, "lock") - - check exitCode == QuitSuccess - - var lines = output.processOutput - if isNew: - check lines.inLinesOrdered(generatingTheLockFileMsg) - check lines.inLinesOrdered(lockFileIsGeneratedMsg) - else: - check lines.inLinesOrdered(updatingTheLockFileMsg) - check lines.inLinesOrdered(lockFileIsUpdatedMsg) - - testLockedVcsRevisions(deps, lockFileName) - template filesAndDirsToRemove() = removeFile pkgListFilePath removeDir installDir @@ -209,21 +178,9 @@ requires "nim >= 1.5.1" test "test publishVersions": cleanUp() cd "nimdep": - removeFile "nimble.develop" - removeFile "nimble.lock" - removeDir "Nim" - - check execNimbleYes("-y", "develop", "nim").exitCode == QuitSuccess - cd "Nim": - let (_, exitCode) = execNimbleYes("-y", "install") - check exitCode == QuitSuccess - # check if the compiler version will be used when doing build - testLockFile(@[("nim", "Nim")], isNew = true) - removeFile "nimble.develop" - removeDir "Nim" + let (output, res) = execNimbleYes("-y", "publishVersions") - let (output, exitCodeInstall) = execNimbleYes("-y", "build") check exitCodeInstall == QuitSuccess let usingNim = when defined(Windows): "nim.exe for compilation" else: "bin/nim for compilation" check output.contains(usingNim) From 823bb23698b6949ae63544357344b9a420d9080c Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Sat, 18 Jan 2025 23:05:22 -0700 Subject: [PATCH 03/42] tests --- tests/tpublish.nim | 86 +++++++++++++++++++++++++++++++--------------- 1 file changed, 59 insertions(+), 27 deletions(-) diff --git a/tests/tpublish.nim b/tests/tpublish.nim index c169325e..02d99074 100644 --- a/tests/tpublish.nim +++ b/tests/tpublish.nim @@ -21,12 +21,61 @@ from nimblepkg/developfile import ValidationError, ValidationErrorKind, developFileName, getValidationErrorMessage suite "publish": + type + PackagesListFileRecord = object + name: string + url: string + `method`: DownloadMethod + tags: seq[string] + description: string + license: string + + PackagesListFileContent = seq[PackagesListFileRecord] + + PkgIdent {.pure.} = enum + main = "main" + dep1 = "dep1" + dep2 = "dep2" + + template definePackageConstants(pkgName: PkgIdent) = + ## By given dependency number defines all relevant constants for it. + + const + `pkgName"PkgName"` {.used, inject.} = $pkgName + `pkgName"PkgNimbleFileName"` {.used, inject.} = + `pkgName"PkgName"` & ".nimble" + `pkgName"PkgRepoPath"` {.used, inject.} = tempDir / `pkgName"PkgName"` + `pkgName"PkgOriginRepoPath"`{.used, inject.} = + originsDirPath / `pkgName"PkgName"` + `pkgName"PkgRemoteName"` {.used, inject.} = + `pkgName"PkgName"` & "Remote" + `pkgName"PkgRemotePath"` {.used, inject.} = + additionalRemotesDirPath / `pkgName"PkgRemoteName"` + `pkgName"PkgOriginRemoteName"` {.used, inject.} = + `pkgName"PkgName"` & "OriginRemote" + `pkgName"PkgOriginRemotePath"` {.used, inject.} = + additionalRemotesDirPath / `pkgName"PkgOriginRemoteName"` + + `pkgName"PkgListFileRecord"` {.used, inject.} = PackagesListFileRecord( + name: `pkgName"PkgName"`, + url: `pkgName"PkgOriginRepoPath"`, + `method`: DownloadMethod.git, + tags: @["test"], + description: "This is a test package.", + license: "MIT") + const - tempDir = getTempDir() / "tpublish" + tempDir = getTempDir() / "tlockfile" originsDirName = "origins" originsDirPath = tempDir / originsDirName + additionalRemotesDirName = "remotes" + additionalRemotesDirPath = tempDir / additionalRemotesDirName + + pkgListFileName = "packages.json" + pkgListFilePath = tempDir / pkgListFileName + nimbleFileTemplate = """ version = "$1" @@ -36,6 +85,10 @@ license = "MIT" requires "nim >= 1.5.1" """ + definePackageConstants(PkgIdent.main) + definePackageConstants(PkgIdent.dep1) + definePackageConstants(PkgIdent.dep2) + proc newNimbleFileContent(pkgName, fileTemplate: string, deps: seq[string]): string = result = fileTemplate % pkgName @@ -160,35 +213,14 @@ requires "nim >= 1.5.1" # Push it to the newly added remote to be able to lock. push(remoteName) - proc testDepsSync = - let (output, exitCode) = execNimbleYes("sync") - check exitCode == QuitSuccess - let lines = output.processOutput - check lines.inLines( - pkgWorkingCopyIsSyncedMsg(dep1PkgName, dep1PkgRepoPath)) - check lines.inLines( - pkgWorkingCopyIsSyncedMsg(dep2PkgName, dep2PkgRepoPath)) - - cd mainPkgRepoPath: - # After successful sync the revisions written in the lock file must - # match those in the lock file. - testLockedVcsRevisions(@[(dep1PkgName, dep1PkgRepoPath), - (dep2PkgName, dep2PkgRepoPath)]) - test "test publishVersions": cleanUp() - cd "nimdep": + initNewNimblePackage(mainPkgOriginRepoPath, mainPkgRepoPath, + @[dep1PkgName]) + cd mainPkgRepoPath: let (output, res) = execNimbleYes("-y", "publishVersions") - check exitCodeInstall == QuitSuccess - let usingNim = when defined(Windows): "nim.exe for compilation" else: "bin/nim for compilation" - check output.contains(usingNim) - - # check the nim version - let (outputVersion, _) = execNimble("version") - check outputVersion.contains(getRevision("nim")) + # check exitCodeInstall == QuitSuccess + check output.contains("something...") - let (outputGlobalNim, exitCodeGlobalNim) = execNimbleYes("-y", "--use-system-nim", "build") - check exitCodeGlobalNim == QuitSuccess - check not outputGlobalNim.contains(usingNim) From 3d1379df1cb2b794363afde3a87524b59ad46594 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Sat, 18 Jan 2025 23:18:48 -0700 Subject: [PATCH 04/42] tests --- src/nimblepkg/publish.nim | 2 +- tests/tpublish.nim | 38 +++++++++++++++++--------------------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/nimblepkg/publish.nim b/src/nimblepkg/publish.nim index 51170bce..f80b7bad 100644 --- a/src/nimblepkg/publish.nim +++ b/src/nimblepkg/publish.nim @@ -320,7 +320,7 @@ proc findVersions(commits: seq[(Sha1Hash, string)], projdir, nimbleFile: string, prevMonotonicsOk = monotonics.mapIt(ver < it).all(proc (x: bool): bool = x) if ver < prev[0] and prevMonotonicsOk: - displayDetails(&"versions ok at tags {ver}@{info.commit} and previous tag of {prev[0]}@{prev[1]}", HighPriority) + displaySuccess(&"versions ok at tags {ver}@{info.commit} and previous tag of {prev[0]}@{prev[1]}", HighPriority) else: if prev[0] notin nonMonotonicVers: monotonics.add(prev[0]) # track last largest monotonic so we can check, e.g. 0.2, 3.0, 0.3 and not 0.2, 3.0, 0.2 diff --git a/tests/tpublish.nim b/tests/tpublish.nim index 02d99074..4d90b8f1 100644 --- a/tests/tpublish.nim +++ b/tests/tpublish.nim @@ -89,16 +89,9 @@ requires "nim >= 1.5.1" definePackageConstants(PkgIdent.dep1) definePackageConstants(PkgIdent.dep2) - proc newNimbleFileContent(pkgName, fileTemplate: string, - deps: seq[string]): string = - result = fileTemplate % pkgName - if deps.len == 0: - return - result &= "requires " - for i, dep in deps: - result &= &"\"{dep}\"" - if i != deps.len - 1: - result &= "," + proc newNimbleFileContent(fileTemplate: string, + version: string): string = + result = fileTemplate % [version] proc addFiles(files: varargs[string]) = var filesStr = "" @@ -143,22 +136,23 @@ requires "nim >= 1.5.1" branch(branchName) checkout(branchName) - proc initNewNimbleFile(dir: string, deps: seq[string] = @[]): string = + proc initNewNimbleFile(dir: string, version: string): string = let pkgName = dir.splitPath.tail let nimbleFileName = pkgName & ".nimble" - let nimbleFileContent = newNimbleFileContent( - pkgName, nimbleFileTemplate, deps) + let nimbleFileContent = newNimbleFileContent(nimbleFileTemplate, version) writeFile(nimbleFileName, nimbleFileContent) return nimbleFileName - proc initNewNimblePackage(dir, clonePath: string, deps: seq[string] = @[]) = + proc initNewNimblePackage(dir, clonePath: string, versions: seq[string] = @[]) = cdNewDir dir: initRepo() - let nimbleFileName = dir.initNewNimbleFile(deps) - addFiles(nimbleFileName) - commit("Initial commit") - - clone(dir, clonePath) + echo "created repo at: ", getCurrentDir() + for version in versions: + let nimbleFileName = dir.initNewNimbleFile(version) + addFiles(nimbleFileName) + commit("Initial commit") + echo "created package version ", version + echo "" proc addAdditionalFileToTheRepo(fileName, fileContent: string) = writeFile(fileName, fileContent) @@ -214,10 +208,12 @@ requires "nim >= 1.5.1" push(remoteName) test "test publishVersions": - cleanUp() + # cleanUp() initNewNimblePackage(mainPkgOriginRepoPath, mainPkgRepoPath, - @[dep1PkgName]) + @["0.1.0", "0.1.1", "0.1.2", "0.2.1", "1.0"]) cd mainPkgRepoPath: + echo "mainPkgRepoPath: ", mainPkgRepoPath + echo "getCurrentDir: ", getCurrentDir() let (output, res) = execNimbleYes("-y", "publishVersions") From b3121d3eeabc5c881b2f4e2902d54b5cc58f210b Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Sat, 18 Jan 2025 23:22:28 -0700 Subject: [PATCH 05/42] tests --- tests/tpublish.nim | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/tpublish.nim b/tests/tpublish.nim index 4d90b8f1..986d95a3 100644 --- a/tests/tpublish.nim +++ b/tests/tpublish.nim @@ -143,7 +143,7 @@ requires "nim >= 1.5.1" writeFile(nimbleFileName, nimbleFileContent) return nimbleFileName - proc initNewNimblePackage(dir, clonePath: string, versions: seq[string] = @[]) = + proc initNewNimblePackage(dir: string, versions: seq[string] = @[]) = cdNewDir dir: initRepo() echo "created repo at: ", getCurrentDir() @@ -209,8 +209,8 @@ requires "nim >= 1.5.1" test "test publishVersions": # cleanUp() - initNewNimblePackage(mainPkgOriginRepoPath, mainPkgRepoPath, - @["0.1.0", "0.1.1", "0.1.2", "0.2.1", "1.0"]) + let versions = @["0.1.0", "0.1.1", "0.1.2", "0.2.1", "1.0.0"] + initNewNimblePackage(mainPkgRepoPath, versions) cd mainPkgRepoPath: echo "mainPkgRepoPath: ", mainPkgRepoPath echo "getCurrentDir: ", getCurrentDir() @@ -218,5 +218,6 @@ requires "nim >= 1.5.1" let (output, res) = execNimbleYes("-y", "publishVersions") # check exitCodeInstall == QuitSuccess - check output.contains("something...") + for version in versions[1..^1]: + check output.contains("Found new version $1" % version) From faf51ad4f73baef32ccf394696355b62f881ca83 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Sat, 18 Jan 2025 23:23:44 -0700 Subject: [PATCH 06/42] tests --- tests/tpublish.nim | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/tests/tpublish.nim b/tests/tpublish.nim index 986d95a3..1cc82aa0 100644 --- a/tests/tpublish.nim +++ b/tests/tpublish.nim @@ -207,7 +207,7 @@ requires "nim >= 1.5.1" # Push it to the newly added remote to be able to lock. push(remoteName) - test "test publishVersions": + test "test publishVersions basic find versions": # cleanUp() let versions = @["0.1.0", "0.1.1", "0.1.2", "0.2.1", "1.0.0"] initNewNimblePackage(mainPkgRepoPath, versions) @@ -215,9 +215,22 @@ requires "nim >= 1.5.1" echo "mainPkgRepoPath: ", mainPkgRepoPath echo "getCurrentDir: ", getCurrentDir() - let (output, res) = execNimbleYes("-y", "publishVersions") + let (output, exitCode) = execNimbleYes("-y", "publishVersions") - # check exitCodeInstall == QuitSuccess + check exitCode == QuitSuccess for version in versions[1..^1]: check output.contains("Found new version $1" % version) + test "test publishVersions basic find versions": + # cleanUp() + let versions = @["0.1.0", "0.1.1", "2.1.0", "0.2.1", "1.0.0"] + initNewNimblePackage(mainPkgRepoPath, versions) + cd mainPkgRepoPath: + echo "mainPkgRepoPath: ", mainPkgRepoPath + echo "getCurrentDir: ", getCurrentDir() + + let (output, res) = execNimbleYes("-y", "publishVersions") + + # check exitCodeInstall == QuitSuccess + # for version in versions[1..^1]: + # check output.contains("Found new version $1" % version) From ef3fddbcda969576c7dde48c9ad9bc6fcedb9111 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Sat, 18 Jan 2025 23:28:29 -0700 Subject: [PATCH 07/42] tests --- src/nimblepkg/publish.nim | 2 +- tests/tpublish.nim | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/nimblepkg/publish.nim b/src/nimblepkg/publish.nim index f80b7bad..2b58b375 100644 --- a/src/nimblepkg/publish.nim +++ b/src/nimblepkg/publish.nim @@ -320,7 +320,7 @@ proc findVersions(commits: seq[(Sha1Hash, string)], projdir, nimbleFile: string, prevMonotonicsOk = monotonics.mapIt(ver < it).all(proc (x: bool): bool = x) if ver < prev[0] and prevMonotonicsOk: - displaySuccess(&"versions ok at tags {ver}@{info.commit} and previous tag of {prev[0]}@{prev[1]}", HighPriority) + displayWarning(&"versions ok at tags {ver}@{info.commit} and previous tag of {prev[0]}@{prev[1]}", HighPriority) else: if prev[0] notin nonMonotonicVers: monotonics.add(prev[0]) # track last largest monotonic so we can check, e.g. 0.2, 3.0, 0.3 and not 0.2, 3.0, 0.2 diff --git a/tests/tpublish.nim b/tests/tpublish.nim index 1cc82aa0..38c8e42b 100644 --- a/tests/tpublish.nim +++ b/tests/tpublish.nim @@ -34,7 +34,7 @@ suite "publish": PkgIdent {.pure.} = enum main = "main" - dep1 = "dep1" + bad1 = "bad1" dep2 = "dep2" template definePackageConstants(pkgName: PkgIdent) = @@ -86,7 +86,7 @@ requires "nim >= 1.5.1" """ definePackageConstants(PkgIdent.main) - definePackageConstants(PkgIdent.dep1) + definePackageConstants(PkgIdent.bad1) definePackageConstants(PkgIdent.dep2) proc newNimbleFileContent(fileTemplate: string, @@ -146,7 +146,7 @@ requires "nim >= 1.5.1" proc initNewNimblePackage(dir: string, versions: seq[string] = @[]) = cdNewDir dir: initRepo() - echo "created repo at: ", getCurrentDir() + echo "created repo at: ", dir, " cwd: ", getCurrentDir() for version in versions: let nimbleFileName = dir.initNewNimbleFile(version) addFiles(nimbleFileName) @@ -186,7 +186,7 @@ requires "nim >= 1.5.1" template withPkgListFile(body: untyped) = writePackageListFile( - pkgListFilePath, @[dep1PkgListFileRecord, dep2PkgListFileRecord]) + pkgListFilePath, @[bad1PkgListFileRecord, dep2PkgListFileRecord]) usePackageListFile pkgListFilePath: body @@ -224,9 +224,9 @@ requires "nim >= 1.5.1" test "test publishVersions basic find versions": # cleanUp() let versions = @["0.1.0", "0.1.1", "2.1.0", "0.2.1", "1.0.0"] - initNewNimblePackage(mainPkgRepoPath, versions) - cd mainPkgRepoPath: - echo "mainPkgRepoPath: ", mainPkgRepoPath + initNewNimblePackage(bad1PkgRepoPath, versions) + cd bad1PkgRepoPath: + echo "mainPkgRepoPath: ", bad1PkgRepoPath echo "getCurrentDir: ", getCurrentDir() let (output, res) = execNimbleYes("-y", "publishVersions") From 26d34a380e7ab709fd07b63628499aba0ba01ec3 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Sat, 18 Jan 2025 23:34:37 -0700 Subject: [PATCH 08/42] tests --- tests/testscommon.nim | 7 ++++++- tests/tpublish.nim | 7 +++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/testscommon.nim b/tests/testscommon.nim index 09ea1d2d..0aef7ed4 100644 --- a/tests/testscommon.nim +++ b/tests/testscommon.nim @@ -6,6 +6,7 @@ import sequtils, strutils, strformat, os, osproc, sugar, unittest, macros import pkg/checksums/sha1 +import nimblepkg/cli from nimblepkg/common import cd, nimblePackagesDirName, ProcessOutput from nimblepkg/developfile import developFileVersion @@ -70,7 +71,8 @@ template verify*(res: (string, int)) = check r[1] == QuitSuccess proc processOutput*(output: string): seq[string] = - output.strip.splitLines().filter( + checkpoint(output) + result = output.strip.splitLines().filter( (x: string) => ( x.len > 0 and "Using env var NIM_LIB_PREFIX" notin x @@ -207,6 +209,9 @@ proc writeDevelopFile*(path: string, includes: seq[string], # Set env var to propagate nimble binary path putEnv("NIMBLE_TEST_BINARY_PATH", nimblePath) +setVerbosity(MediumPriority) +setShowColor(false) + # Always recompile. block: # Verbose name is used for exit code so assert is clearer diff --git a/tests/tpublish.nim b/tests/tpublish.nim index 38c8e42b..a67c8b33 100644 --- a/tests/tpublish.nim +++ b/tests/tpublish.nim @@ -146,11 +146,11 @@ requires "nim >= 1.5.1" proc initNewNimblePackage(dir: string, versions: seq[string] = @[]) = cdNewDir dir: initRepo() - echo "created repo at: ", dir, " cwd: ", getCurrentDir() + echo "created repo at: ", dir for version in versions: let nimbleFileName = dir.initNewNimbleFile(version) addFiles(nimbleFileName) - commit("Initial commit") + commit("commit $1" % version) echo "created package version ", version echo "" @@ -231,6 +231,9 @@ requires "nim >= 1.5.1" let (output, res) = execNimbleYes("-y", "publishVersions") + echo "output: " + for line in output.splitLines(): + echo line # check exitCodeInstall == QuitSuccess # for version in versions[1..^1]: # check output.contains("Found new version $1" % version) From 1dbd702ec94fdeeb8a000481db5c8646baba0a18 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Sat, 18 Jan 2025 23:50:53 -0700 Subject: [PATCH 09/42] tests --- src/nimblepkg/publish.nim | 8 ++++++-- tests/tpublish.nim | 10 ++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/nimblepkg/publish.nim b/src/nimblepkg/publish.nim index 2b58b375..c2983802 100644 --- a/src/nimblepkg/publish.nim +++ b/src/nimblepkg/publish.nim @@ -320,12 +320,16 @@ proc findVersions(commits: seq[(Sha1Hash, string)], projdir, nimbleFile: string, prevMonotonicsOk = monotonics.mapIt(ver < it).all(proc (x: bool): bool = x) if ver < prev[0] and prevMonotonicsOk: - displayWarning(&"versions ok at tags {ver}@{info.commit} and previous tag of {prev[0]}@{prev[1]}", HighPriority) + displayHint(&"Versions monotonic between tag {ver}@{info.commit} " & + &" and previous tag of {prev[0]}@{prev[1].commit}", MediumPriority) else: if prev[0] notin nonMonotonicVers: monotonics.add(prev[0]) # track last largest monotonic so we can check, e.g. 0.2, 3.0, 0.3 and not 0.2, 3.0, 0.2 nonMonotonicVers[ver] = info.commit - displayError(&"bad version found with tag {ver}@{info.commit} and previous tag at {prev[0]}@{prev[1]}", HighPriority) + displayError(&"Non-monotonic (decreasing) version found between tag {ver}@{info.commit}" & + &" and the previous tag {prev[0]}@{prev[1].commit}", HighPriority) + displayWarning(&"Version {ver} will be skipped. Please tag it manually if the version is correct." , HighPriority) + displayHint(&"Note that versions are checked from larget to smallest" , HighPriority) for (version, info) in versions.pairs: if options.action.createTags: diff --git a/tests/tpublish.nim b/tests/tpublish.nim index a67c8b33..006ba18d 100644 --- a/tests/tpublish.nim +++ b/tests/tpublish.nim @@ -229,11 +229,13 @@ requires "nim >= 1.5.1" echo "mainPkgRepoPath: ", bad1PkgRepoPath echo "getCurrentDir: ", getCurrentDir() - let (output, res) = execNimbleYes("-y", "publishVersions") + let (output, exitCode) = execNimbleYes("-y", "publishVersions") echo "output: " for line in output.splitLines(): echo line - # check exitCodeInstall == QuitSuccess - # for version in versions[1..^1]: - # check output.contains("Found new version $1" % version) + check output.contains("Non-monotonic (decreasing) version found between tag 2.1.0") + + check exitCode == QuitSuccess + for version in versions[1..^1]: + check output.contains("Found new version $1" % version) From 62fbf4382e0013db6b50442ea1418a22c099afa9 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Sat, 18 Jan 2025 23:51:44 -0700 Subject: [PATCH 10/42] tests --- src/nimblepkg/publish.nim | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/nimblepkg/publish.nim b/src/nimblepkg/publish.nim index c2983802..454c799e 100644 --- a/src/nimblepkg/publish.nim +++ b/src/nimblepkg/publish.nim @@ -331,12 +331,15 @@ proc findVersions(commits: seq[(Sha1Hash, string)], projdir, nimbleFile: string, displayWarning(&"Version {ver} will be skipped. Please tag it manually if the version is correct." , HighPriority) displayHint(&"Note that versions are checked from larget to smallest" , HighPriority) - for (version, info) in versions.pairs: - if options.action.createTags: - displayWarning(&"Creating tag for new version {version} at {info.commit}", HighPriority) - let res = createTag(&"v{version}", info.commit, info.message, projdir, nimbleFile, downloadMethod) - if not res: - displayError(&"Unable to create tag {version}", HighPriority) + if options.action.createTags: + for (version, info) in versions.pairs: + if version in nonMonotonicVers: + displayWarning(&"Skipping creating tag for new version {version} at {info.commit}", HighPriority) + else: + displayWarning(&"Creating tag for new version {version} at {info.commit}", HighPriority) + let res = createTag(&"v{version}", info.commit, info.message, projdir, nimbleFile, downloadMethod) + if not res: + displayError(&"Unable to create tag {version}", HighPriority) proc publishVersions*(p: PackageInfo, options: Options) = displayInfo(&"Searcing for new tags for {$p.basicInfo.name} @{$p.basicInfo.version}", HighPriority) From ed4bd2c465451a26cbdd2a3e014d600e43142db1 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Sun, 19 Jan 2025 00:00:21 -0700 Subject: [PATCH 11/42] tests --- tests/tpublish.nim | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/tests/tpublish.nim b/tests/tpublish.nim index 006ba18d..4456b538 100644 --- a/tests/tpublish.nim +++ b/tests/tpublish.nim @@ -35,7 +35,7 @@ suite "publish": PkgIdent {.pure.} = enum main = "main" bad1 = "bad1" - dep2 = "dep2" + bad2 = "bad2" template definePackageConstants(pkgName: PkgIdent) = ## By given dependency number defines all relevant constants for it. @@ -87,7 +87,7 @@ requires "nim >= 1.5.1" definePackageConstants(PkgIdent.main) definePackageConstants(PkgIdent.bad1) - definePackageConstants(PkgIdent.dep2) + definePackageConstants(PkgIdent.bad2) proc newNimbleFileContent(fileTemplate: string, version: string): string = @@ -143,21 +143,23 @@ requires "nim >= 1.5.1" writeFile(nimbleFileName, nimbleFileContent) return nimbleFileName + proc addAdditionalFileToTheRepo(fileName, fileContent: string) = + writeFile(fileName, fileContent) + addFiles(fileName) + commit("Add additional file") + proc initNewNimblePackage(dir: string, versions: seq[string] = @[]) = cdNewDir dir: initRepo() echo "created repo at: ", dir - for version in versions: + for idx, version in versions: let nimbleFileName = dir.initNewNimbleFile(version) addFiles(nimbleFileName) commit("commit $1" % version) echo "created package version ", version echo "" - - proc addAdditionalFileToTheRepo(fileName, fileContent: string) = - writeFile(fileName, fileContent) - addFiles(fileName) - commit("Add additional file") + if idx in [0, 1, versions.len() - 2]: + addAdditionalFileToTheRepo("test.txt", $idx) proc testLockedVcsRevisions(deps: seq[tuple[name, path: string]], lockFileName = defaultLockFileName) = check lockFileName.fileExists @@ -221,9 +223,9 @@ requires "nim >= 1.5.1" for version in versions[1..^1]: check output.contains("Found new version $1" % version) - test "test publishVersions basic find versions": + test "test warning publishVersions non-monotonic versions": # cleanUp() - let versions = @["0.1.0", "0.1.1", "2.1.0", "0.2.1", "1.0.0"] + let versions = @["0.1.0", "0.1.1", "0.1.2", "2.1.0", "0.2.1", "1.0.0"] initNewNimblePackage(bad1PkgRepoPath, versions) cd bad1PkgRepoPath: echo "mainPkgRepoPath: ", bad1PkgRepoPath @@ -239,3 +241,24 @@ requires "nim >= 1.5.1" check exitCode == QuitSuccess for version in versions[1..^1]: check output.contains("Found new version $1" % version) + + test "test skipping publishVersions non-monotonic versions": + # cleanUp() + let versions = @["0.1.0", "0.1.1", "2.1.0", "0.2.1", "1.0.0"] + # initNewNimblePackage(bad1PkgRepoPath, versions) + cd bad1PkgRepoPath: + echo "mainPkgRepoPath: ", bad1PkgRepoPath + echo "getCurrentDir: ", getCurrentDir() + + let (output, exitCode) = execNimbleYes("publishVersions", "--create") + + echo "output: " + for line in output.splitLines(): + echo line + check output.contains("Non-monotonic (decreasing) version found between tag 2.1.0") + + check exitCode == QuitSuccess + for version in versions[1..^1]: + if version == "2.1.0": + continue + check output.contains("Creating tag for new version $1" % version) From ab5609c5590db92170defcecd861f4894d21ccc4 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Sun, 19 Jan 2025 00:06:09 -0700 Subject: [PATCH 12/42] tests --- src/nimblepkg/publish.nim | 2 +- tests/tpublish.nim | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/nimblepkg/publish.nim b/src/nimblepkg/publish.nim index 454c799e..ad25a320 100644 --- a/src/nimblepkg/publish.nim +++ b/src/nimblepkg/publish.nim @@ -334,7 +334,7 @@ proc findVersions(commits: seq[(Sha1Hash, string)], projdir, nimbleFile: string, if options.action.createTags: for (version, info) in versions.pairs: if version in nonMonotonicVers: - displayWarning(&"Skipping creating tag for new version {version} at {info.commit}", HighPriority) + displayWarning(&"Skipping creating tag for non-monotonic {version} at {info.commit}", HighPriority) else: displayWarning(&"Creating tag for new version {version} at {info.commit}", HighPriority) let res = createTag(&"v{version}", info.commit, info.message, projdir, nimbleFile, downloadMethod) diff --git a/tests/tpublish.nim b/tests/tpublish.nim index 4456b538..5214be76 100644 --- a/tests/tpublish.nim +++ b/tests/tpublish.nim @@ -262,3 +262,25 @@ requires "nim >= 1.5.1" if version == "2.1.0": continue check output.contains("Creating tag for new version $1" % version) + + test "test skipping publishVersions non-monotonic versions 2 ": + # cleanUp() + let versions = @["0.1.0", "0.1.1", "0.2.3", "2.1.0", "0.2.2", "0.2.4"] + initNewNimblePackage(bad2PkgRepoPath, versions) + cd bad2PkgRepoPath: + echo "mainPkgRepoPath: ", bad2PkgRepoPath + echo "getCurrentDir: ", getCurrentDir() + + let (output, exitCode) = execNimbleYes("publishVersions", "--create") + + echo "output: " + for line in output.splitLines(): + echo line + check output.contains("Non-monotonic (decreasing) version found between tag 2.1.0") + check output.contains("Non-monotonic (decreasing) version found between tag 0.2.2") + + check exitCode == QuitSuccess + for version in versions[1..^1]: + if version in ["2.1.0", "0.2.2"]: + continue + check output.contains("Creating tag for new version $1" % version) From 62aa5ca444c4d6c06a5093b05860e9568c5e4d13 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Sun, 19 Jan 2025 00:09:12 -0700 Subject: [PATCH 13/42] tests --- tests/tpublish.nim | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/tests/tpublish.nim b/tests/tpublish.nim index 5214be76..caa81e2c 100644 --- a/tests/tpublish.nim +++ b/tests/tpublish.nim @@ -233,9 +233,6 @@ requires "nim >= 1.5.1" let (output, exitCode) = execNimbleYes("-y", "publishVersions") - echo "output: " - for line in output.splitLines(): - echo line check output.contains("Non-monotonic (decreasing) version found between tag 2.1.0") check exitCode == QuitSuccess @@ -252,9 +249,6 @@ requires "nim >= 1.5.1" let (output, exitCode) = execNimbleYes("publishVersions", "--create") - echo "output: " - for line in output.splitLines(): - echo line check output.contains("Non-monotonic (decreasing) version found between tag 2.1.0") check exitCode == QuitSuccess @@ -273,14 +267,11 @@ requires "nim >= 1.5.1" let (output, exitCode) = execNimbleYes("publishVersions", "--create") - echo "output: " - for line in output.splitLines(): - echo line check output.contains("Non-monotonic (decreasing) version found between tag 2.1.0") check output.contains("Non-monotonic (decreasing) version found between tag 0.2.2") check exitCode == QuitSuccess for version in versions[1..^1]: - if version in ["2.1.0", "0.2.2"]: + if version in ["2.1.0", "0.2.3"]: continue check output.contains("Creating tag for new version $1" % version) From 3bc941dbaa4858d0608483f47e4d7eba147f493b Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Sun, 19 Jan 2025 00:11:07 -0700 Subject: [PATCH 14/42] tests --- src/nimblepkg/publish.nim | 1 + tests/tpublish.nim | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/nimblepkg/publish.nim b/src/nimblepkg/publish.nim index ad25a320..2a03d74d 100644 --- a/src/nimblepkg/publish.nim +++ b/src/nimblepkg/publish.nim @@ -330,6 +330,7 @@ proc findVersions(commits: seq[(Sha1Hash, string)], projdir, nimbleFile: string, &" and the previous tag {prev[0]}@{prev[1].commit}", HighPriority) displayWarning(&"Version {ver} will be skipped. Please tag it manually if the version is correct." , HighPriority) displayHint(&"Note that versions are checked from larget to smallest" , HighPriority) + displayHint(&"Note later smaller versions are always peferred. Please manually review your tags before pushing." , HighPriority) if options.action.createTags: for (version, info) in versions.pairs: diff --git a/tests/tpublish.nim b/tests/tpublish.nim index caa81e2c..93deb744 100644 --- a/tests/tpublish.nim +++ b/tests/tpublish.nim @@ -268,7 +268,7 @@ requires "nim >= 1.5.1" let (output, exitCode) = execNimbleYes("publishVersions", "--create") check output.contains("Non-monotonic (decreasing) version found between tag 2.1.0") - check output.contains("Non-monotonic (decreasing) version found between tag 0.2.2") + check output.contains("Non-monotonic (decreasing) version found between tag 0.2.3") check exitCode == QuitSuccess for version in versions[1..^1]: From b92caca3e37815f1aa7171e9a07e0ba91f5c005d Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Sun, 19 Jan 2025 00:24:24 -0700 Subject: [PATCH 15/42] tests --- src/nimblepkg/options.nim | 3 +++ src/nimblepkg/publish.nim | 23 ++++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/nimblepkg/options.nim b/src/nimblepkg/options.nim index afee297d..dd2c5b5b 100644 --- a/src/nimblepkg/options.nim +++ b/src/nimblepkg/options.nim @@ -127,6 +127,7 @@ type publishAction*: string of actionPublishVersions: createTags*: bool + pushTags*: bool of actionShellEnv, actionShell: discard @@ -777,6 +778,8 @@ proc parseFlag*(flag, val: string, result: var Options, kind = cmdLongOption) = case f of "c", "create": result.action.createTags = true + of "p", "push": + result.action.pushTags = true else: wasFlagHandled = false of actionDeps: diff --git a/src/nimblepkg/publish.nim b/src/nimblepkg/publish.nim index 2a03d74d..3e4e4a3b 100644 --- a/src/nimblepkg/publish.nim +++ b/src/nimblepkg/publish.nim @@ -282,6 +282,20 @@ proc createTag*(tag: string, commit: Sha1Hash, message, repoDir, nimbleFile: str of DownloadMethod.hg: assert false, "hg not supported" +proc pushTags*(tags: seq[string], repoDir: string, downloadMethod: DownloadMethod): bool = + case downloadMethod: + of DownloadMethod.git: + # git push origin tag experiment-0.8.1 + let tags = tags.mapIt(it.quoteShell()).join(" ") + let (output, code) = doCmdEx(&"git -C {repoDir} push origin tag {tags} ") + result = code == QuitSuccess + if not result: + displayError(&"Failed to push tag {tags} with error {output}") + of DownloadMethod.hg: + assert false, "hg not supported" + +const tagVersionFmt = "v$1" + proc findVersions(commits: seq[(Sha1Hash, string)], projdir, nimbleFile: string, downloadMethod: DownloadMethod, options: Options) = ## parse the versions var @@ -338,10 +352,17 @@ proc findVersions(commits: seq[(Sha1Hash, string)], projdir, nimbleFile: string, displayWarning(&"Skipping creating tag for non-monotonic {version} at {info.commit}", HighPriority) else: displayWarning(&"Creating tag for new version {version} at {info.commit}", HighPriority) - let res = createTag(&"v{version}", info.commit, info.message, projdir, nimbleFile, downloadMethod) + let res = createTag(tagVersionFmt % [$version], info.commit, info.message, projdir, nimbleFile, downloadMethod) if not res: displayError(&"Unable to create tag {version}", HighPriority) + if options.action.pushTags: + var tags: seq[string] + for (version, info) in versions.pairs: + if version in nonMonotonicVers: + tags.add(tagVersionFmt % [$version]) + let res = pushTags(tags, projdir, downloadMethod) + proc publishVersions*(p: PackageInfo, options: Options) = displayInfo(&"Searcing for new tags for {$p.basicInfo.name} @{$p.basicInfo.version}", HighPriority) let (projdir, file, ext) = p.myPath.splitFile() From f1ffc56456c3f756d09247b10d9eeca7e8292ef7 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Sun, 19 Jan 2025 00:28:54 -0700 Subject: [PATCH 16/42] adding publish and docs --- src/nimblepkg/options.nim | 6 +++--- src/nimblepkg/publish.nim | 14 ++++++++------ tests/tpublish.nim | 1 - 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/nimblepkg/options.nim b/src/nimblepkg/options.nim index dd2c5b5b..afc308db 100644 --- a/src/nimblepkg/options.nim +++ b/src/nimblepkg/options.nim @@ -181,10 +181,10 @@ Commands: publish Publishes a package on nim-lang/packages. The current working directory needs to be the top level directory of the Nimble package. - publishVersions Finds package versions based on commits + publishVersions Lists package versions based on commits where the package's Nimble version changed. - [-c, --create] Only list the tags and versions which are found without - actually performing tag or publishing them. + [-c, --create] Creates tags for missing versions. + [-p, --push] Push only tagged versions (tags) to VCS. uninstall [pkgname, ...] Uninstalls a list of packages. [-i, --inclDeps] Uninstalls package and dependent package(s). build [opts, ...] [bin] Builds a package. Passes options to the Nim diff --git a/src/nimblepkg/publish.nim b/src/nimblepkg/publish.nim index 3e4e4a3b..1b89ed99 100644 --- a/src/nimblepkg/publish.nim +++ b/src/nimblepkg/publish.nim @@ -296,18 +296,20 @@ proc pushTags*(tags: seq[string], repoDir: string, downloadMethod: DownloadMetho const tagVersionFmt = "v$1" -proc findVersions(commits: seq[(Sha1Hash, string)], projdir, nimbleFile: string, downloadMethod: DownloadMethod, options: Options) = - ## parse the versions - var - versions: OrderedTable[Version, tuple[commit: Sha1Hash, message: string]] - existingTags: HashSet[Version] +proc findExistingTags(projdir: string, downloadMethod: DownloadMethod): HashSet[Version] = for tag in getTagsList(projdir, downloadMethod): let tag = tag.strip(leading=true, chars={'v'}) try: - existingTags.incl(newVersion(tag)) + result.incl(newVersion(tag)) except ParseVersionError: discard +proc findVersions(commits: seq[(Sha1Hash, string)], projdir, nimbleFile: string, downloadMethod: DownloadMethod, options: Options) = + ## parse the versions + var + versions: OrderedTable[Version, tuple[commit: Sha1Hash, message: string]] + existingTags = findExistingTags(projdir, downloadMethod) + # adapted from @beef331's algorithm https://github.com/beef331/graffiti/blob/master/src/graffiti.nim for (commit, message) in commits: # echo "commit: ", commit diff --git a/tests/tpublish.nim b/tests/tpublish.nim index 93deb744..1469d6d7 100644 --- a/tests/tpublish.nim +++ b/tests/tpublish.nim @@ -157,7 +157,6 @@ requires "nim >= 1.5.1" addFiles(nimbleFileName) commit("commit $1" % version) echo "created package version ", version - echo "" if idx in [0, 1, versions.len() - 2]: addAdditionalFileToTheRepo("test.txt", $idx) From 42dfcc94a19e66f3333f800f93d0ea4d38e860e4 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Sun, 19 Jan 2025 00:32:32 -0700 Subject: [PATCH 17/42] adding publish and docs --- src/nimblepkg/options.nim | 1 + src/nimblepkg/publish.nim | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/nimblepkg/options.nim b/src/nimblepkg/options.nim index afc308db..7378f292 100644 --- a/src/nimblepkg/options.nim +++ b/src/nimblepkg/options.nim @@ -128,6 +128,7 @@ type of actionPublishVersions: createTags*: bool pushTags*: bool + all*: bool of actionShellEnv, actionShell: discard diff --git a/src/nimblepkg/publish.nim b/src/nimblepkg/publish.nim index 1b89ed99..5b2cb3ae 100644 --- a/src/nimblepkg/publish.nim +++ b/src/nimblepkg/publish.nim @@ -348,22 +348,22 @@ proc findVersions(commits: seq[(Sha1Hash, string)], projdir, nimbleFile: string, displayHint(&"Note that versions are checked from larget to smallest" , HighPriority) displayHint(&"Note later smaller versions are always peferred. Please manually review your tags before pushing." , HighPriority) + var newTags: HashSet[string] if options.action.createTags: for (version, info) in versions.pairs: if version in nonMonotonicVers: displayWarning(&"Skipping creating tag for non-monotonic {version} at {info.commit}", HighPriority) else: + let tag = tagVersionFmt % [$version] displayWarning(&"Creating tag for new version {version} at {info.commit}", HighPriority) - let res = createTag(tagVersionFmt % [$version], info.commit, info.message, projdir, nimbleFile, downloadMethod) + let res = createTag(tag, info.commit, info.message, projdir, nimbleFile, downloadMethod) if not res: displayError(&"Unable to create tag {version}", HighPriority) + else: + newTags.add(tag) if options.action.pushTags: - var tags: seq[string] - for (version, info) in versions.pairs: - if version in nonMonotonicVers: - tags.add(tagVersionFmt % [$version]) - let res = pushTags(tags, projdir, downloadMethod) + let res = pushTags(tags.toSeq(), projdir, downloadMethod) proc publishVersions*(p: PackageInfo, options: Options) = displayInfo(&"Searcing for new tags for {$p.basicInfo.name} @{$p.basicInfo.version}", HighPriority) From dc513d0d8f79c2d86e601437478e71d51e9df729 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Sun, 19 Jan 2025 00:48:01 -0700 Subject: [PATCH 18/42] adding --all option --- src/nimblepkg/options.nim | 4 +++- src/nimblepkg/publish.nim | 39 ++++++++++++++++++++++++--------------- tests/tpublish.nim | 2 ++ 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/nimblepkg/options.nim b/src/nimblepkg/options.nim index 7378f292..0c9a8096 100644 --- a/src/nimblepkg/options.nim +++ b/src/nimblepkg/options.nim @@ -128,7 +128,7 @@ type of actionPublishVersions: createTags*: bool pushTags*: bool - all*: bool + allTags*: bool of actionShellEnv, actionShell: discard @@ -781,6 +781,8 @@ proc parseFlag*(flag, val: string, result: var Options, kind = cmdLongOption) = result.action.createTags = true of "p", "push": result.action.pushTags = true + of "a", "all": + result.action.allTags = true else: wasFlagHandled = false of actionDeps: diff --git a/src/nimblepkg/publish.nim b/src/nimblepkg/publish.nim index 5b2cb3ae..7cca8160 100644 --- a/src/nimblepkg/publish.nim +++ b/src/nimblepkg/publish.nim @@ -309,21 +309,30 @@ proc findVersions(commits: seq[(Sha1Hash, string)], projdir, nimbleFile: string, var versions: OrderedTable[Version, tuple[commit: Sha1Hash, message: string]] existingTags = findExistingTags(projdir, downloadMethod) + firstTag = newVersion("0.0.0") + if existingTags.len() > 0: + firstTag = existingTags.toSeq().sorted()[0] + echo "FIRST TAG: ", firstTag # adapted from @beef331's algorithm https://github.com/beef331/graffiti/blob/master/src/graffiti.nim - for (commit, message) in commits: - # echo "commit: ", commit - let diffs = vcsDiff(commit, projdir, nimbleFile, downloadMethod) - for line in diffs: - var matches: array[0..MaxSubpatterns, string] - if line.find(peg"'+version' \s* '=' \s* {[\34\39]} {@} $1", matches) > -1: - let ver = newVersion(matches[1]) - if ver notin versions: - versions[ver] = (commit: commit, message: message) - if ver in existingTags: - displayInfo(&"Found existing tag for version {ver} at commit {commit}", HighPriority) - else: - displayInfo(&"Found new version {ver} at {commit}", HighPriority) + block outer: + for (commit, message) in commits: + # echo "commit: ", commit + let diffs = vcsDiff(commit, projdir, nimbleFile, downloadMethod) + for line in diffs: + var matches: array[0..MaxSubpatterns, string] + if line.find(peg"'+version' \s* '=' \s* {[\34\39]} {@} $1", matches) > -1: + let ver = newVersion(matches[1]) + if ver <= firstTag: + echo "FIRST TAG PASSED " + break outer + if ver notin versions: + versions[ver] = (commit: commit, message: message) + if ver in existingTags: + displayInfo(&"Found existing tag for version {ver} at commit {commit}", HighPriority) + else: + displayInfo(&"Found new version {ver} at {commit}", HighPriority) + echo "FIRST TAG DONE " var nonMonotonicVers: Table[Version, Sha1Hash] if versions.len() >= 2: @@ -360,10 +369,10 @@ proc findVersions(commits: seq[(Sha1Hash, string)], projdir, nimbleFile: string, if not res: displayError(&"Unable to create tag {version}", HighPriority) else: - newTags.add(tag) + newTags.incl(tag) if options.action.pushTags: - let res = pushTags(tags.toSeq(), projdir, downloadMethod) + let res = pushTags(newTags.toSeq(), projdir, downloadMethod) proc publishVersions*(p: PackageInfo, options: Options) = displayInfo(&"Searcing for new tags for {$p.basicInfo.name} @{$p.basicInfo.version}", HighPriority) diff --git a/tests/tpublish.nim b/tests/tpublish.nim index 1469d6d7..0d0cf089 100644 --- a/tests/tpublish.nim +++ b/tests/tpublish.nim @@ -269,6 +269,8 @@ requires "nim >= 1.5.1" check output.contains("Non-monotonic (decreasing) version found between tag 2.1.0") check output.contains("Non-monotonic (decreasing) version found between tag 0.2.3") + for line in output.splitLines(): + echo ">>> ", line check exitCode == QuitSuccess for version in versions[1..^1]: if version in ["2.1.0", "0.2.3"]: From 072a2c1cb06814f5490534050e80d8f2970e1a0d Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Sun, 19 Jan 2025 00:50:53 -0700 Subject: [PATCH 19/42] adding --all option --- src/nimblepkg/publish.nim | 14 +++++++------- tests/tpublish.nim | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/nimblepkg/publish.nim b/src/nimblepkg/publish.nim index 7cca8160..af554c79 100644 --- a/src/nimblepkg/publish.nim +++ b/src/nimblepkg/publish.nim @@ -294,7 +294,7 @@ proc pushTags*(tags: seq[string], repoDir: string, downloadMethod: DownloadMetho of DownloadMethod.hg: assert false, "hg not supported" -const tagVersionFmt = "v$1" +const TagVersionFmt = "v$1" proc findExistingTags(projdir: string, downloadMethod: DownloadMethod): HashSet[Version] = for tag in getTagsList(projdir, downloadMethod): @@ -345,14 +345,14 @@ proc findVersions(commits: seq[(Sha1Hash, string)], projdir, nimbleFile: string, prevMonotonicsOk = monotonics.mapIt(ver < it).all(proc (x: bool): bool = x) if ver < prev[0] and prevMonotonicsOk: - displayHint(&"Versions monotonic between tag {ver}@{info.commit} " & - &" and previous tag of {prev[0]}@{prev[1].commit}", MediumPriority) + displayHint(&"Versions monotonic between tag {TagVersionFmt % $ver}@{info.commit} " & + &" and previous tag of {TagVersionFmt % $prev[0]}@{prev[1].commit}", MediumPriority) else: if prev[0] notin nonMonotonicVers: monotonics.add(prev[0]) # track last largest monotonic so we can check, e.g. 0.2, 3.0, 0.3 and not 0.2, 3.0, 0.2 nonMonotonicVers[ver] = info.commit - displayError(&"Non-monotonic (decreasing) version found between tag {ver}@{info.commit}" & - &" and the previous tag {prev[0]}@{prev[1].commit}", HighPriority) + displayError(&"Non-monotonic (decreasing) version found between tag {TagVersionFmt % $ver}@{info.commit}" & + &" and the previous tag {TagVersionFmt % $prev[0]}@{prev[1].commit}", HighPriority) displayWarning(&"Version {ver} will be skipped. Please tag it manually if the version is correct." , HighPriority) displayHint(&"Note that versions are checked from larget to smallest" , HighPriority) displayHint(&"Note later smaller versions are always peferred. Please manually review your tags before pushing." , HighPriority) @@ -363,11 +363,11 @@ proc findVersions(commits: seq[(Sha1Hash, string)], projdir, nimbleFile: string, if version in nonMonotonicVers: displayWarning(&"Skipping creating tag for non-monotonic {version} at {info.commit}", HighPriority) else: - let tag = tagVersionFmt % [$version] + let tag = TagVersionFmt % [$version] displayWarning(&"Creating tag for new version {version} at {info.commit}", HighPriority) let res = createTag(tag, info.commit, info.message, projdir, nimbleFile, downloadMethod) if not res: - displayError(&"Unable to create tag {version}", HighPriority) + displayError(&"Unable to create tag {TagVersionFmt % $version}", HighPriority) else: newTags.incl(tag) diff --git a/tests/tpublish.nim b/tests/tpublish.nim index 0d0cf089..3562be22 100644 --- a/tests/tpublish.nim +++ b/tests/tpublish.nim @@ -232,7 +232,7 @@ requires "nim >= 1.5.1" let (output, exitCode) = execNimbleYes("-y", "publishVersions") - check output.contains("Non-monotonic (decreasing) version found between tag 2.1.0") + check output.contains("Non-monotonic (decreasing) version found between tag v2.1.0") check exitCode == QuitSuccess for version in versions[1..^1]: @@ -248,7 +248,7 @@ requires "nim >= 1.5.1" let (output, exitCode) = execNimbleYes("publishVersions", "--create") - check output.contains("Non-monotonic (decreasing) version found between tag 2.1.0") + check output.contains("Non-monotonic (decreasing) version found between tag v2.1.0") check exitCode == QuitSuccess for version in versions[1..^1]: @@ -266,8 +266,8 @@ requires "nim >= 1.5.1" let (output, exitCode) = execNimbleYes("publishVersions", "--create") - check output.contains("Non-monotonic (decreasing) version found between tag 2.1.0") - check output.contains("Non-monotonic (decreasing) version found between tag 0.2.3") + check output.contains("Non-monotonic (decreasing) version found between tag v2.1.0") + check output.contains("Non-monotonic (decreasing) version found between tag v0.2.3") for line in output.splitLines(): echo ">>> ", line From 32f76d034c97500c1af294a9ca679b4f8ec96ee0 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Sun, 19 Jan 2025 01:00:29 -0700 Subject: [PATCH 20/42] adding --all option --- tests/tpublish.nim | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/tests/tpublish.nim b/tests/tpublish.nim index 3562be22..d5b59a4a 100644 --- a/tests/tpublish.nim +++ b/tests/tpublish.nim @@ -36,6 +36,7 @@ suite "publish": main = "main" bad1 = "bad1" bad2 = "bad2" + nonAll = "nonAll" template definePackageConstants(pkgName: PkgIdent) = ## By given dependency number defines all relevant constants for it. @@ -88,6 +89,7 @@ requires "nim >= 1.5.1" definePackageConstants(PkgIdent.main) definePackageConstants(PkgIdent.bad1) definePackageConstants(PkgIdent.bad2) + definePackageConstants(PkgIdent.nonAll) proc newNimbleFileContent(fileTemplate: string, version: string): string = @@ -131,6 +133,12 @@ requires "nim >= 1.5.1" proc checkout(what: string) = tryDoCmdEx(&"git checkout {what}") + proc getRepoRevision: string = + result = tryDoCmdEx("git rev-parse HEAD").replace("\n", "") + + proc getRevision(dep: string, lockFileName = defaultLockFileName): string = + result = lockFileName.readFile.parseJson{$lfjkPackages}{dep}{$lfjkPkgVcsRevision}.str + proc createBranchAndSwitchToIt(branchName: string) = if branchName.len > 0: branch(branchName) @@ -148,7 +156,7 @@ requires "nim >= 1.5.1" addFiles(fileName) commit("Add additional file") - proc initNewNimblePackage(dir: string, versions: seq[string] = @[]) = + proc initNewNimblePackage(dir: string, versions: seq[string], tags: seq[string] = @[]) = cdNewDir dir: initRepo() echo "created repo at: ", dir @@ -157,8 +165,13 @@ requires "nim >= 1.5.1" addFiles(nimbleFileName) commit("commit $1" % version) echo "created package version ", version + let commit = getRepoRevision() + if version in tags: + echo "tagging version ", version, " tag ", commit + tryDoCmdEx("git tag " & "v$1" % version.quoteShell()) if idx in [0, 1, versions.len() - 2]: addAdditionalFileToTheRepo("test.txt", $idx) + proc testLockedVcsRevisions(deps: seq[tuple[name, path: string]], lockFileName = defaultLockFileName) = check lockFileName.fileExists @@ -191,12 +204,6 @@ requires "nim >= 1.5.1" usePackageListFile pkgListFilePath: body - proc getRepoRevision: string = - result = tryDoCmdEx("git rev-parse HEAD").replace("\n", "") - - proc getRevision(dep: string, lockFileName = defaultLockFileName): string = - result = lockFileName.readFile.parseJson{$lfjkPackages}{dep}{$lfjkPkgVcsRevision}.str - proc addAdditionalFileAndPushToRemote( repoPath, remoteName, remotePath, fileContent: string) = cdNewDir remotePath: @@ -276,3 +283,24 @@ requires "nim >= 1.5.1" if version in ["2.1.0", "0.2.3"]: continue check output.contains("Creating tag for new version $1" % version) + + test "test non-all ": + # cleanUp() + let versions = @["0.1.0", "0.2.3", "2.1.0", "0.2.2", "0.2.3", "0.2.4", "0.2.5"] + initNewNimblePackage(nonAllPkgRepoPath, versions, tags = @["0.2.3"]) + cd nonAllPkgRepoPath: + echo "mainPkgRepoPath: ", nonAllPkgRepoPath + echo "getCurrentDir: ", getCurrentDir() + + let (output, exitCode) = execNimbleYes("publishVersions", "--create") + + check output.contains("Non-monotonic (decreasing) version found between tag v2.1.0") + check output.contains("Non-monotonic (decreasing) version found between tag v0.2.3") + + for line in output.splitLines(): + echo ">>> ", line + check exitCode == QuitSuccess + for version in versions[1..^1]: + if version in ["2.1.0", "0.2.3"]: + continue + check output.contains("Creating tag for new version $1" % version) From cbb745d6e4f3680d89efdfd6968f0ed1cc4a229a Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Sun, 19 Jan 2025 01:07:07 -0700 Subject: [PATCH 21/42] adding --all option --- tests/tpublish.nim | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/tests/tpublish.nim b/tests/tpublish.nim index d5b59a4a..a4f116b9 100644 --- a/tests/tpublish.nim +++ b/tests/tpublish.nim @@ -276,8 +276,6 @@ requires "nim >= 1.5.1" check output.contains("Non-monotonic (decreasing) version found between tag v2.1.0") check output.contains("Non-monotonic (decreasing) version found between tag v0.2.3") - for line in output.splitLines(): - echo ">>> ", line check exitCode == QuitSuccess for version in versions[1..^1]: if version in ["2.1.0", "0.2.3"]: @@ -286,21 +284,24 @@ requires "nim >= 1.5.1" test "test non-all ": # cleanUp() - let versions = @["0.1.0", "0.2.3", "2.1.0", "0.2.2", "0.2.3", "0.2.4", "0.2.5"] - initNewNimblePackage(nonAllPkgRepoPath, versions, tags = @["0.2.3"]) + let versions = @["0.1.0", "0.2.3", "2.1.0", "0.3.2", "0.3.3", "0.3.4", "0.3.5"] + initNewNimblePackage(nonAllPkgRepoPath, versions, tags = @["0.3.3"]) cd nonAllPkgRepoPath: echo "mainPkgRepoPath: ", nonAllPkgRepoPath echo "getCurrentDir: ", getCurrentDir() let (output, exitCode) = execNimbleYes("publishVersions", "--create") - check output.contains("Non-monotonic (decreasing) version found between tag v2.1.0") - check output.contains("Non-monotonic (decreasing) version found between tag v0.2.3") + # check output.contains("Non-monotonic (decreasing) version found between tag v2.1.0") + # check output.contains("Non-monotonic (decreasing) version found between tag v0.2.3") - for line in output.splitLines(): - echo ">>> ", line + # for line in output.splitLines(): + # echo ">>> ", line check exitCode == QuitSuccess - for version in versions[1..^1]: - if version in ["2.1.0", "0.2.3"]: - continue - check output.contains("Creating tag for new version $1" % version) + for version in versions: + if version in @["0.3.4", "0.3.5"]: + checkpoint("Checking for version $1" % version) + check output.contains("Creating tag for new version $1" % version) + # else: + checkpoint("Checking version $1 is not found" % version) + check not output.contains("Creating tag for new version $1" % version) From 72468a893433de4ec489a0c48cb9d9705e48f97c Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Sun, 19 Jan 2025 01:09:57 -0700 Subject: [PATCH 22/42] adding --all option --- tests/tpublish.nim | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/tests/tpublish.nim b/tests/tpublish.nim index a4f116b9..7bfe1078 100644 --- a/tests/tpublish.nim +++ b/tests/tpublish.nim @@ -292,16 +292,35 @@ requires "nim >= 1.5.1" let (output, exitCode) = execNimbleYes("publishVersions", "--create") - # check output.contains("Non-monotonic (decreasing) version found between tag v2.1.0") - # check output.contains("Non-monotonic (decreasing) version found between tag v0.2.3") + check not output.contains("Non-monotonic (decreasing) version found between tag v2.1.0") + check not output.contains("Non-monotonic (decreasing) version found between tag v0.2.3") - # for line in output.splitLines(): - # echo ">>> ", line check exitCode == QuitSuccess for version in versions: if version in @["0.3.4", "0.3.5"]: checkpoint("Checking for version $1" % version) check output.contains("Creating tag for new version $1" % version) - # else: + else: checkpoint("Checking version $1 is not found" % version) check not output.contains("Creating tag for new version $1" % version) + + test "test all": + # cleanUp() + let versions = @["0.1.0", "0.2.3", "2.1.0", "0.3.2", "0.3.3", "0.3.4", "0.3.5"] + cd nonAllPkgRepoPath: + echo "mainPkgRepoPath: ", nonAllPkgRepoPath + echo "getCurrentDir: ", getCurrentDir() + + let (output, exitCode) = execNimbleYes("publishVersions", "--create", "--all") + + check output.contains("Non-monotonic (decreasing) version found between tag v2.1.0") + check output.contains("Non-monotonic (decreasing) version found between tag v0.2.3") + + check exitCode == QuitSuccess + for version in versions: + if version in @["0.3.4", "0.3.5"]: + checkpoint("Checking version $1 is not found" % version) + check not output.contains("Creating tag for new version $1" % version) + else: + checkpoint("Checking for version $1" % version) + check output.contains("Creating tag for new version $1" % version) From 8c2826ffe330cb9cc366fec9ed76c8e5321f712a Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Sun, 19 Jan 2025 01:15:08 -0700 Subject: [PATCH 23/42] adding --all option --- src/nimblepkg/publish.nim | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/nimblepkg/publish.nim b/src/nimblepkg/publish.nim index af554c79..b7471d34 100644 --- a/src/nimblepkg/publish.nim +++ b/src/nimblepkg/publish.nim @@ -309,11 +309,7 @@ proc findVersions(commits: seq[(Sha1Hash, string)], projdir, nimbleFile: string, var versions: OrderedTable[Version, tuple[commit: Sha1Hash, message: string]] existingTags = findExistingTags(projdir, downloadMethod) - firstTag = newVersion("0.0.0") - if existingTags.len() > 0: - firstTag = existingTags.toSeq().sorted()[0] - echo "FIRST TAG: ", firstTag # adapted from @beef331's algorithm https://github.com/beef331/graffiti/blob/master/src/graffiti.nim block outer: for (commit, message) in commits: @@ -323,13 +319,13 @@ proc findVersions(commits: seq[(Sha1Hash, string)], projdir, nimbleFile: string, var matches: array[0..MaxSubpatterns, string] if line.find(peg"'+version' \s* '=' \s* {[\34\39]} {@} $1", matches) > -1: let ver = newVersion(matches[1]) - if ver <= firstTag: - echo "FIRST TAG PASSED " - break outer if ver notin versions: versions[ver] = (commit: commit, message: message) if ver in existingTags: - displayInfo(&"Found existing tag for version {ver} at commit {commit}", HighPriority) + if not options.action.allTags: + break outer + else: + displayInfo(&"Found existing tag for version {ver} at commit {commit}", HighPriority) else: displayInfo(&"Found new version {ver} at {commit}", HighPriority) echo "FIRST TAG DONE " From 7139011eb81f4e8bd4083f2849f7887cb6d8a2f4 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Sun, 19 Jan 2025 01:21:05 -0700 Subject: [PATCH 24/42] adding --all option --- src/nimblepkg/publish.nim | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/nimblepkg/publish.nim b/src/nimblepkg/publish.nim index b7471d34..a385aab5 100644 --- a/src/nimblepkg/publish.nim +++ b/src/nimblepkg/publish.nim @@ -320,15 +320,14 @@ proc findVersions(commits: seq[(Sha1Hash, string)], projdir, nimbleFile: string, if line.find(peg"'+version' \s* '=' \s* {[\34\39]} {@} $1", matches) > -1: let ver = newVersion(matches[1]) if ver notin versions: - versions[ver] = (commit: commit, message: message) if ver in existingTags: - if not options.action.allTags: - break outer - else: + if options.action.allTags: displayInfo(&"Found existing tag for version {ver} at commit {commit}", HighPriority) + else: + break outer else: displayInfo(&"Found new version {ver} at {commit}", HighPriority) - echo "FIRST TAG DONE " + versions[ver] = (commit: commit, message: message) var nonMonotonicVers: Table[Version, Sha1Hash] if versions.len() >= 2: @@ -351,7 +350,7 @@ proc findVersions(commits: seq[(Sha1Hash, string)], projdir, nimbleFile: string, &" and the previous tag {TagVersionFmt % $prev[0]}@{prev[1].commit}", HighPriority) displayWarning(&"Version {ver} will be skipped. Please tag it manually if the version is correct." , HighPriority) displayHint(&"Note that versions are checked from larget to smallest" , HighPriority) - displayHint(&"Note later smaller versions are always peferred. Please manually review your tags before pushing." , HighPriority) + displayHint(&"Note smaller versions later in history are always peferred. Please manually review your tags before pushing." , HighPriority) var newTags: HashSet[string] if options.action.createTags: From 403b5f865940a9d4afd8b45df0c776b697c566e0 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Sun, 19 Jan 2025 01:26:13 -0700 Subject: [PATCH 25/42] adding --all option --- tests/tpublish.nim | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/tpublish.nim b/tests/tpublish.nim index 7bfe1078..254fad76 100644 --- a/tests/tpublish.nim +++ b/tests/tpublish.nim @@ -314,13 +314,15 @@ requires "nim >= 1.5.1" let (output, exitCode) = execNimbleYes("publishVersions", "--create", "--all") check output.contains("Non-monotonic (decreasing) version found between tag v2.1.0") - check output.contains("Non-monotonic (decreasing) version found between tag v0.2.3") + check output.contains("Skipping creating tag for non-monotonic 2.1.0") check exitCode == QuitSuccess - for version in versions: - if version in @["0.3.4", "0.3.5"]: + for version in versions[1..^1]: + if version in ["0.3.3", "0.3.4", "0.3.5"]: checkpoint("Checking version $1 is not found" % version) check not output.contains("Creating tag for new version $1" % version) + elif version in ["2.1.0"]: + discard else: checkpoint("Checking for version $1" % version) check output.contains("Creating tag for new version $1" % version) From e0d66082e873c4c388818abba31ad28e032ec90b Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Sun, 19 Jan 2025 01:26:36 -0700 Subject: [PATCH 26/42] adding --all option --- tests/tpublish.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tpublish.nim b/tests/tpublish.nim index 254fad76..ca28357d 100644 --- a/tests/tpublish.nim +++ b/tests/tpublish.nim @@ -164,7 +164,7 @@ requires "nim >= 1.5.1" let nimbleFileName = dir.initNewNimbleFile(version) addFiles(nimbleFileName) commit("commit $1" % version) - echo "created package version ", version + # echo "created package version ", version let commit = getRepoRevision() if version in tags: echo "tagging version ", version, " tag ", commit From b9b05e23d70bd8515bdf3c51f3cabef43aa77ee3 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Sun, 19 Jan 2025 01:44:49 -0700 Subject: [PATCH 27/42] adding some more info messages --- src/nimblepkg/options.nim | 7 ++++--- src/nimblepkg/publish.nim | 9 ++++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/nimblepkg/options.nim b/src/nimblepkg/options.nim index 0c9a8096..09d00149 100644 --- a/src/nimblepkg/options.nim +++ b/src/nimblepkg/options.nim @@ -182,8 +182,9 @@ Commands: publish Publishes a package on nim-lang/packages. The current working directory needs to be the top level directory of the Nimble package. - publishVersions Lists package versions based on commits - where the package's Nimble version changed. + versions Lists package versions based on commits in the + current branch where the package's Nimble version + was changed. [-c, --create] Creates tags for missing versions. [-p, --push] Push only tagged versions (tags) to VCS. uninstall [pkgname, ...] Uninstalls a list of packages. @@ -340,7 +341,7 @@ proc parseActionType*(action: string): ActionType = result = actionUninstall of "publish": result = actionPublish - of "publishversions": + of "versions", "publishversions": result = actionPublishVersions of "upgrade": result = actionUpgrade diff --git a/src/nimblepkg/publish.nim b/src/nimblepkg/publish.nim index a385aab5..ea8afa68 100644 --- a/src/nimblepkg/publish.nim +++ b/src/nimblepkg/publish.nim @@ -6,7 +6,7 @@ import system except TResult import httpclient, strutils, json, os, browsers, times, uri -import common, tools, cli, config, options, packageinfotypes, sha1hashes, version, download +import common, tools, cli, config, options, packageinfotypes, vcstools, sha1hashes, version, download import strformat, sequtils, pegs, sets, tables, algorithm {.warning[UnusedImport]: off.} from net import SslCVerifyMode, newContext @@ -310,6 +310,13 @@ proc findVersions(commits: seq[(Sha1Hash, string)], projdir, nimbleFile: string, versions: OrderedTable[Version, tuple[commit: Sha1Hash, message: string]] existingTags = findExistingTags(projdir, downloadMethod) + let currBranch = getCurrentBranch(projdir) + if currBranch notin ["main", "master"]: + displayWarning(&"Note runnig this command on a non-standard primary branch `{currBranch}` may have unintened consequences", HighPriority) + + for ver in existingTags.toSeq().sorted(): + displayInfo(&"Existing tag for version {ver} ", HighPriority) + # adapted from @beef331's algorithm https://github.com/beef331/graffiti/blob/master/src/graffiti.nim block outer: for (commit, message) in commits: From 292346f832399f372f4fd69c6a23da2aae0a7f8a Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Sun, 19 Jan 2025 02:27:00 -0700 Subject: [PATCH 28/42] some refactoring --- src/nimblepkg/download.nim | 42 ++++++++++++++++++++++++-------------- src/nimblepkg/publish.nim | 18 ++++++---------- 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/src/nimblepkg/download.nim b/src/nimblepkg/download.nim index d2323fef..c6a62d5b 100644 --- a/src/nimblepkg/download.nim +++ b/src/nimblepkg/download.nim @@ -53,6 +53,18 @@ proc gitFetchTags*(repoDir: string, downloadMethod: DownloadMethod) = of DownloadMethod.hg: assert false, "hg not supported" +iterator gitTagsFromRefs(output: string): tuple[tag: string, commit: Sha1Hash] = + for line in output.splitLines(): + let refStart = line.find("refs/tags/") + # git outputs warnings, empty lines, etc + if refStart == -1: continue + if line.len() < 50: continue + let hashStr = line[0..<40] + let start = refStart+"refs/tags/".len + let tag = line[start .. line.len-1] + let hash = initSha1Hash(hashStr) + if not tag.endswith("^{}"): + yield (tag, hash) proc getTagsList*(dir: string, meth: DownloadMethod): seq[string] = var output: string @@ -66,9 +78,8 @@ proc getTagsList*(dir: string, meth: DownloadMethod): seq[string] = case meth of DownloadMethod.git: result = @[] - for i in output.splitLines(): - if i == "": continue - result.add(i) + for item in output.gitTagsFromRefs(): + result.add(item.tag) of DownloadMethod.hg: result = @[] for i in output.splitLines(): @@ -81,20 +92,11 @@ proc getTagsList*(dir: string, meth: DownloadMethod): seq[string] = result = @[] proc getTagsListRemote*(url: string, meth: DownloadMethod): seq[string] = - result = @[] case meth of DownloadMethod.git: - var (output, exitCode) = doCmdEx(&"git ls-remote --tags {url}") - if exitCode != QuitSuccess: - raise nimbleError("Unable to query remote tags for " & url & - ". Git returned: " & output) - for i in output.splitLines(): - let refStart = i.find("refs/tags/") - # git outputs warnings, empty lines, etc - if refStart == -1: continue - let start = refStart+"refs/tags/".len - let tag = i[start .. i.len-1] - if not tag.endswith("^{}"): result.add(tag) + var output = tryDoCmdEx(&"git ls-remote {url}") + for item in output.gitTagsFromRefs(): + result.add item.tag of DownloadMethod.hg: # http://stackoverflow.com/questions/2039150/show-tags-for-remote-hg-repository @@ -116,6 +118,16 @@ proc getVersionList*(tags: seq[string]): OrderedTable[Version, string] = SortOrder.Descending) result = toOrderedTable[Version, string](taggedVers) +proc gitTagCommits*(repoDir: string, downloadMethod: DownloadMethod): Table[string, Sha1Hash] = + ## Return a table of tag -> commit + case downloadMethod: + of DownloadMethod.git: + let output = tryDoCmdEx(&"git -C {repoDir} show-ref") + for item in output.gitTagsFromRefs(): + result[item.tag] = item.commit + of DownloadMethod.hg: + assert false, "hg not supported" + proc getHeadName*(meth: DownloadMethod): Version = ## Returns the name of the download method specific head. i.e. for git ## it's ``head`` for hg it's ``tip``. diff --git a/src/nimblepkg/publish.nim b/src/nimblepkg/publish.nim index ea8afa68..6fad09c6 100644 --- a/src/nimblepkg/publish.nim +++ b/src/nimblepkg/publish.nim @@ -296,26 +296,20 @@ proc pushTags*(tags: seq[string], repoDir: string, downloadMethod: DownloadMetho const TagVersionFmt = "v$1" -proc findExistingTags(projdir: string, downloadMethod: DownloadMethod): HashSet[Version] = - for tag in getTagsList(projdir, downloadMethod): - let tag = tag.strip(leading=true, chars={'v'}) - try: - result.incl(newVersion(tag)) - except ParseVersionError: - discard - proc findVersions(commits: seq[(Sha1Hash, string)], projdir, nimbleFile: string, downloadMethod: DownloadMethod, options: Options) = ## parse the versions var versions: OrderedTable[Version, tuple[commit: Sha1Hash, message: string]] - existingTags = findExistingTags(projdir, downloadMethod) + existingTags = gitTagCommits(projdir, downloadMethod) + existingVers = existingTags.keys().toSeq().getVersionList() let currBranch = getCurrentBranch(projdir) if currBranch notin ["main", "master"]: displayWarning(&"Note runnig this command on a non-standard primary branch `{currBranch}` may have unintened consequences", HighPriority) - for ver in existingTags.toSeq().sorted(): - displayInfo(&"Existing tag for version {ver} ", HighPriority) + for tag in existingTags.keys().toSeq().sorted(): + # let commit = getVersionList(tag) + displayInfo(&"Existing version {tag} ", HighPriority) # adapted from @beef331's algorithm https://github.com/beef331/graffiti/blob/master/src/graffiti.nim block outer: @@ -327,7 +321,7 @@ proc findVersions(commits: seq[(Sha1Hash, string)], projdir, nimbleFile: string, if line.find(peg"'+version' \s* '=' \s* {[\34\39]} {@} $1", matches) > -1: let ver = newVersion(matches[1]) if ver notin versions: - if ver in existingTags: + if ver in existingVers: if options.action.allTags: displayInfo(&"Found existing tag for version {ver} at commit {commit}", HighPriority) else: From 1f8cd275b46fb8c395e855ee15126707f9a0b679 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Sun, 19 Jan 2025 02:28:57 -0700 Subject: [PATCH 29/42] some refactoring --- src/nimblepkg/publish.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nimblepkg/publish.nim b/src/nimblepkg/publish.nim index 6fad09c6..b21f325d 100644 --- a/src/nimblepkg/publish.nim +++ b/src/nimblepkg/publish.nim @@ -308,8 +308,8 @@ proc findVersions(commits: seq[(Sha1Hash, string)], projdir, nimbleFile: string, displayWarning(&"Note runnig this command on a non-standard primary branch `{currBranch}` may have unintened consequences", HighPriority) for tag in existingTags.keys().toSeq().sorted(): - # let commit = getVersionList(tag) - displayInfo(&"Existing version {tag} ", HighPriority) + let commit = existingTags[tag] + displayInfo(&"Existing version {tag}@{$commit} ", HighPriority) # adapted from @beef331's algorithm https://github.com/beef331/graffiti/blob/master/src/graffiti.nim block outer: From 8409039b8cc1234f7a17d9e43fbd87978114fe22 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Sun, 19 Jan 2025 02:32:02 -0700 Subject: [PATCH 30/42] some refactoring --- src/nimblepkg/publish.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nimblepkg/publish.nim b/src/nimblepkg/publish.nim index b21f325d..cfe1d449 100644 --- a/src/nimblepkg/publish.nim +++ b/src/nimblepkg/publish.nim @@ -307,9 +307,9 @@ proc findVersions(commits: seq[(Sha1Hash, string)], projdir, nimbleFile: string, if currBranch notin ["main", "master"]: displayWarning(&"Note runnig this command on a non-standard primary branch `{currBranch}` may have unintened consequences", HighPriority) - for tag in existingTags.keys().toSeq().sorted(): + for ver, tag in existingVers.pairs(): let commit = existingTags[tag] - displayInfo(&"Existing version {tag}@{$commit} ", HighPriority) + displayInfo(&"Existing version {ver} with tag {tag} at commit {$commit} ", HighPriority) # adapted from @beef331's algorithm https://github.com/beef331/graffiti/blob/master/src/graffiti.nim block outer: From b48f5c8c9e9b8c0860bb49d7848a25354c7552fe Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Sun, 19 Jan 2025 02:56:23 -0700 Subject: [PATCH 31/42] some refactoring --- src/nimblepkg/download.nim | 44 ++++++++++++++++++++++++++++++-------- src/nimblepkg/publish.nim | 24 --------------------- 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/src/nimblepkg/download.nim b/src/nimblepkg/download.nim index c6a62d5b..e6fd5159 100644 --- a/src/nimblepkg/download.nim +++ b/src/nimblepkg/download.nim @@ -53,7 +53,7 @@ proc gitFetchTags*(repoDir: string, downloadMethod: DownloadMethod) = of DownloadMethod.hg: assert false, "hg not supported" -iterator gitTagsFromRefs(output: string): tuple[tag: string, commit: Sha1Hash] = +proc gitTagsFromRefs(output: string, derefTags = true): OrderedTable[string, Sha1Hash] = for line in output.splitLines(): let refStart = line.find("refs/tags/") # git outputs warnings, empty lines, etc @@ -63,8 +63,10 @@ iterator gitTagsFromRefs(output: string): tuple[tag: string, commit: Sha1Hash] = let start = refStart+"refs/tags/".len let tag = line[start .. line.len-1] let hash = initSha1Hash(hashStr) - if not tag.endswith("^{}"): - yield (tag, hash) + if tag.endswith("^{}") and derefTags: + result[tag] = hash + else: + result[tag] = hash proc getTagsList*(dir: string, meth: DownloadMethod): seq[string] = var output: string @@ -78,8 +80,8 @@ proc getTagsList*(dir: string, meth: DownloadMethod): seq[string] = case meth of DownloadMethod.git: result = @[] - for item in output.gitTagsFromRefs(): - result.add(item.tag) + for item in output.gitTagsFromRefs().pairs: + result.add(item[0]) of DownloadMethod.hg: result = @[] for i in output.splitLines(): @@ -95,8 +97,8 @@ proc getTagsListRemote*(url: string, meth: DownloadMethod): seq[string] = case meth of DownloadMethod.git: var output = tryDoCmdEx(&"git ls-remote {url}") - for item in output.gitTagsFromRefs(): - result.add item.tag + for item in output.gitTagsFromRefs().pairs: + result.add item[0] of DownloadMethod.hg: # http://stackoverflow.com/questions/2039150/show-tags-for-remote-hg-repository @@ -123,8 +125,32 @@ proc gitTagCommits*(repoDir: string, downloadMethod: DownloadMethod): Table[stri case downloadMethod: of DownloadMethod.git: let output = tryDoCmdEx(&"git -C {repoDir} show-ref") - for item in output.gitTagsFromRefs(): - result[item.tag] = item.commit + for item in output.gitTagsFromRefs().pairs: + result[item[0]] = item[1] + of DownloadMethod.hg: + assert false, "hg not supported" + +proc vcsFindCommits*(repoDir, nimbleFile: string, downloadMethod: DownloadMethod): seq[(Sha1Hash, string)] = + var output: string + case downloadMethod: + of DownloadMethod.git: + output = tryDoCmdEx(&"git -C {repoDir} log --format=\"%H %s\" -- $2") + of DownloadMethod.hg: + assert false, "hg not supported" + + for line in output.splitLines(): + let line = line.strip() + if line != "": + result.add((line[0..39].initSha1Hash(), line[40..^1])) + +proc vcsDiff*(commit: Sha1Hash, repoDir, nimbleFile: string, downloadMethod: DownloadMethod): seq[string] = + case downloadMethod: + of DownloadMethod.git: + let (output, exitCode) = doCmdEx(&"git -C {repoDir} diff {commit}~ {commit} {nimbleFile}") + if exitCode != QuitSuccess: + return @[] + else: + return output.splitLines() of DownloadMethod.hg: assert false, "hg not supported" diff --git a/src/nimblepkg/publish.nim b/src/nimblepkg/publish.nim index cfe1d449..f7b06828 100644 --- a/src/nimblepkg/publish.nim +++ b/src/nimblepkg/publish.nim @@ -248,30 +248,6 @@ proc publish*(p: PackageInfo, o: Options) = let prUrl = createPullRequest(auth, p, url, branchName) display("Success:", "Pull request successful, check at " & prUrl , Success, HighPriority) -proc vcsFindCommits*(repoDir, nimbleFile: string, downloadMethod: DownloadMethod): seq[(Sha1Hash, string)] = - var output: string - case downloadMethod: - of DownloadMethod.git: - output = tryDoCmdEx(&"git -C {repoDir} log --format=\"%H %s\" -- $2") - of DownloadMethod.hg: - assert false, "hg not supported" - - for line in output.splitLines(): - let line = line.strip() - if line != "": - result.add((line[0..39].initSha1Hash(), line[40..^1])) - -proc vcsDiff*(commit: Sha1Hash, repoDir, nimbleFile: string, downloadMethod: DownloadMethod): seq[string] = - case downloadMethod: - of DownloadMethod.git: - let (output, exitCode) = doCmdEx(&"git -C {repoDir} diff {commit}~ {commit} {nimbleFile}") - if exitCode != QuitSuccess: - return @[] - else: - return output.splitLines() - of DownloadMethod.hg: - assert false, "hg not supported" - proc createTag*(tag: string, commit: Sha1Hash, message, repoDir, nimbleFile: string, downloadMethod: DownloadMethod): bool = case downloadMethod: of DownloadMethod.git: From f6d9c8900c420bde6938160849e2ae5038e5fb07 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Sun, 19 Jan 2025 02:59:18 -0700 Subject: [PATCH 32/42] some refactoring --- src/nimblepkg/download.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nimblepkg/download.nim b/src/nimblepkg/download.nim index e6fd5159..0ef31f75 100644 --- a/src/nimblepkg/download.nim +++ b/src/nimblepkg/download.nim @@ -65,7 +65,7 @@ proc gitTagsFromRefs(output: string, derefTags = true): OrderedTable[string, Sha let hash = initSha1Hash(hashStr) if tag.endswith("^{}") and derefTags: result[tag] = hash - else: + elif not tag.endswith("^{}"): result[tag] = hash proc getTagsList*(dir: string, meth: DownloadMethod): seq[string] = From 0aefcaedea152383752adf30c04cd3e6cb4982f4 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Sun, 19 Jan 2025 03:06:11 -0700 Subject: [PATCH 33/42] some refactoring --- src/nimblepkg/download.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nimblepkg/download.nim b/src/nimblepkg/download.nim index 0ef31f75..6ba5dc38 100644 --- a/src/nimblepkg/download.nim +++ b/src/nimblepkg/download.nim @@ -73,7 +73,7 @@ proc getTagsList*(dir: string, meth: DownloadMethod): seq[string] = cd dir: case meth of DownloadMethod.git: - output = tryDoCmdEx("git tag") + output = tryDoCmdEx(&"git show-ref --dereference") of DownloadMethod.hg: output = tryDoCmdEx("hg tags") if output.len > 0: @@ -124,7 +124,7 @@ proc gitTagCommits*(repoDir: string, downloadMethod: DownloadMethod): Table[stri ## Return a table of tag -> commit case downloadMethod: of DownloadMethod.git: - let output = tryDoCmdEx(&"git -C {repoDir} show-ref") + let output = tryDoCmdEx(&"git -C {repoDir} show-ref --dereference") for item in output.gitTagsFromRefs().pairs: result[item[0]] = item[1] of DownloadMethod.hg: From 372b7e7acca2abf67b7f3c8c38af149fa8d7ac83 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Sun, 19 Jan 2025 03:13:38 -0700 Subject: [PATCH 34/42] some refactoring --- src/nimblepkg/download.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nimblepkg/download.nim b/src/nimblepkg/download.nim index 6ba5dc38..f9f425e0 100644 --- a/src/nimblepkg/download.nim +++ b/src/nimblepkg/download.nim @@ -64,7 +64,7 @@ proc gitTagsFromRefs(output: string, derefTags = true): OrderedTable[string, Sha let tag = line[start .. line.len-1] let hash = initSha1Hash(hashStr) if tag.endswith("^{}") and derefTags: - result[tag] = hash + result[tag[0..^4]] = hash elif not tag.endswith("^{}"): result[tag] = hash @@ -97,7 +97,7 @@ proc getTagsListRemote*(url: string, meth: DownloadMethod): seq[string] = case meth of DownloadMethod.git: var output = tryDoCmdEx(&"git ls-remote {url}") - for item in output.gitTagsFromRefs().pairs: + for item in output.gitTagsFromRefs(derefTags = false).pairs: result.add item[0] of DownloadMethod.hg: From d11c2ec04deb2953e617a5b00746015cfe42fcff Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Sun, 19 Jan 2025 03:16:18 -0700 Subject: [PATCH 35/42] some refactoring --- src/nimblepkg/publish.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nimblepkg/publish.nim b/src/nimblepkg/publish.nim index f7b06828..90a36def 100644 --- a/src/nimblepkg/publish.nim +++ b/src/nimblepkg/publish.nim @@ -299,7 +299,7 @@ proc findVersions(commits: seq[(Sha1Hash, string)], projdir, nimbleFile: string, if ver notin versions: if ver in existingVers: if options.action.allTags: - displayInfo(&"Found existing tag for version {ver} at commit {commit}", HighPriority) + displayInfo(&"Skipping historical version {ver} at commit {commit} that has an existing tag", HighPriority) else: break outer else: From c1758467fd680703f58ae2e4f99045ccba0f7691 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Sun, 19 Jan 2025 03:18:20 -0700 Subject: [PATCH 36/42] some refactoring --- src/nimblepkg/download.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nimblepkg/download.nim b/src/nimblepkg/download.nim index f9f425e0..c0fcc478 100644 --- a/src/nimblepkg/download.nim +++ b/src/nimblepkg/download.nim @@ -97,7 +97,7 @@ proc getTagsListRemote*(url: string, meth: DownloadMethod): seq[string] = case meth of DownloadMethod.git: var output = tryDoCmdEx(&"git ls-remote {url}") - for item in output.gitTagsFromRefs(derefTags = false).pairs: + for item in output.gitTagsFromRefs().pairs: result.add item[0] of DownloadMethod.hg: From df35f6048bbcb62a790fdc4ae3586e1158e2d5ff Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Sun, 19 Jan 2025 03:19:20 -0700 Subject: [PATCH 37/42] some refactoring --- src/nimblepkg/publish.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nimblepkg/publish.nim b/src/nimblepkg/publish.nim index 90a36def..a47936d8 100644 --- a/src/nimblepkg/publish.nim +++ b/src/nimblepkg/publish.nim @@ -299,7 +299,7 @@ proc findVersions(commits: seq[(Sha1Hash, string)], projdir, nimbleFile: string, if ver notin versions: if ver in existingVers: if options.action.allTags: - displayInfo(&"Skipping historical version {ver} at commit {commit} that has an existing tag", HighPriority) + displayWarning(&"Skipping historical version {ver} at commit {commit} that has an existing tag", HighPriority) else: break outer else: From f18ce400701911751b555c48b719c6c08de74e60 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Sun, 19 Jan 2025 04:04:07 -0700 Subject: [PATCH 38/42] some refactoring --- src/nimblepkg/publish.nim | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/nimblepkg/publish.nim b/src/nimblepkg/publish.nim index a47936d8..8bfe9cec 100644 --- a/src/nimblepkg/publish.nim +++ b/src/nimblepkg/publish.nim @@ -345,6 +345,8 @@ proc findVersions(commits: seq[(Sha1Hash, string)], projdir, nimbleFile: string, if options.action.pushTags: let res = pushTags(newTags.toSeq(), projdir, downloadMethod) + if not res: + displayError(&"Error pushing tags", HighPriority) proc publishVersions*(p: PackageInfo, options: Options) = displayInfo(&"Searcing for new tags for {$p.basicInfo.name} @{$p.basicInfo.version}", HighPriority) From fd6b7b64f1853ed5b6171b52ca33eccfcdcdd3c2 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Sun, 19 Jan 2025 04:09:16 -0700 Subject: [PATCH 39/42] cleanup --- tests/tpublish.nim | 90 +++++++--------------------------------------- 1 file changed, 12 insertions(+), 78 deletions(-) diff --git a/tests/tpublish.nim b/tests/tpublish.nim index ca28357d..10082ac5 100644 --- a/tests/tpublish.nim +++ b/tests/tpublish.nim @@ -3,22 +3,17 @@ {.used.} -import unittest, os, strformat, json, strutils, sequtils +import unittest, os, strformat, json, strutils import testscommon -import nimblepkg/displaymessages import nimblepkg/sha1hashes import nimblepkg/paths -import nimblepkg/vcstools from nimblepkg/common import cd, dump, cdNewDir from nimblepkg/tools import tryDoCmdEx, doCmdEx from nimblepkg/packageinfotypes import DownloadMethod from nimblepkg/lockfile import LockFileJsonKeys -from nimblepkg/options import defaultLockFileName -from nimblepkg/developfile import ValidationError, ValidationErrorKind, - developFileName, getValidationErrorMessage suite "publish": type @@ -30,7 +25,7 @@ suite "publish": description: string license: string - PackagesListFileContent = seq[PackagesListFileRecord] + # PackagesListFileContent = seq[PackagesListFileRecord] PkgIdent {.pure.} = enum main = "main" @@ -74,8 +69,8 @@ suite "publish": additionalRemotesDirName = "remotes" additionalRemotesDirPath = tempDir / additionalRemotesDirName - pkgListFileName = "packages.json" - pkgListFilePath = tempDir / pkgListFileName + # pkgListFileName = "packages.json" + # pkgListFilePath = tempDir / pkgListFileName nimbleFileTemplate = """ @@ -104,16 +99,6 @@ requires "nim >= 1.5.1" proc commit(msg: string) = tryDoCmdEx("git commit -am " & msg.quoteShell) - proc push(remote: string) = - tryDoCmdEx( - &"git push --set-upstream {remote} {vcsTypeGit.getVcsDefaultBranchName}") - - proc pull(remote: string) = - tryDoCmdEx("git pull " & remote) - - proc addRemote(remoteName, remoteUrl: string) = - tryDoCmdEx(&"git remote add {remoteName} {remoteUrl}") - proc configUserAndEmail = tryDoCmdEx("git config user.name \"John Doe\"") tryDoCmdEx("git config user.email \"john.doe@example.com\"") @@ -123,27 +108,9 @@ requires "nim >= 1.5.1" tryDoCmdEx("git init " & bare) configUserAndEmail() - proc clone(urlFrom, pathTo: string) = - tryDoCmdEx(&"git clone {urlFrom} {pathTo}") - cd pathTo: configUserAndEmail() - - proc branch(branchName: string) = - tryDoCmdEx(&"git branch {branchName}") - - proc checkout(what: string) = - tryDoCmdEx(&"git checkout {what}") - proc getRepoRevision: string = result = tryDoCmdEx("git rev-parse HEAD").replace("\n", "") - proc getRevision(dep: string, lockFileName = defaultLockFileName): string = - result = lockFileName.readFile.parseJson{$lfjkPackages}{dep}{$lfjkPkgVcsRevision}.str - - proc createBranchAndSwitchToIt(branchName: string) = - if branchName.len > 0: - branch(branchName) - checkout(branchName) - proc initNewNimbleFile(dir: string, version: string): string = let pkgName = dir.splitPath.tail let nimbleFileName = pkgName & ".nimble" @@ -173,47 +140,14 @@ requires "nim >= 1.5.1" addAdditionalFileToTheRepo("test.txt", $idx) - proc testLockedVcsRevisions(deps: seq[tuple[name, path: string]], lockFileName = defaultLockFileName) = - check lockFileName.fileExists - - let json = lockFileName.readFile.parseJson - for (depName, depPath) in deps: - let expectedVcsRevision = depPath.getVcsRevision - check depName in json{$lfjkPackages} - let lockedVcsRevision = - json{$lfjkPackages}{depName}{$lfjkPkgVcsRevision}.str.initSha1Hash - check lockedVcsRevision == expectedVcsRevision - - template filesAndDirsToRemove() = - removeFile pkgListFilePath - removeDir installDir - removeDir tempDir - - template cleanUp() = - filesAndDirsToRemove() - defer: filesAndDirsToRemove() - - proc writePackageListFile(path: string, content: PackagesListFileContent) = - let dir = path.splitPath.head - createDir dir - writeFile(path, (%content).pretty) - - template withPkgListFile(body: untyped) = - writePackageListFile( - pkgListFilePath, @[bad1PkgListFileRecord, dep2PkgListFileRecord]) - usePackageListFile pkgListFilePath: - body - - proc addAdditionalFileAndPushToRemote( - repoPath, remoteName, remotePath, fileContent: string) = - cdNewDir remotePath: - initRepo(isBare = true) - cd repoPath: - # Add commit to the dependency. - addAdditionalFileToTheRepo("dep1.nim", fileContent) - addRemote(remoteName, remotePath) - # Push it to the newly added remote to be able to lock. - push(remoteName) + # template filesAndDirsToRemove() = + # removeFile pkgListFilePath + # removeDir installDir + # removeDir tempDir + + # template cleanUp() = + # filesAndDirsToRemove() + # defer: filesAndDirsToRemove() test "test publishVersions basic find versions": # cleanUp() From 9812a44d91c54b1011875be11664086591a3c91c Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Sun, 19 Jan 2025 04:45:43 -0700 Subject: [PATCH 40/42] fix compile warnings --- tests/tpublish.nim | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/tpublish.nim b/tests/tpublish.nim index 10082ac5..252bde4f 100644 --- a/tests/tpublish.nim +++ b/tests/tpublish.nim @@ -13,7 +13,6 @@ import nimblepkg/paths from nimblepkg/common import cd, dump, cdNewDir from nimblepkg/tools import tryDoCmdEx, doCmdEx from nimblepkg/packageinfotypes import DownloadMethod -from nimblepkg/lockfile import LockFileJsonKeys suite "publish": type From bb65d955fbe5be790c2bbc546c77aa63e340c6d4 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Sat, 18 Jan 2025 21:28:42 -0700 Subject: [PATCH 41/42] change tests default output From 1265ca34a807e79594002b7378d9e6c82b06260f Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Sun, 19 Jan 2025 17:36:40 -0700 Subject: [PATCH 42/42] change to hardcoded checks for debugging ease --- tests/tpublish.nim | 51 ++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/tests/tpublish.nim b/tests/tpublish.nim index 252bde4f..b414b6fe 100644 --- a/tests/tpublish.nim +++ b/tests/tpublish.nim @@ -159,8 +159,10 @@ requires "nim >= 1.5.1" let (output, exitCode) = execNimbleYes("-y", "publishVersions") check exitCode == QuitSuccess - for version in versions[1..^1]: - check output.contains("Found new version $1" % version) + check output.contains("Found new version 0.1.1") + check output.contains("Found new version 0.1.2") + check output.contains("Found new version 0.2.1") + check output.contains("Found new version 1.0.0") test "test warning publishVersions non-monotonic versions": # cleanUp() @@ -175,8 +177,10 @@ requires "nim >= 1.5.1" check output.contains("Non-monotonic (decreasing) version found between tag v2.1.0") check exitCode == QuitSuccess - for version in versions[1..^1]: - check output.contains("Found new version $1" % version) + check output.contains("Found new version 0.1.1") + check output.contains("Found new version 0.1.2") + check output.contains("Found new version 0.2.1") + check output.contains("Found new version 1.0.0") test "test skipping publishVersions non-monotonic versions": # cleanUp() @@ -191,10 +195,9 @@ requires "nim >= 1.5.1" check output.contains("Non-monotonic (decreasing) version found between tag v2.1.0") check exitCode == QuitSuccess - for version in versions[1..^1]: - if version == "2.1.0": - continue - check output.contains("Creating tag for new version $1" % version) + check output.contains("Found new version 0.1.1") + check output.contains("Found new version 0.2.1") + check output.contains("Found new version 1.0.0") test "test skipping publishVersions non-monotonic versions 2 ": # cleanUp() @@ -214,6 +217,9 @@ requires "nim >= 1.5.1" if version in ["2.1.0", "0.2.3"]: continue check output.contains("Creating tag for new version $1" % version) + check output.contains("Found new version 0.1.1") + check output.contains("Found new version 0.2.2") + check output.contains("Found new version 0.2.4") test "test non-all ": # cleanUp() @@ -229,13 +235,12 @@ requires "nim >= 1.5.1" check not output.contains("Non-monotonic (decreasing) version found between tag v0.2.3") check exitCode == QuitSuccess - for version in versions: - if version in @["0.3.4", "0.3.5"]: - checkpoint("Checking for version $1" % version) - check output.contains("Creating tag for new version $1" % version) - else: - checkpoint("Checking version $1 is not found" % version) - check not output.contains("Creating tag for new version $1" % version) + check output.contains("Creating tag for new version 0.3.4") + check output.contains("Creating tag for new version 0.3.5") + check not output.contains("Creating tag for new version 0.2.3") + check not output.contains("Creating tag for new version 2.1.0") + check not output.contains("Creating tag for new version 0.3.2") + check not output.contains("Creating tag for new version 0.3.3") test "test all": # cleanUp() @@ -250,12 +255,10 @@ requires "nim >= 1.5.1" check output.contains("Skipping creating tag for non-monotonic 2.1.0") check exitCode == QuitSuccess - for version in versions[1..^1]: - if version in ["0.3.3", "0.3.4", "0.3.5"]: - checkpoint("Checking version $1 is not found" % version) - check not output.contains("Creating tag for new version $1" % version) - elif version in ["2.1.0"]: - discard - else: - checkpoint("Checking for version $1" % version) - check output.contains("Creating tag for new version $1" % version) + check not output.contains("Creating tag for new version 0.3.3") + check not output.contains("Creating tag for new version 0.3.4") + check not output.contains("Creating tag for new version 0.3.5") + check not output.contains("Creating tag for new version 0.1.0") + check output.contains("Creating tag for new version 0.2.3") + check not output.contains("Creating tag for new version 2.1.0") + check output.contains("Creating tag for new version 0.3.2")