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

Load sdk version from buildinfo #521

Merged
merged 2 commits into from
Dec 27, 2024

Conversation

Yang-33
Copy link
Contributor

@Yang-33 Yang-33 commented Dec 25, 2024

Currently, line-bot-sdk-go embeds the library version defined in version.go as the user-agent, so version.go is updated manually or forcibly at release time to avoid manual operation. And we define a github workflow to push tag forcibly to automate (1) updating version.go and (2)fix git tag. Because of this, GitHub's branch protection cannot be used. (we can solve this by using PAT, but we don't want to use it)

Since Go 1.18, https://pkg.go.dev/debug/buildinfo has been provided. By using runtime/debug, library(like line-bot-sdk-go) can obtain the library's own version from the runtime of the library user. Since the latest version of line-bot-sdk-go only supports Go 1.22 and above, this feature should be usable.

In the user's environment, the version of line-bot-sdk-go is retrieved from buildinfo only once in runtime. There's no point in recalculating it each time since the same value should be obtained every time.

Excluding meaningless mocks, tests in this repository cannot be written. I created minimum example for this patch.

@Yang-33 Yang-33 requested a review from kkdai December 25, 2024 23:55
@Yang-33 Yang-33 self-assigned this Dec 26, 2024
Copy link
Member

@kkdai kkdai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems GetVersion() cannot retrieval github.com/line/line-bot-sdk-go build info. only itself deps.

Have you ever try it?

@Yang-33
Copy link
Contributor Author

Yang-33 commented Dec 26, 2024

I created minimum samples for this case. it worked as expected.

About lib repository

https://github.com/Yang-33/line-bot-sdk-go-521-lib

This provides simple http-client calling debug.ReadBuildInfo() internally. You can consider this as a repository similar to line-bot-sdk-go with this patch.

Below app uses this. (or you can use this library in your app)

about app repository

https://github.com/Yang-33/line-bot-sdk-go-521-app

This just uses https://github.com/Yang-33/line-bot-sdk-go-521-lib (lib repository like line-bot-sdk-go), and other libraries.

When the app uses library provided in https://github.com/Yang-33/line-bot-sdk-go-521-lib, it shows all dependencies the app uses.

like

=== All Dependencies ===
- github.com/Yang-33/line-bot-sdk-go-521-lib v0.1.0
- github.com/sirupsen/logrus v1.9.0
- golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8
========================

app calls lib, and lib shows all dependencies in app.

Therefore, I believe this change is working as expected. In the user app, line-bot-sdk-go can obtain its version from buildinfo.

I believe we no longer need to write the version in version.go in line-bot-sdk-go explicitly.

@Yang-33 Yang-33 requested a review from kkdai December 26, 2024 13:45
Copy link
Member

@kkdai kkdai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I don't have any more question. Thank you.

@Yang-33
Copy link
Contributor Author

Yang-33 commented Dec 27, 2024

Thank you for your review!

@Yang-33 Yang-33 merged commit 53a2230 into line:master Dec 27, 2024
4 checks passed
@Yang-33 Yang-33 deleted the get-version-from-buildinfo branch December 27, 2024 04:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants