Skip to content

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

Merged
mholt merged 1 commit intocaddyserver:masterfrom
jshenguru:master
Dec 1, 2024
Merged

Extract correct version when using --with flag to replace Caddy core#216
mholt merged 1 commit intocaddyserver:masterfrom
jshenguru:master

Conversation

@jshenguru
Copy link
Copy Markdown
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
Copy Markdown
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
@JasonLovesDoggo
Copy link
Copy Markdown

Could a new release be drafted up that includes these changes?

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.

3 participants