Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could pandoc --version indicates a different version for nightly builds of current unreleased Pandoc ? #8016

Closed
cderv opened this issue Apr 11, 2022 · 16 comments

Comments

@cderv
Copy link
Contributor

cderv commented Apr 11, 2022

Pandoc is built daily through Github action (https://github.com/jgm/pandoc/actions/workflows/nightly.yml) and this is really useful to be able to tests our external toolings based on next Pandoc version. For example, we use these builds in CI tests to detect breaking change before a new Pandoc version is released. This complete our tests suites of several Pandoc versions.

One thing that is not easy to overcome is that nightly version of Pandoc does have the same version number as the last Pandoc release.

pandoc.exe 2.18
Compiled with pandoc-types 1.22.2, texmath 0.12.5, skylighting 0.12.3,
citeproc 0.7, ipynb 0.2, hslua 2.2.0
Scripting engine: Lua 5.4
User data directory: C:\Users\chris\AppData\Roaming\pandoc
Copyright (C) 2006-2022 John MacFarlane. Web:  https://pandoc.org
This is free software; see the source for copying conditions. There is no
warranty, not even for merchantability or fitness for a particular purpose.

This means there is no easy way to know that we are running a newer Pandoc version than last released one. However, the newer version could already have changes we need to deal with and usually adding conditional testing as we want support also for older version.
It would be good to have a way to know from Pandoc CLI itself that we are not running last release (2.18 here) but a newer version (2.18+). Then we could just add a condition like

if (pandoc version > 2.18) then 
  test new behavior
else 
  test old behavior

This can't be done for now as pandoc --version would give the same version number.

About potential solution,

I think that one could be in the version scheme itself which is common for software I believe. Pandoc follows Haskell versionning policy and already uses up to 4 components. This would probably mean adding a 5th one. Devel version would be on 5 numbers (2.18.0.0.0 = devel after 2.18, 2.14.0.3.0 = devel after 2.14.0.3, ...) with the last number incremented at each nightly build or not incremented to simplify and staying with 0, or maybe another one like 9 or 99 to be more clear on devel status (2.18.0.0.99 for devel right after 2.18, or 2.14.0.3.99 for devel after 2.14.0.3).

If version scheme change is not an option, then it could simply be an indication in results from pandoc --version that could be parsed.
This is less ideal because it means having specific parsing step to detect development version, and comparing version number would not show that the nightly build is above the last release one.

This could be something like

pandoc.exe 2.18
+ nightly build from commit 810879a
Compiled with pandoc-types 1.22.2, texmath 0.12.5, skylighting 0.12.3,
citeproc 0.7, ipynb 0.2, hslua 2.2.0
Scripting engine: Lua 5.4
User data directory: C:\Users\chris\AppData\Roaming\pandoc
Copyright (C) 2006-2022 John MacFarlane. Web:  https://pandoc.org
This is free software; see the source for copying conditions. There is no
warranty, not even for merchantability or fitness for a particular purpose.

This could be probably using some flags or environment variable to opt in adding this string output and that would be set in the Github action build workflow

, Option "v" ["version"]
(NoArg
(\_ -> do
prg <- getProgName
defaultDatadir <- defaultUserDataDir
luaVersion <- HsLua.run @HsLua.Exception $ do
openlibs
getglobal "_VERSION"
peek top
UTF8.hPutStrLn stdout
$ T.pack
$ prg ++ " " ++ T.unpack pandocVersion ++
compileInfo ++ "\nScripting engine: " ++ luaVersion ++
"\nUser data directory: " ++ defaultDatadir ++
('\n':copyrightMessage)
exitSuccess ))
"" -- "Print version"

Regarding alternatives I have considered, our current workaround is to set an environment variable indicating we are installing a nightly build version, and check this instead of the version number only in our conditional testing. This is not ideal it requires manual editing when a new version is released to adjust as pandoc --version will output a higher version in the new release.

I am opening this issue for discussion. Is this something you would consider adding ?

Thank you.

@jgm
Copy link
Owner

jgm commented Apr 11, 2022

I don't want to mess with version numbers (which aren't really meaningful for the nightlies anyway, since we often don't increment them with API changes until a release happens).
But including the git hash in the --version output seems a good idea. Indeed, we could do this for all builds, not just nightlies: why not?

@jgm
Copy link
Owner

jgm commented Apr 11, 2022

Note: some builds aren't from a git repository, but e.g. from a tarball, so maybe not all builds.

@jgm
Copy link
Owner

jgm commented Apr 11, 2022

@cderv
Copy link
Contributor Author

cderv commented Apr 11, 2022

If we have a way to differentiate easily an unreleased build version from a release build, then it would improve this.

If it is not by the version number, that is fine. It means the latest release, and unreleased build would still have the same version though. If the later have a hash included, that would be enough to parse the version message and know this is not a released build but a newer version.

And if some builds have that, even if not all, that would be good too.

Thanks for considering

@jgm
Copy link
Owner

jgm commented Apr 11, 2022

I've pushed a commit that adds info about the git hash and date of the build to all builds.
This doesn't address your desire to have a clear marking of whether it's a release build, so perhaps we can keep this open for now.

@jgm jgm closed this as completed in f81f5a2 Apr 12, 2022
@jgm
Copy link
Owner

jgm commented Apr 12, 2022

I've reverted that commit and used a different approach, just adding the suffix -nightly-DATE on the version for nightlies. (This is triggered via a cabal flag nightly.)

@cderv
Copy link
Contributor Author

cderv commented Apr 12, 2022

That will work perfectly thank you !

cderv added a commit to rstudio/rmarkdown that referenced this issue Apr 12, 2022
They are of the form `X.Y.Z.p-nightly-DATE`, with `X.Y.Z.p` being the version number of last pandoc release.

Tweak is made to be numeric so that `pandoc_available()` can properly compare.

Follows update in jgm/pandoc#8016
cderv added a commit to cderv/pandoc that referenced this issue Apr 12, 2022
They are of the form `X.Y.Z.p-nightly-DATE`, with `X.Y.Z.p` being the version number of last pandoc release.

Tweak is made to be numeric so that `pandoc_available()` can properly compare.

Follows update in jgm/pandoc#8016
@cderv
Copy link
Contributor Author

cderv commented Apr 12, 2022

I don't know if this is directly related to this change but could be. the nightly version does not work correctly:

❯ echo "**test**" | ./pandoc -t native
Could not find data file D:\a\pandoc\pandoc\.stack-work\install\05458cf5\share\x86_64-windows-ghc-8.10.7\pandoc-2.18\data\abbreviations
❯ ./pandoc --version
pandoc.exe 2.18-nightly-2022-04-12
Compiled with pandoc-types 1.22.2, texmath 0.12.5, skylighting 0.12.3,
citeproc 0.7, ipynb 0.2, hslua 2.2.0
Scripting engine: Lua 5.4
User data directory: C:\Users\chris\AppData\Roaming\pandoc
Copyright (C) 2006-2022 John MacFarlane. Web:  https://pandoc.org
This is free software; see the source for copying conditions. There is no
warranty, not even for merchantability or fitness for a particular purpose.

Seems like some hard coded path from the Windows build are there now. Do you want a new issue for this ?

@jgm
Copy link
Owner

jgm commented Apr 12, 2022

I can guess what the problem is...it seems to be overwriting all flags rather than just setting teh nightly flag. We can reopen this.

@jgm jgm reopened this Apr 12, 2022
jgm added a commit that referenced this issue Apr 12, 2022
It seems that stack is replacing ALL flag settings rather
than overriding just one with `--flag`?

This should address #8016 but we await testing after
tonight's nightly is built.
@jgm
Copy link
Owner

jgm commented Apr 12, 2022

Let's see how tonight's nightlies look.

@jgm
Copy link
Owner

jgm commented Apr 12, 2022

Oh, I just realized that the patch I suggested is completely wrong. (It will print the current time, not the compile time.)
We need either template haskell or something simpler, like passing in an explicit version suffix using a CPP define.

@jgm
Copy link
Owner

jgm commented Apr 12, 2022

For now I've rolled back all the changes.
Will try another approach later.

@cderv
Copy link
Contributor Author

cderv commented Apr 12, 2022

Ok thanks. I'll revert on my side too then.

@hseg
Copy link
Contributor

hseg commented Apr 12, 2022

This doesn't address your desire to have a clear marking of whether it's a
release build

Judging by git describe's manpage, the problem is that githash neither
exposes git describe --exact-match, nor does it decompose the structure
returned by git describe. It could do so, by instead running
git describe --tags --abbrev=0,
git rev-list $(git rev-list --tags --no-walk --max-count=1)..@ --count,
git rev-parse HEAD respectively. We could then detect non-release builds by
checking if the commit count is 0.

Or alternatively, we could parse git describe's output ourselves, eg

commitsSinceTag :: GitInfo -> Maybe Int
commitsSinceTag gi =
    read . rtakeWhile (/='-') <$> lstrip ("-g" ++ giTag gi) (giDescribe gi)
  where
    lstrip xs ys = reverse <$> strip (reverse xs) (reverse ys)
    strip [] ys = Just ys
    strip (x:xs) (y:ys) = guard (x == y) *> strip xs ys
    rtakeWhile p = reverse . takeWhile p . reverse

Much less elegant. Do we want to bug githash upstream about this?

@jgm jgm closed this as completed in dc03399 Apr 13, 2022
@jgm
Copy link
Owner

jgm commented Apr 13, 2022

Actually the githash package provides giTag, which does list the number of commits since the last tag.

I didn't want to use this, though, because I usually tag AFTER building releases (to make sure they work). So this method can't detect a release build, unless we build the packages again after tagging, which i'd rather not do (waste of energy).

Anyway, I've pushed a new patch which builds in the compile date when the nightly flag is set, and without requiring the githash package.

@hseg
Copy link
Contributor

hseg commented Apr 13, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants