Skip to content

Commit

Permalink
Remove mage notice in favour of make notice
Browse files Browse the repository at this point in the history
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
  • Loading branch information
belimawr committed Sep 9, 2022
1 parent 54d7aad commit 65be8a5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 84 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
84 changes: 0 additions & 84 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ import (
"bytes"
"context"
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
"runtime"
"strconv"
"strings"
"sync"
"time"

"github.com/hashicorp/go-multierror"
Expand All @@ -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"

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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"),
)
}

0 comments on commit 65be8a5

Please sign in to comment.