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

Remove mage notice in favour of make notice #1108

Merged
merged 7 commits into from
Sep 13, 2022
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 52 additions & 4 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package main

import (
"bytes"
"context"
"fmt"
"io"
Expand Down Expand Up @@ -111,8 +112,21 @@ func Notice() error {
return errors.Wrap(err, "failed running go list, please fix the issues reported")
}
fmt.Println(">> fmt - go run")
cmd := exec.Command("go", "run", "go.elastic.co/go-licence-detector", "-includeIndirect", "-rules", "dev-tools/notice/rules.json", "-overrides", "dev-tools/notice/overrides.json", "-noticeTemplate", "dev-tools/notice/NOTICE.txt.tmpl",
"-noticeOut", "NOTICE.txt", "-depsOut", "\"\"")
goLicenceDetectorCMD := []string{"go",
"run",
"go.elastic.co/go-licence-detector",
"-includeIndirect",
"-rules",
"dev-tools/notice/rules.json",
"-overrides",
"dev-tools/notice/overrides.json",
"-noticeTemplate",
"dev-tools/notice/NOTICE.txt.tmpl",
"-noticeOut",
"NOTICE.txt",
}
printCMD(goLicenceDetectorCMD)
cmd := exec.Command(goLicenceDetectorCMD[0], goLicenceDetectorCMD[1:]...)
stdin, err := cmd.StdinPipe()
if err != nil {
return errors.Wrap(err, "failed running go run, please fix the issues reported")
Expand All @@ -126,11 +140,27 @@ func Notice() error {
fmt.Println(err)
}
}()
out, err := cmd.CombinedOutput()
wg.Wait()
_, err = cmd.CombinedOutput()
if err != nil {
return errors.Wrap(err, "failed combined output, please fix the issues reported")
return fmt.Errorf("calling go-licence-detector returned an error: '%w'. Its output is: '%s'", err, string(out))
}

noticeFile, err := os.OpenFile("NOTICE.txt", os.O_APPEND|os.O_WRONLY, 0644)
if err != nil {
return fmt.Errorf("cannot open NOTICE.txt for appending: %w", err)
}
defer noticeFile.Close()

toAppendNotice, err := os.ReadFile(filepath.Join("dev-tools", "notice", "NOTICE.txt.append"))
if err != nil {
return fmt.Errorf("cannot read notice file to be appended: %w", err)
}

if _, err := noticeFile.Write(toAppendNotice); err != nil {
return fmt.Errorf("cannot append data to NOTICE.txt: %w", err)
}

return nil
}

Expand Down Expand Up @@ -925,3 +955,21 @@ func majorMinor() string {
}
return ""
}

// printCMD prints the command in the same format than when
// using the functions from the `sh` package. It also respects
// the mage verbose flag
func printCMD(cmd []string) {
if !mg.Verbose() {
return
}

buff := &bytes.Buffer{}

fmt.Fprintf(buff, "exec: %s", cmd[0])
for _, arg := range cmd[1:] {
fmt.Fprintf(buff, " %q", arg)
}

fmt.Println(buff.String())
}