From 65be8a5fb77835deec4c76d28fdeaf2b36cdbd37 Mon Sep 17 00:00:00 2001 From: Tiago Queiroz Date: Fri, 9 Sep 2022 17:51:03 +0200 Subject: [PATCH] Remove mage notice in favour of make notice The current implementation of mage notice is not working because it was never finalised, the fact that it and `make notice` exist only generates confusion. This commit removes the `mage notice` and documents that `make notice` should be used insted for the time being. In the long run we want to use the implementation on `elastic-agent-libs`, however it is not woking at the monent. Closes #1107 --- README.md | 17 +++++++++++ magefile.go | 84 ----------------------------------------------------- 2 files changed, 17 insertions(+), 84 deletions(-) diff --git a/README.md b/README.md index faecad7b70..b1f581b38b 100644 --- a/README.md +++ b/README.md @@ -103,3 +103,20 @@ kubectl apply -f elastic-agent-${ELASTIC_AGENT_MODE}-kubernetes.yaml ``` kubectl -n kube-system get pods -l app=elastic-agent ``` + +## Updating dependencies/PRs +Even though we prefer `mage` to our automation, we still have some +rules implemented on our `Makefile` as well as CI will use the +`Makefile`. CI will run `make check-ci`, so make sure to run it +locally before submitting any PRs to have a quicker feedback instead +of waiting for a CI failure. + +### Generating the `NOTICE.txt` when updating/adding dependencies +To do so, just run `make notice`, this is also part of the `make +check-ci` and is the same check our CI will do. + +At some point we will migrate it to mage (see discussion on +https://github.com/elastic/elastic-agent/pull/1108 and on +https://github.com/elastic/elastic-agent/issues/1107). However until +we have the mage automation sorted out, it has been removed to avoid +confusion. diff --git a/magefile.go b/magefile.go index 8d4c53242c..dfe6d383f6 100644 --- a/magefile.go +++ b/magefile.go @@ -11,14 +11,12 @@ import ( "bytes" "context" "fmt" - "io" "os" "os/exec" "path/filepath" "runtime" "strconv" "strings" - "sync" "time" "github.com/hashicorp/go-multierror" @@ -30,8 +28,6 @@ import ( devtools "github.com/elastic/elastic-agent/dev-tools/mage" - devtoolslibs "github.com/elastic/elastic-agent-libs/dev-tools/mage" - // mage:import "github.com/elastic/elastic-agent/dev-tools/mage/target/common" @@ -95,77 +91,6 @@ type Demo mg.Namespace // Dev runs package and build for dev purposes. type Dev mg.Namespace -// Notice regenerates the NOTICE.txt file. -func Notice() error { - fmt.Println(">> Generating NOTICE") - fmt.Println(">> fmt - go mod tidy") - err := sh.RunV("go", "mod", "tidy", "-v") - if err != nil { - return errors.Wrap(err, "failed running go mod tidy, please fix the issues reported") - } - fmt.Println(">> fmt - go mod download") - err = sh.RunV("go", "mod", "download") - if err != nil { - return errors.Wrap(err, "failed running go mod download, please fix the issues reported") - } - fmt.Println(">> fmt - go list") - str, err := sh.Output("go", "list", "-m", "-json", "all") - if err != nil { - return errors.Wrap(err, "failed running go list, please fix the issues reported") - } - fmt.Println(">> fmt - go run") - 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") - } - var wg sync.WaitGroup - wg.Add(1) - go func() { - defer stdin.Close() - defer wg.Done() - if _, err := io.WriteString(stdin, str); err != nil { - fmt.Println(err) - } - }() - out, err := cmd.CombinedOutput() - wg.Wait() - if err != nil { - 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 -} - func CheckNoChanges() error { fmt.Println(">> fmt - go run") err := sh.RunV("go", "mod", "tidy", "-v") @@ -975,12 +900,3 @@ func printCMD(cmd []string) { fmt.Println(buff.String()) } - -// Notice generates a NOTICE.txt file for the module. -func NoticeLib() error { - return devtoolslibs.GenerateNotice( - filepath.Join("dev-tools", "notice", "overrides.json"), - filepath.Join("dev-tools", "notice", "rules.json"), - filepath.Join("dev-tools", "notice", "NOTICE.txt.tmpl"), - ) -}