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

Allow version to be set manually #5072

Merged
merged 4 commits into from Oct 5, 2022
Merged

Allow version to be set manually #5072

merged 4 commits into from Oct 5, 2022

Conversation

assistcontrol
Copy link
Contributor

When Caddy is built from a release tarball (as downloaded from GitHub), caddy version returns an empty string. This causes confusion for downstream packagers.

With this commit, VersionString can be set with eg.
go build (...) -ldflags '-X (...).VersionString=v1.2.3'
Then the short form version will be "v1.2.3", and the full version string will begin with "v1.2.3 ".

When Caddy is built from a release tarball (as downloaded from GitHub),
`caddy version` returns an empty string. This causes confusion for
downstream packagers.

With this commit, VersionString can be set with eg.
  go build (...) -ldflags '-X (...).VersionString=v1.2.3'
Then the short form version will be "v1.2.3", and the full version
string will begin with "v1.2.3 ".
@assistcontrol
Copy link
Contributor Author

See #5065 for some discussion on this.

@mholt
Copy link
Member

mholt commented Sep 29, 2022

Thanks! I just pushed some revisions that prefer the embedded version if available, but still prepends the CustomVersion (renamed from VersionString) if set.

Let me know if that's OK with you, and if so I'll merge this and maybe release 2.6.2 here pretty soon.

@mholt mholt added the under review 🧐 Review is pending before merging label Sep 29, 2022
@mholt mholt added this to the v2.6.2 milestone Sep 29, 2022
@assistcontrol
Copy link
Contributor Author

If I'm reading it correctly, CustomVersion is no longer prepended to full if full is non-empty.

It looks like it is still possible for full to wind up being empty.

if full == "" {
	full = CustomVersion
} else if CustomVersion != "" {
	full = CustomVersion + " " + full
}

If full = "" and CustomVersion = "", then full will be empty. Similarly, if full = "" and CustomVersion="foo", then full = "foo " (with a trailing space).

Perhaps instead, default an empty full to simple, and prepend CustomVersion:

	if simple == "" || simple == "(devel)" {
		simple = "unknown"
		if CustomVersion != "" {
			simple = CustomVersion
		} else {
			simple = "unknown"
		}
	}

	if full == "" {
		if CustomVersion == "" {
			full = simple
		} else {
			full = CustomVersion
		}
	} else {
		full = CustomVersion + " " + full
	}

@assistcontrol
Copy link
Contributor Author

The first simple = "unknown" is probably superfluous.

It may also be safe to assume that an empty full should just be simple which will be CustomVersion, because an empty full means an empty simple:

	if simple == "" || simple == "(devel)" {
		if CustomVersion != "" {
			simple = CustomVersion
		} else {
			simple = "unknown"
		}
	}

	if full == "" {
		full = simple
	} else {
		full = CustomVersion + " " + full
	}

@mholt
Copy link
Member

mholt commented Sep 29, 2022

(Can you do inline comments next time? That'll make code review easier.)

If I'm reading it correctly, CustomVersion is no longer prepended to full if full is non-empty.

It is still prepended: https://github.com/caddyserver/caddy/pull/5072/files#diff-57caf2be698e920a2599b611efd1b33dea35fd79976cacdf3354ab3f55706515R932

It looks like it is still possible for full to wind up being empty.

Yes, but only if there is absolutely no version information embedded and CustomVersion is empty, then full will be empty. This is probably OK, rather than covering up the fact with a non-empty value? I dunno.

Similarly, if full = "" and CustomVersion="foo", then full = "foo " (with a trailing space).

Are you sure that's true? Not in my testing.

Let's sort out those understandings and then we can make more tweaks if needed.

@mholt
Copy link
Member

mholt commented Oct 5, 2022

@assistcontrol Is there anything else before I go ahead and merge this in? Will probably do so in a day or two otherwise.

@assistcontrol
Copy link
Contributor Author

Sorry, IRL has been busy.

It looks like it is still possible for full to wind up being empty.

Yes, but only if there is absolutely no version information embedded and CustomVersion is empty, then full will be empty. This is probably OK, rather than covering up the fact with a non-empty value? I dunno.

All it takes for there to be absolutely no version information embedded is to download any of the tarballs on the GH releases page.

I guess the question is, when someone downloads a tarball from the GH release page and doesn't know to set CustomVersion, would you prefer that caddy version print nothing, or unknown? I have my preference ("unknown" is better than wondering whether the caddy version command itself is broken) but I'm behind you and pleased with your edits no matter which path you prefer here.

@mholt
Copy link
Member

mholt commented Oct 5, 2022

I guess we could print "unknown" for the full version too.

@mholt mholt removed the under review 🧐 Review is pending before merging label Oct 5, 2022
Copy link
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

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

CI is stuck, so going ahead and merging. Thanks for your contribution @assistcontrol !

GitHub incident: https://www.githubstatus.com/incidents/smn1qtqvbsb6

@mholt mholt merged commit e4fac12 into caddyserver:master Oct 5, 2022
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.

None yet

2 participants