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

Extract correct version when using --with flag to replace Caddy core #216

Merged
merged 1 commit into from
Dec 1, 2024

Conversation

jshenguru
Copy link
Contributor

The following build failed on Windows with Invalid Semantic Version error.
xcaddy build v2.8.4 --with github.com/caddyserver/caddy/v2=c:\Users\test\caddy

The bug is among lines 97 - 110 in the builder.go.

	// generating windows resources for embedding
	if b.OS == "windows" {
		// get version string, we need to parse the output to get the exact version instead tag, branch or commit
		cmd := buildEnv.newGoBuildCommand(ctx, "list", "-m", buildEnv.caddyModulePath)
		var buffer bytes.Buffer
		cmd.Stdout = &buffer
		err = buildEnv.runCommand(ctx, cmd)
		if err != nil {
			return err
		}

		// output looks like: github.com/caddyserver/caddy/v2 v2.7.6
		version := strings.TrimSpace(strings.TrimPrefix(buffer.String(), buildEnv.caddyModulePath))

		err = utils.WindowsResource(version, outputFile, buildEnv.tempFolder)

Detailed explanation:
The go list -m command in this case would return github.com/caddyserver/caddy/v2 v2.8.4 => c:\Users\test\caddy. The value of the version would end up being v2.8.4 => c:\Users\test\Documents\EyeSCADA-v4\_esRouter\caddy-2.8.4. Therefore, the utils.WIndows Resource() call would fail with 'Invalid Semantic Version` error.

A quick fix would be adding the following between version := ... and err = util.WIndowsResource(...):

index := strings.Index(version, "=>")
if index != -1 {
    version = strings.TrimSpace(version[:index])
}

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.

Cool, thanks for the patch. LGTM

@mholt mholt merged commit c0aca26 into caddyserver:master Dec 1, 2024
8 checks passed
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