release-it / keep-a-changelog

Keep a Changelog plugin for release-it

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is it possible `latestTag` is not being set in the context somehow?

birtles opened this issue · comments

I've been using this plugin over in my 10ten-ja-reader repository and I've noticed it never quite updates the version links correctly. Instead I get changes like:

-[unreleased]: https://github.com/birchill/10ten-ja-reader/compare/v1.15.1...HEAD
+[unreleased]: https://github.com/birchill/10ten-ja-reader/compare/v1.16.0...HEAD
 [1.15.1]: https://github.com/birchill/10ten-ja-reader/compare/v1.15.0...v1.15.1
 ...
 [0.0.4]: https://github.com/birchill/10ten-ja-reader/releases/tag/v0.0.4
+
+[1.16.0]: https://github.com/birchill/10ten-ja-reader/releases/tag/v1.16.0

Whereas I expect it to produce:

-[unreleased]: https://github.com/birchill/10ten-ja-reader/compare/v1.15.1...HEAD
+[unreleased]: https://github.com/birchill/10ten-ja-reader/compare/v1.16.0...HEAD
+[1.16.0]: https://github.com/birchill/10ten-ja-reader/compare/v1.15.1...v1.16.0
 [1.15.1]: https://github.com/birchill/10ten-ja-reader/compare/v1.15.0...v1.15.1

Examples:

I've had a dig through the code and the only way I can see this happening is if the following line is true:

if (!latestTag || latestTag === '0.0.0') {

So my best guess is latestTag is not being passed to the plugin (or is undefined at the point where it is set).

Here is the verbose log from the CI run for the 1.16.0 release:

https://github.com/birchill/10ten-ja-reader/actions/runs/6999944916/job/19039902679#step:9:1

Of note:

  • Initially it appears to have trouble fetching tags:
    $ git describe --tags --match=v* --abbrev=0
    fatal: No tags can describe '8985aaeed8e32cd4c970affa7fa97d8918100512'.
    Try --always, or create some tags.
    
    Running the same command locally works for me, however, so I'm not sure what is different in CI. I suppose it's something to do with the way the repo is fetched?
  • However, later on it runs the same command, uses a cached result, and seems to know that the previous release is 1.15.1 when it logs:
    $ git describe --tags --match=v* --abbrev=0  [cached]
    🚀 Let's release 10ten-ja-reader (1.15.1...1.16.0)
    

I haven't dug into how release-it calls plugins yet, but I'm just filing this for now in case anyone else has suggestions of where to look.

(Note to self, running with NODE_DEBUG=release-it:* might help.)

(Also note to self, getLatestTagFromAllRefs looks interesting but I'm not using branches as part of the release process so it shouldn't matter?)

On further thought, I'll bet this is just a matter of adding fetch-depth: 0 to the checkout step so that all tags are fetched.

Now I wonder if adding fetch-depth: 0 helped :)

Yes, me too! I'm still waiting until the next release is ready to check but I'm 95% sure that's the problem so feel free to close this in anticipation of that.

Don't want to miss out on this one, the suspense is killing me! 😄

Yes, fetch-depth: 0 fixed it! Sorry for the false alarm.

No worries, just glad we're through :)