Skip to content

Commit 65be8a5

Browse files
committed
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
1 parent 54d7aad commit 65be8a5

File tree

2 files changed

+17
-84
lines changed

2 files changed

+17
-84
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,20 @@ kubectl apply -f elastic-agent-${ELASTIC_AGENT_MODE}-kubernetes.yaml
103103
```
104104
kubectl -n kube-system get pods -l app=elastic-agent
105105
```
106+
107+
## Updating dependencies/PRs
108+
Even though we prefer `mage` to our automation, we still have some
109+
rules implemented on our `Makefile` as well as CI will use the
110+
`Makefile`. CI will run `make check-ci`, so make sure to run it
111+
locally before submitting any PRs to have a quicker feedback instead
112+
of waiting for a CI failure.
113+
114+
### Generating the `NOTICE.txt` when updating/adding dependencies
115+
To do so, just run `make notice`, this is also part of the `make
116+
check-ci` and is the same check our CI will do.
117+
118+
At some point we will migrate it to mage (see discussion on
119+
https://github.com/elastic/elastic-agent/pull/1108 and on
120+
https://github.com/elastic/elastic-agent/issues/1107). However until
121+
we have the mage automation sorted out, it has been removed to avoid
122+
confusion.

magefile.go

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@ import (
1111
"bytes"
1212
"context"
1313
"fmt"
14-
"io"
1514
"os"
1615
"os/exec"
1716
"path/filepath"
1817
"runtime"
1918
"strconv"
2019
"strings"
21-
"sync"
2220
"time"
2321

2422
"github.com/hashicorp/go-multierror"
@@ -30,8 +28,6 @@ import (
3028

3129
devtools "github.com/elastic/elastic-agent/dev-tools/mage"
3230

33-
devtoolslibs "github.com/elastic/elastic-agent-libs/dev-tools/mage"
34-
3531
// mage:import
3632
"github.com/elastic/elastic-agent/dev-tools/mage/target/common"
3733

@@ -95,77 +91,6 @@ type Demo mg.Namespace
9591
// Dev runs package and build for dev purposes.
9692
type Dev mg.Namespace
9793

98-
// Notice regenerates the NOTICE.txt file.
99-
func Notice() error {
100-
fmt.Println(">> Generating NOTICE")
101-
fmt.Println(">> fmt - go mod tidy")
102-
err := sh.RunV("go", "mod", "tidy", "-v")
103-
if err != nil {
104-
return errors.Wrap(err, "failed running go mod tidy, please fix the issues reported")
105-
}
106-
fmt.Println(">> fmt - go mod download")
107-
err = sh.RunV("go", "mod", "download")
108-
if err != nil {
109-
return errors.Wrap(err, "failed running go mod download, please fix the issues reported")
110-
}
111-
fmt.Println(">> fmt - go list")
112-
str, err := sh.Output("go", "list", "-m", "-json", "all")
113-
if err != nil {
114-
return errors.Wrap(err, "failed running go list, please fix the issues reported")
115-
}
116-
fmt.Println(">> fmt - go run")
117-
goLicenceDetectorCMD := []string{"go",
118-
"run",
119-
"go.elastic.co/go-licence-detector",
120-
"-includeIndirect",
121-
"-rules",
122-
"dev-tools/notice/rules.json",
123-
"-overrides",
124-
"dev-tools/notice/overrides.json",
125-
"-noticeTemplate",
126-
"dev-tools/notice/NOTICE.txt.tmpl",
127-
"-noticeOut",
128-
"NOTICE.txt",
129-
}
130-
printCMD(goLicenceDetectorCMD)
131-
cmd := exec.Command(goLicenceDetectorCMD[0], goLicenceDetectorCMD[1:]...)
132-
stdin, err := cmd.StdinPipe()
133-
if err != nil {
134-
return errors.Wrap(err, "failed running go run, please fix the issues reported")
135-
}
136-
var wg sync.WaitGroup
137-
wg.Add(1)
138-
go func() {
139-
defer stdin.Close()
140-
defer wg.Done()
141-
if _, err := io.WriteString(stdin, str); err != nil {
142-
fmt.Println(err)
143-
}
144-
}()
145-
out, err := cmd.CombinedOutput()
146-
wg.Wait()
147-
if err != nil {
148-
return fmt.Errorf("calling go-licence-detector returned an error: '%w'. Its output is: '%s'", err, string(out))
149-
}
150-
151-
noticeFile, err := os.OpenFile("NOTICE.txt", os.O_APPEND|os.O_WRONLY, 0644)
152-
if err != nil {
153-
return fmt.Errorf("cannot open NOTICE.txt for appending: %w", err)
154-
}
155-
defer noticeFile.Close()
156-
157-
toAppendNotice, err := os.ReadFile(filepath.Join("dev-tools", "notice", "NOTICE.txt.append"))
158-
if err != nil {
159-
return fmt.Errorf("cannot read notice file to be appended: %w", err)
160-
}
161-
162-
if _, err := noticeFile.Write(toAppendNotice); err != nil {
163-
return fmt.Errorf("cannot append data to NOTICE.txt: %w", err)
164-
}
165-
166-
return nil
167-
}
168-
16994
func CheckNoChanges() error {
17095
fmt.Println(">> fmt - go run")
17196
err := sh.RunV("go", "mod", "tidy", "-v")
@@ -975,12 +900,3 @@ func printCMD(cmd []string) {
975900

976901
fmt.Println(buff.String())
977902
}
978-
979-
// Notice generates a NOTICE.txt file for the module.
980-
func NoticeLib() error {
981-
return devtoolslibs.GenerateNotice(
982-
filepath.Join("dev-tools", "notice", "overrides.json"),
983-
filepath.Join("dev-tools", "notice", "rules.json"),
984-
filepath.Join("dev-tools", "notice", "NOTICE.txt.tmpl"),
985-
)
986-
}

0 commit comments

Comments
 (0)