diff --git a/cmd/authelia-scripts/cmd/build.go b/cmd/authelia-scripts/cmd/build.go index bddf4801b..b6fb1ef79 100644 --- a/cmd/authelia-scripts/cmd/build.go +++ b/cmd/authelia-scripts/cmd/build.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "io" "os" "os/exec" "path/filepath" @@ -240,12 +241,41 @@ func buildCmdPrint(cmd *exec.Cmd) { b.WriteString(fmt.Sprintf("cd %s\n", cmd.Dir)) } - if len(cmd.Env) != 0 { - b.WriteString(strings.Join(cmd.Env, " ")) - b.WriteString(" ") - } - - b.WriteString(cmd.String()) + buildCmdWriteCmd(b, cmd) fmt.Println(b.String()) } + +func buildCmdWriteCmd(wr io.StringWriter, cmd *exec.Cmd) { + buildCmdWriteEnv(wr, cmd) + + _, _ = wr.WriteString(cmd.Path) + + for _, arg := range cmd.Args[1:] { + _, _ = wr.WriteString(" ") + if strings.Contains(arg, " ") { + _, _ = wr.WriteString(fmt.Sprintf(`"%s"`, arg)) + } else { + _, _ = wr.WriteString(arg) + } + } +} + +func buildCmdWriteEnv(wr io.StringWriter, cmd *exec.Cmd) { + n := len(cmd.Env) + + if n == 0 { + return + } + + envs := make([]string, n) + + for i, env := range cmd.Env { + parts := strings.SplitN(env, "=", 2) + + envs[i] = fmt.Sprintf(`%s="%s"`, parts[0], parts[1]) + } + + _, _ = wr.WriteString(strings.Join(envs, " ")) + _, _ = wr.WriteString(" ") +} diff --git a/docs/content/en/contributing/development/build-and-test.md b/docs/content/en/contributing/development/build-and-test.md index 9436ebdfe..64e3af591 100644 --- a/docs/content/en/contributing/development/build-and-test.md +++ b/docs/content/en/contributing/development/build-and-test.md @@ -144,8 +144,8 @@ go build -ldflags "-linkmode=external -s -w" -trimpath -buildmode=pie -o autheli *__Please Note:__ The reproducibility instructions only apply for v4.38.0 or above. Users interested in reproducibility of previous versions will have to carefully modify the linker flags to match the values outputted from the `authelia build-info` command. In particular the Build Date was set as the actual time previously rather than the -commit time. If you have trouble reproducing a build please let us know so we can figure it out, assist you, and -document it.* +commit time. In addition to this the ability to print the commands did not exist until just before this tag. If you have +trouble reproducing a build please let us know so we can figure it out, assist you, and document it.* Authelia allows production of reproducible builds that were built using our pipeline. The only variables injected into a build are from commit information other than the exceptions listed in this section. This means that we can provide the diff --git a/internal/suites/suite_cli_test.go b/internal/suites/suite_cli_test.go index 1efcb88af..235c75cb8 100644 --- a/internal/suites/suite_cli_test.go +++ b/internal/suites/suite_cli_test.go @@ -51,7 +51,7 @@ func (s *CLISuite) TestShouldPrintBuildInformation() { output, err := s.Exec("authelia-backend", []string{"authelia", "build-info"}) s.Assert().NoError(err) - r := regexp.MustCompile(`^Last Tag: v\d+\.\d+\.\d+\nState: (tagged|untagged) (clean|dirty)\nBranch: [^\s\n]+\nCommit: [0-9a-f]{40}\nCommit Date: (Sun|Mon|Tue|Wed|Thu|Fri|Sat), \d{2} (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \d{4} \d{2}:\d{2}:\d{2} \+0000\nBuild Number: \d+\nBuild OS: (linux|darwin|windows|freebsd)\nBuild Arch: (amd64|arm|arm64)\nBuild Go Version: go\d+\.\d+(\.\d+)?\nExtra:`) + r := regexp.MustCompile(`^Last Tag: v\d+\.\d+\.\d+\nState: (tagged|untagged) (clean|dirty)\nBranch: [^\s\n]+\nCommit: [0-9a-f]{40}\nCommit Date: (Sun|Mon|Tue|Wed|Thu|Fri|Sat), \d{2} (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \d{4} \d{2}:\d{2}:\d{2} UTC\nBuild Number: \d+\nBuild OS: (linux|darwin|windows|freebsd)\nBuild Arch: (amd64|arm|arm64)\nBuild Go Version: go\d+\.\d+(\.\d+)?\nExtra:`) s.Assert().Regexp(r, output) }