From 66296afd030f710f82451c44aa76468ac29300fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Jochum?= Date: Wed, 4 Sep 2024 04:20:41 +0200 Subject: [PATCH] feat(CI): Use dagger instead of custom scripts. --- .github/workflows/main.yaml | 50 ++----- .github/workflows/pr.yaml | 50 ++----- README.md | 17 ++- Taskfile.yml | 22 +++ dagger.json | 6 + dagger/.gitattributes | 4 + dagger/.gitignore | 4 + dagger/go.mod | 50 +++++++ dagger/go.sum | 92 ++++++++++++ dagger/main.go | 270 ++++++++++++++++++++++++++++++++++ scripts/deps/polaris.sh | 54 ------- scripts/fmt.sh | 14 -- scripts/lib/run_bench.sh | 42 ------ scripts/lib/run_lint.sh | 26 ---- scripts/lib/run_test.sh | 41 ------ scripts/lib/util.sh | 83 ----------- scripts/mod-dropreplace.sh | 18 --- scripts/mod-replace.sh | 30 ---- scripts/release.sh | 127 ---------------- scripts/template/changelog.md | 1 - scripts/test.sh | 237 ----------------------------- 21 files changed, 487 insertions(+), 751 deletions(-) create mode 100644 Taskfile.yml create mode 100644 dagger.json create mode 100644 dagger/.gitattributes create mode 100644 dagger/.gitignore create mode 100644 dagger/go.mod create mode 100644 dagger/go.sum create mode 100644 dagger/main.go delete mode 100644 scripts/deps/polaris.sh delete mode 100755 scripts/fmt.sh delete mode 100755 scripts/lib/run_bench.sh delete mode 100644 scripts/lib/run_lint.sh delete mode 100755 scripts/lib/run_test.sh delete mode 100755 scripts/lib/util.sh delete mode 100755 scripts/mod-dropreplace.sh delete mode 100755 scripts/mod-replace.sh delete mode 100755 scripts/release.sh delete mode 100644 scripts/template/changelog.md delete mode 100755 scripts/test.sh diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index f102b631..3002e578 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -5,51 +5,31 @@ on: - main permissions: read-all jobs: - golangci: + lint: name: Lint runs-on: [self-hosted, linux, x64] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 - - uses: actions/setup-go@v3 + - name: Lint files + uses: dagger/dagger-for-github@v6 with: - go-version: "1.23" - check-latest: true - - name: Run Linters - run: ./scripts/test.sh lint all - env: - PROCS: 1 - GOMAXPROGS: 1 + version: "latest" + verb: call + args: lint --root=. + cloud-token: ${{ secrets.DAGGER_CLOUD_TOKEN }} test: name: Unit Tests runs-on: [self-hosted, linux, x64] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 - - uses: actions/setup-go@v3 + - name: Lint files + uses: dagger/dagger-for-github@v6 with: - go-version: "1.23" - check-latest: true - - name: Run Unit Tests - run: ./scripts/test.sh test all - env: - PROCS: 1 - GOMAXPROGS: 1 - summary: - name: Summary - runs-on: [self-hosted, linux, x64] - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - uses: actions/setup-go@v3 - with: - go-version: "1.23" - check-latest: true - - name: Create Summary - run: ./scripts/test.sh summary all - env: - PROCS: 1 - GOMAXPROGS: 1 + version: "latest" + verb: call + args: test --root=. + cloud-token: ${{ secrets.DAGGER_CLOUD_TOKEN }} diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 3336e2a0..1d567f0d 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -3,51 +3,31 @@ on: pull_request: {} permissions: read-all jobs: - golangci: + lint: name: Lint runs-on: [self-hosted, linux, x64] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 - - uses: actions/setup-go@v3 + - name: Lint files + uses: dagger/dagger-for-github@v6 with: - go-version: "1.23" - check-latest: true - - name: Run Linters - run: ./scripts/test.sh lint changes - env: - PROCS: 1 - GOMAXPROGS: 1 + version: "latest" + verb: call + args: lint --root=. + cloud-token: ${{ secrets.DAGGER_CLOUD_TOKEN }} test: name: Unit Tests runs-on: [self-hosted, linux, x64] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 - - uses: actions/setup-go@v3 + - name: Lint files + uses: dagger/dagger-for-github@v6 with: - go-version: "1.23" - check-latest: true - - name: Run Unit Tests - run: ./scripts/test.sh test changes - env: - PROCS: 1 - GOMAXPROGS: 1 - summary: - name: Summary - runs-on: [self-hosted, linux, x64] - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - uses: actions/setup-go@v3 - with: - go-version: "1.23" - check-latest: true - - name: Create Summary - run: ./scripts/test.sh summary changes - env: - PROCS: 1 - GOMAXPROGS: 1 + version: "latest" + verb: call + args: test --root=. + cloud-token: ${{ secrets.DAGGER_CLOUD_TOKEN }} diff --git a/README.md b/README.md index 83a2a97e..247ee315 100644 --- a/README.md +++ b/README.md @@ -16,16 +16,17 @@ We do not accept commit's with a "replace" line in a go.mod. ### Run the tests -- all: +Install [dagger](https://docs.dagger.io/quickstart/cli) - ```bash - ./scripts/test.sh test all - ``` +```sh +dagger call test --root=. +``` -- or just one: - ```bash - ./scripts/test.sh test client/orb_transport/grpc - ``` +### Check linting + +```sh +dagger call lint --root=. +``` ### Quirks diff --git a/Taskfile.yml b/Taskfile.yml new file mode 100644 index 00000000..e68a94b2 --- /dev/null +++ b/Taskfile.yml @@ -0,0 +1,22 @@ +version: '3' + +tasks: + lint: + desc: Run "golangci-lint" in all packages + cmds: + - cmd: dagger call lint --root=. + + mod-tidy: + desc: Run "go mod tidy" in all packages + cmds: + - cmd: dagger call tidy --root=. source export --path=. + + mod-update: + desc: Run "go get -u -t ./..." in all packages + cmds: + - cmd: dagger call update --root=. source export --path=. + + test: + desc: Run "go test ./..." in all packages + cmds: + - cmd: dagger call test --root=. \ No newline at end of file diff --git a/dagger.json b/dagger.json new file mode 100644 index 00000000..4526aab8 --- /dev/null +++ b/dagger.json @@ -0,0 +1,6 @@ +{ + "name": "go-orb", + "sdk": "go", + "source": "dagger", + "engineVersion": "v0.12.6" +} diff --git a/dagger/.gitattributes b/dagger/.gitattributes new file mode 100644 index 00000000..3a454933 --- /dev/null +++ b/dagger/.gitattributes @@ -0,0 +1,4 @@ +/dagger.gen.go linguist-generated +/internal/dagger/** linguist-generated +/internal/querybuilder/** linguist-generated +/internal/telemetry/** linguist-generated diff --git a/dagger/.gitignore b/dagger/.gitignore new file mode 100644 index 00000000..7ebabcc1 --- /dev/null +++ b/dagger/.gitignore @@ -0,0 +1,4 @@ +/dagger.gen.go +/internal/dagger +/internal/querybuilder +/internal/telemetry diff --git a/dagger/go.mod b/dagger/go.mod new file mode 100644 index 00000000..b93402de --- /dev/null +++ b/dagger/go.mod @@ -0,0 +1,50 @@ +module dagger/go-orb + +go 1.23.0 + +require ( + github.com/99designs/gqlgen v0.17.49 + github.com/Khan/genqlient v0.7.0 + github.com/hashicorp/go-multierror v1.1.1 + github.com/vektah/gqlparser/v2 v2.5.16 + go.opentelemetry.io/otel v1.29.0 + go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.5.0 + go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.5.0 + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.29.0 + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.29.0 + go.opentelemetry.io/otel/log v0.5.0 + go.opentelemetry.io/otel/sdk v1.29.0 + go.opentelemetry.io/otel/sdk/log v0.5.0 + go.opentelemetry.io/otel/trace v1.29.0 + go.opentelemetry.io/proto/otlp v1.3.1 + golang.org/x/exp v0.0.0-20240823005443-9b4947da3948 + golang.org/x/sync v0.8.0 + google.golang.org/grpc v1.66.0 +) + +require ( + github.com/cenkalti/backoff/v4 v4.3.0 // indirect + github.com/go-logr/logr v1.4.2 // indirect + github.com/go-logr/stdr v1.2.2 // indirect + github.com/google/uuid v1.6.0 // indirect + github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect + github.com/hashicorp/errwrap v1.1.0 // indirect + github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect + github.com/sosodev/duration v1.3.1 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.29.0 // indirect + go.opentelemetry.io/otel/metric v1.29.0 // indirect + golang.org/x/net v0.28.0 // indirect + golang.org/x/sys v0.24.0 // indirect + golang.org/x/text v0.17.0 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20240827150818-7e3bb234dfed // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240827150818-7e3bb234dfed // indirect + google.golang.org/protobuf v1.34.2 // indirect +) + +replace go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc => go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.0.0-20240518090000-14441aefdf88 + +replace go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp => go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.3.0 + +replace go.opentelemetry.io/otel/log => go.opentelemetry.io/otel/log v0.3.0 + +replace go.opentelemetry.io/otel/sdk/log => go.opentelemetry.io/otel/sdk/log v0.3.0 diff --git a/dagger/go.sum b/dagger/go.sum new file mode 100644 index 00000000..cf3793bc --- /dev/null +++ b/dagger/go.sum @@ -0,0 +1,92 @@ +github.com/99designs/gqlgen v0.17.49 h1:b3hNGexHd33fBSAd4NDT/c3NCcQzcAVkknhN9ym36YQ= +github.com/99designs/gqlgen v0.17.49/go.mod h1:tC8YFVZMed81x7UJ7ORUwXF4Kn6SXuucFqQBhN8+BU0= +github.com/Khan/genqlient v0.7.0 h1:GZ1meyRnzcDTK48EjqB8t3bcfYvHArCUUvgOwpz1D4w= +github.com/Khan/genqlient v0.7.0/go.mod h1:HNyy3wZvuYwmW3Y7mkoQLZsa/R5n5yIRajS1kPBvSFM= +github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ= +github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= +github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= +github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= +github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 h1:asbCHRVmodnJTuQ3qamDwqVOIjwqUPTYmYuemVOx+Ys= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0/go.mod h1:ggCgvZ2r7uOoQjOyu2Y1NhHmEPPzzuhWgcza5M1Ji1I= +github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= +github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= +github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8= +github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4= +github.com/sosodev/duration v1.3.1 h1:qtHBDMQ6lvMQsL15g4aopM4HEfOaYuhWBw3NPTtlqq4= +github.com/sosodev/duration v1.3.1/go.mod h1:RQIBBX0+fMLc/D9+Jb/fwvVmo0eZvDDEERAikUR6SDg= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/vektah/gqlparser/v2 v2.5.16 h1:1gcmLTvs3JLKXckwCwlUagVn/IlV2bwqle0vJ0vy5p8= +github.com/vektah/gqlparser/v2 v2.5.16/go.mod h1:1lz1OeCqgQbQepsGxPVywrjdBHW2T08PUS3pJqepRww= +go.opentelemetry.io/otel v1.29.0 h1:PdomN/Al4q/lN6iBJEN3AwPvUiHPMlt93c8bqTG5Llw= +go.opentelemetry.io/otel v1.29.0/go.mod h1:N/WtXPs1CNCUEx+Agz5uouwCba+i+bJGFicT8SR4NP8= +go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.0.0-20240518090000-14441aefdf88 h1:oM0GTNKGlc5qHctWeIGTVyda4iFFalOzMZ3Ehj5rwB4= +go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.0.0-20240518090000-14441aefdf88/go.mod h1:JGG8ebaMO5nXOPnvKEl+DiA4MGwFjCbjsxT1WHIEBPY= +go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.3.0 h1:ccBrA8nCY5mM0y5uO7FT0ze4S0TuFcWdDB2FxGMTjkI= +go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.3.0/go.mod h1:/9pb6634zi2Lk8LYg9Q0X8Ar6jka4dkFOylBLbVQPCE= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.29.0 h1:dIIDULZJpgdiHz5tXrTgKIMLkus6jEFa7x5SOKcyR7E= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.29.0/go.mod h1:jlRVBe7+Z1wyxFSUs48L6OBQZ5JwH2Hg/Vbl+t9rAgI= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.29.0 h1:nSiV3s7wiCam610XcLbYOmMfJxB9gO4uK3Xgv5gmTgg= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.29.0/go.mod h1:hKn/e/Nmd19/x1gvIHwtOwVWM+VhuITSWip3JUDghj0= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.29.0 h1:JAv0Jwtl01UFiyWZEMiJZBiTlv5A50zNs8lsthXqIio= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.29.0/go.mod h1:QNKLmUEAq2QUbPQUfvw4fmv0bgbK7UlOSFCnXyfvSNc= +go.opentelemetry.io/otel/log v0.3.0 h1:kJRFkpUFYtny37NQzL386WbznUByZx186DpEMKhEGZs= +go.opentelemetry.io/otel/log v0.3.0/go.mod h1:ziCwqZr9soYDwGNbIL+6kAvQC+ANvjgG367HVcyR/ys= +go.opentelemetry.io/otel/metric v1.29.0 h1:vPf/HFWTNkPu1aYeIsc98l4ktOQaL6LeSoeV2g+8YLc= +go.opentelemetry.io/otel/metric v1.29.0/go.mod h1:auu/QWieFVWx+DmQOUMgj0F8LHWdgalxXqvp7BII/W8= +go.opentelemetry.io/otel/sdk v1.29.0 h1:vkqKjk7gwhS8VaWb0POZKmIEDimRCMsopNYnriHyryo= +go.opentelemetry.io/otel/sdk v1.29.0/go.mod h1:pM8Dx5WKnvxLCb+8lG1PRNIDxu9g9b9g59Qr7hfAAok= +go.opentelemetry.io/otel/sdk/log v0.3.0 h1:GEjJ8iftz2l+XO1GF2856r7yYVh74URiF9JMcAacr5U= +go.opentelemetry.io/otel/sdk/log v0.3.0/go.mod h1:BwCxtmux6ACLuys1wlbc0+vGBd+xytjmjajwqqIul2g= +go.opentelemetry.io/otel/trace v1.29.0 h1:J/8ZNK4XgR7a21DZUAsbF8pZ5Jcw1VhACmnYt39JTi4= +go.opentelemetry.io/otel/trace v1.29.0/go.mod h1:eHl3w0sp3paPkYstJOmAimxhiFXPg+MMTlEh3nsQgWQ= +go.opentelemetry.io/proto/otlp v1.3.1 h1:TrMUixzpM0yuc/znrFTP9MMRh8trP93mkCiDVeXrui0= +go.opentelemetry.io/proto/otlp v1.3.1/go.mod h1:0X1WI4de4ZsLrrJNLAQbFeLCm3T7yBkR0XqQ7niQU+8= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= +golang.org/x/exp v0.0.0-20240823005443-9b4947da3948 h1:kx6Ds3MlpiUHKj7syVnbp57++8WpuKPcR5yjLBjvLEA= +golang.org/x/exp v0.0.0-20240823005443-9b4947da3948/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ= +golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE= +golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg= +golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= +golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= +golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +google.golang.org/genproto/googleapis/api v0.0.0-20240827150818-7e3bb234dfed h1:3RgNmBoI9MZhsj3QxC+AP/qQhNwpCLOvYDYYsFrhFt0= +google.golang.org/genproto/googleapis/api v0.0.0-20240827150818-7e3bb234dfed/go.mod h1:OCdP9MfskevB/rbYvHTsXTtKC+3bHWajPdoKgjcYkfo= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240827150818-7e3bb234dfed h1:J6izYgfBXAI3xTKLgxzTmUltdYaLsuBxFCgDHWJ/eXg= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240827150818-7e3bb234dfed/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU= +google.golang.org/grpc v1.66.0 h1:DibZuoBznOxbDQxRINckZcUvnCEvrW9pcWIE2yF9r1c= +google.golang.org/grpc v1.66.0/go.mod h1:s3/l6xSSCURdVfAnL+TqCNMyTDAGN6+lZeVxnZR128Y= +google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= +google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/dagger/main.go b/dagger/main.go new file mode 100644 index 00000000..27b491b9 --- /dev/null +++ b/dagger/main.go @@ -0,0 +1,270 @@ +// A generated module for GoOrb functions +// +// This module has been generated via dagger init and serves as a reference to +// basic module structure as you get started with Dagger. +// +// Two functions have been pre-created. You can modify, delete, or add to them, +// as needed. They demonstrate usage of arguments and return types using simple +// echo and grep commands. The functions can be called from the dagger CLI or +// from one of the SDKs. +// +// The first line in this comment block is a short description line and the +// rest is a long description with more detail on the module's purpose or usage, +// if appropriate. All modules should have a short description. + +package main + +import ( + "context" + "dagger/go-orb/internal/dagger" + "runtime" + "strings" + "sync" + + "github.com/hashicorp/go-multierror" +) + +type WorkerResult struct { + Module string + Logs string + Err error + Source *dagger.Directory +} + +type AllResult struct { + Logs []string + Source *dagger.Directory +} + +type GoOrb struct{} + +func (m *GoOrb) runAll(ctx context.Context, root *dagger.Directory, worker func(ctx context.Context, wg *sync.WaitGroup, inpupt <-chan string, res chan<- *WorkerResult, root *dagger.Directory)) (*AllResult, error) { + mods, err := m.Modules(ctx, root) + if err != nil { + return nil, err + } + + input := make(chan string, len(mods)) + res := make(chan *WorkerResult, len(mods)) + + var wg sync.WaitGroup + + // Start workers + for i := 0; i < runtime.NumCPU()/2; i++ { + wg.Add(1) + go worker(ctx, &wg, input, res, root) + } + + // Add jobs + for _, mod := range mods { + if len(mod) > 0 { + input <- mod + } + } + close(input) + + // Wait for all workers to complete + wg.Wait() + close(res) + + // Aggregate results + result := &AllResult{Logs: []string{}, Source: dag.Directory()} + for r := range res { + if r.Err != nil { + err = multierror.Append(err, r.Err) + } + + if r.Source != nil { + result.Source = result.Source.WithDirectory(r.Module, r.Source) + } + + if len(r.Logs) > 0 { + result.Logs = append(result.Logs, "## "+r.Module+"\n"+r.Logs+"\n\n") + } + } + + return result, err +} + +// Returns all modules in `root` +func (m *GoOrb) Modules(ctx context.Context, root *dagger.Directory) ([]string, error) { + mods, err := root.Glob(ctx, "**/go.mod") + if err != nil { + return nil, err + } + + for i, mod := range mods { + if strings.HasPrefix(mod, "dagger") { + mods[i] = "" + continue + } + + if len(mod) > 7 { + mods[i] = mod[0 : len(mod)-7] + } else { + mods[i] = "." + } + } + + return mods, err +} + +// Lints all modules starting from `root` with golangci-lint +func (m *GoOrb) Lint(ctx context.Context, root *dagger.Directory) (*AllResult, error) { + lintWorker := func(ctx context.Context, wg *sync.WaitGroup, input <-chan string, res chan<- *WorkerResult, root *dagger.Directory) { + defer wg.Done() + for dir := range input { + select { + case <-ctx.Done(): + return + default: + } + + out, err := dag.Container().From("golangci/golangci-lint"). + WithMountedCache("/go/pkg/mod", + dag.CacheVolume("go-mod"), + dagger.ContainerWithMountedCacheOpts{ + Source: dag.Directory().WithNewDirectory("~/go/pkg/mod"), + Sharing: dagger.CacheSharingMode("SHARED"), + }, + ). + WithMountedCache("/root/.cache/go-build", + dag.CacheVolume("go-build"), + dagger.ContainerWithMountedCacheOpts{ + Source: dag.Directory().WithNewDirectory("~/.cache/go-build"), + Sharing: dagger.CacheSharingMode("SHARED"), + }, + ). + WithMountedCache("/root/.cache/golangci-lint", dag.CacheVolume("golangci-lint")). + WithDirectory("/work/src", root.Directory(dir)). + WithWorkdir("/work/src"). + WithExec([]string{"golangci-lint", "run"}). + Stdout(ctx) + + res <- &WorkerResult{Module: dir, Logs: out, Err: err} + } + } + + return m.runAll(ctx, root, lintWorker) +} + +func (m *GoOrb) goContainer(root *dagger.Directory, dir string) *dagger.Container { + return dag.Container().From("golang:1.23"). + WithMountedCache("/go/pkg/mod", + dag.CacheVolume("go-mod"), + dagger.ContainerWithMountedCacheOpts{ + Source: dag.Directory().WithNewDirectory("~/go/pkg/mod"), + Sharing: dagger.CacheSharingMode("SHARED"), + }, + ). + WithMountedCache("/root/.cache/go-build", + dag.CacheVolume("go-build"), + dagger.ContainerWithMountedCacheOpts{ + Source: dag.Directory().WithNewDirectory("~/.cache/go-build"), + Sharing: dagger.CacheSharingMode("SHARED"), + }, + ). + WithDirectory("/work/src", root.Directory(dir)). + WithWorkdir("/work/src") +} + +// Tests all modules starting from `root` with `go test ./... -v -race -cover` +func (m *GoOrb) Test(ctx context.Context, root *dagger.Directory) (*AllResult, error) { + testWorker := func(ctx context.Context, wg *sync.WaitGroup, input <-chan string, res chan<- *WorkerResult, root *dagger.Directory) { + defer wg.Done() + for dir := range input { + select { + case <-ctx.Done(): + return + default: + } + + c := m.goContainer(root, dir). + WithExec([]string{"apt-get", "-qy", "update"}). + WithExec([]string{"apt-get", "-qy", "install", "unzip"}). + WithExec([]string{"bash", "-c", "test -f ./scripts/pre_test.sh && ./scripts/pre_test.sh || exit 0"}). + WithExec([]string{"go", "mod", "download"}). + WithExec([]string{"go", "test", "./...", "-v", "-race", "-cover"}) + + stdout, err := c.Stdout(ctx) + if err != nil { + res <- &WorkerResult{Module: dir, Err: err} + continue + } + + stderr, err := c.Stderr(ctx) + if err != nil { + res <- &WorkerResult{Module: dir, Err: err} + continue + } + + res <- &WorkerResult{Module: dir, Logs: stdout + stderr, Err: err} + } + } + + return m.runAll(ctx, root, testWorker) +} + +// Runs `go mod tidy -go=1.23` in all modules starting with `root` +func (m *GoOrb) Tidy(ctx context.Context, root *dagger.Directory) (*AllResult, error) { + tidyWorker := func(ctx context.Context, wg *sync.WaitGroup, input <-chan string, res chan<- *WorkerResult, root *dagger.Directory) { + defer wg.Done() + for dir := range input { + select { + case <-ctx.Done(): + return + default: + } + + c := m.goContainer(root, dir). + WithExec([]string{"go", "mod", "tidy", "-go=1.23"}) + stdout, err := c.Stdout(ctx) + if err != nil { + res <- &WorkerResult{Module: dir, Source: c.Directory("/work/src"), Err: err} + continue + } + + stderr, err := c.Stderr(ctx) + if err != nil { + res <- &WorkerResult{Module: dir, Source: c.Directory("/work/src"), Err: err} + continue + } + + res <- &WorkerResult{Module: dir, Logs: stdout + stderr, Source: c.Directory("/work/src"), Err: err} + } + } + + return m.runAll(ctx, root, tidyWorker) +} + +// Runs `go get -u -t ./...` in all modules starting with `root` +func (m *GoOrb) Update(ctx context.Context, root *dagger.Directory) (*AllResult, error) { + updateWorker := func(ctx context.Context, wg *sync.WaitGroup, input <-chan string, res chan<- *WorkerResult, root *dagger.Directory) { + defer wg.Done() + for dir := range input { + select { + case <-ctx.Done(): + return + default: + } + + c := m.goContainer(root, dir). + WithExec([]string{"go", "get", "-u", "-t", "./..."}) + stdout, err := c.Stdout(ctx) + if err != nil { + res <- &WorkerResult{Module: dir, Source: c.Directory("/work/src"), Err: err} + continue + } + + stderr, err := c.Stderr(ctx) + if err != nil { + res <- &WorkerResult{Module: dir, Source: c.Directory("/work/src"), Err: err} + continue + } + + res <- &WorkerResult{Module: dir, Logs: stdout + stderr, Source: c.Directory("/work/src"), Err: err} + } + } + + return m.runAll(ctx, root, updateWorker) +} diff --git a/scripts/deps/polaris.sh b/scripts/deps/polaris.sh deleted file mode 100644 index 9735ed91..00000000 --- a/scripts/deps/polaris.sh +++ /dev/null @@ -1,54 +0,0 @@ -#!/bin/bash - -OS="linux" -ARCH="amd64" -ORG="polarismesh" -REPO="polaris" -PORT="8090" - -echo "Downloading Polaris" - -# Find latest release -package_url=$(curl -s "https://api.github.com/repos/${ORG}/${REPO}/releases/latest" | - grep "https://github.com/polarismesh/polaris/releases/download" | grep "standalone" | grep "${OS}" | grep "${ARCH}" | - cut -d : -f 2,3 | - tr -d '\"[:space:]') - -echo "Downloading from '${package_url}'" - -# Downlaod ladtest release -wget -q "${package_url}" - -# Unzip package -unzip -o "*.linux.amd64.zip" - -package_name=$(find . -maxdepth 1 -name "polaris*" -type d) -if [[ ! -d ${package_name} ]]; then - echo "${package_name} doesn't exist" - exit 1 -fi - -# Change dir to polaris dir -pushd "${package_name}" || exit 1 - -# Run install script -echo "Running install script" -bash install.sh - -# Give it some safety margin to startup -sleep 5 - -# Check if port open -if ! nc -z "127.0.0.1" "${PORT}"; then - echo "Failed to find a service running on ${PORT}" - - # Echo netstat - netstat -tulpn | grep -i polaris -fi - -popd || exit 1 - -# Export Address -export POLARIS_ADDR="127.0.0.1:8091" - -printf "\nPolaris installed successfully on ${POLARIS_ADDR}\n" diff --git a/scripts/fmt.sh b/scripts/fmt.sh deleted file mode 100755 index 187bac6a..00000000 --- a/scripts/fmt.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash -ex - -version=$1 - -if [[ ${version} == "" ]]; then - version='*' -fi - -for d in $(find "${version}" -name 'go.mod'); do - pushd $(dirname "${d}") - go fmt - go mod tidy - popd -done diff --git a/scripts/lib/run_bench.sh b/scripts/lib/run_bench.sh deleted file mode 100755 index 9039f550..00000000 --- a/scripts/lib/run_bench.sh +++ /dev/null @@ -1,42 +0,0 @@ -source ${SCRIPT_DIR}/lib/util.sh - -function run() { - dir="${1}" - - print_header "Running unit tests for ${dir}" - - # Install dependencies if required. - pre_test "${dir}" - - pushd "${dir}" >/dev/null || exit - - if [[ "x${ORB_NODOWNLOAD}" == "x" ]]; then - print_msg "Downloading go modules" - go mod download &>/dev/null 2>&1 - print_msg "done" - fi - - # Run tests. - echo $(go env GOPATH)/bin/go test ./... -v -benchmem -bench=. - $(go env GOPATH)/bin/richgo test ./... -v -benchmem -bench=. - - rc=$? - - popd >/dev/null || exit - - # Kill all depdency processes. - post_test "${dir}" - - return ${rc} -} - -if [[ "${1}" == "xargs" ]]; then - out=$(run $2 "${ORB_ROOT}" 2>&1) - rc=$? - printf "%s" "${out}" - - exit ${rc} -else - run $2 "${ORB_ROOT}" - exit $? -fi \ No newline at end of file diff --git a/scripts/lib/run_lint.sh b/scripts/lib/run_lint.sh deleted file mode 100644 index 166ffe2d..00000000 --- a/scripts/lib/run_lint.sh +++ /dev/null @@ -1,26 +0,0 @@ -source ${SCRIPT_DIR}/lib/util.sh - -function run() { - print_header "Running linter on ${1}" - - if ! cd "${1}"; then - print_red_msg "Failed to change dir" - exit 1 - fi - - /tmp/golangci-lint run - - # Keep track of exit code of linter - if [[ $? -ne 0 ]]; then - print_red_msg "Failed" - exit 1 - fi - - exit 0 -} - -out="$(run $1 2>&1)" -rc=$? - -printf "%s\n" "${out}" -exit $rc \ No newline at end of file diff --git a/scripts/lib/run_test.sh b/scripts/lib/run_test.sh deleted file mode 100755 index 38f5f6bb..00000000 --- a/scripts/lib/run_test.sh +++ /dev/null @@ -1,41 +0,0 @@ -source ${SCRIPT_DIR}/lib/util.sh - -function run() { - dir="${1}" - - print_header "Running unit tests for ${dir}" - - # Install dependencies if required. - pre_test "${dir}" - - pushd "${dir}" >/dev/null || exit - - if [[ "x${ORB_NODOWNLOAD}" == "x" ]]; then - print_msg "Downloading go modules..." - go mod download &>/dev/null 2>&1 - print_msg "done, now running the test..." - fi - - # Run tests. - $(go env GOPATH)/bin/richgo test ./... ${ORB_GO_TEST_FLAGS} - - rc=$? - - popd >/dev/null || exit - - # Kill all depdency processes. - post_test "${dir}" - - return ${rc} -} - -if [[ "${1}" == "xargs" ]]; then - out=$(run $2 "${ORB_ROOT}" 2>&1) - rc=$? - printf "%s" "${out}" - - exit ${rc} -else - run $2 "${ORB_ROOT}" - exit $? -fi \ No newline at end of file diff --git a/scripts/lib/util.sh b/scripts/lib/util.sh deleted file mode 100755 index bb211263..00000000 --- a/scripts/lib/util.sh +++ /dev/null @@ -1,83 +0,0 @@ -## bash -RED='\033[0;31m' -NC='\033[0m' -GREEN='\033[0;32m' -BAR="-------------------------------------------------------------------------------" - -export RICHGO_FORCE_COLOR="true" -# export IN_TRAVIS_CI="true" -# export TRAVIS="true" - -function print_msg() { - printf "${GREEN} > ${1}${NC}\n" -} - -function print_red_msg() { - printf "${RED} > ${1}${NC}\n" -} - -# Print a green colored message to the screen. -function print_header() { - printf "\n\n${GREEN}${BAR}${NC}\n" - printf "${GREEN}| > ${1}${NC}\n" - printf "${GREEN}${BAR}${NC}\n\n" - sleep 1 -} - -# Print a red colored message to the screen. -function print_red_header() { - printf "\n\n${RED}${BAR}${NC}\n" - printf "${RED}| > ${1}${NC}\n" - printf "${RED}${BAR}${NC}\n\n" - sleep 1 -} - -# Print the contents of the directory array. -function print_list() { - dirs=$1 - - print_header "Found ${#dirs[@]} directories to test" - echo "Changed dirs:" - printf '%s \n' "${dirs[@]}" - printf '\n\n' - sleep 1 -} - -# Run a pre_test script for a plugin, usualy downloads a server. -# -function pre_test() { - if [[ ! -e "${1}/scripts/pre_test.sh" ]]; then - # Return no error if no such script - return 0 - fi - - print_msg "Executing pre test for ${1}" - ${1}/scripts/pre_test.sh - return $? -} - -# Run post_test script. -function post_test() { - if [[ ! -e "${1}/scripts/post_test.sh" ]]; then - # Return no error if no such script - return 0 - fi - - print_msg "Executing post test for ${1}" - ${1}/scripts/post_test.sh - return $? -} - -# https://gist.github.com/lukechilds/a83e1d7127b78fef38c2914c4ececc3c -function get_latest_gh_release() { - curl --silent "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api - grep '"tag_name":' | # Get tag line - sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value -} - -# Add a job summary to GitHub Actions. -[ -z ${GITHUB_STEP_SUMMARY+x} ] && GITHUB_STEP_SUMMARY=$(mktemp) - -function add_summary() { - printf "${1}\n" >>"${GITHUB_STEP_SUMMARY}" -} \ No newline at end of file diff --git a/scripts/mod-dropreplace.sh b/scripts/mod-dropreplace.sh deleted file mode 100755 index 756cc729..00000000 --- a/scripts/mod-dropreplace.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash - -RUN_PWD="${PWD}" -GO_ORB="github.com/go-orb/" -GO_ORB_LEN="${#GO_ORB}" -GO_ORB_PLUGINS="${GO_ORB}plugins/" -GO_ORB_PLUGINS_LEN="${#GO_ORB_PLUGINS}" - -pushd "${1}"; -for package in $(grep --null -E "^replace\s+github.com/go-orb/[\/a-zA-Z\-]+ => .*$" go.mod); do - if [[ "${package:0:$GO_ORB_LEN}" != "${GO_ORB}" ]]; then - continue; - fi - - echo go mod edit -dropreplace="${package}"; - go mod edit -dropreplace="${package}"; -done; -popd >/dev/null; \ No newline at end of file diff --git a/scripts/mod-replace.sh b/scripts/mod-replace.sh deleted file mode 100755 index d57a2a1e..00000000 --- a/scripts/mod-replace.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env bash - -RUN_PWD="${PWD}" - -pushd "${1}"; -for package in $(grep --null -E "^(require)?\s+github.com/go-orb/[\/a-zA-Z\-]+" go.mod); do - if [[ "${package:0:18}" != "github.com/go-orb/" ]]; then - continue; - fi; - - noprefix=${package:18}; - - mycwd="${RUN_PWD}/${1}"; - if [[ "${1:0:2}" == "./" ]]; then - mycwd="${RUN_PWD}/${1:2}" - fi - - target=""; - if [[ "${noprefix:0:8}" == "plugins/" ]]; then - target="${RUN_PWD}/${noprefix:8}"; - else - target="${RUN_PWD}/../${noprefix}"; - fi - - realpath=$(realpath --relative-to="${mycwd}" "${target}"); - - echo go mod edit -replace="${package}=${realpath}"; - go mod edit -replace="${package}=${realpath}"; -done; -popd >/dev/null; \ No newline at end of file diff --git a/scripts/release.sh b/scripts/release.sh deleted file mode 100755 index 498b23a0..00000000 --- a/scripts/release.sh +++ /dev/null @@ -1,127 +0,0 @@ -#!/bin/bash - -###################################################################################### -# Release a plugin # -# # -# Usage: # -# $ release.sh all # -# $ release.sh v4/broker/http # -# $ release.sh v4/broker/http,v4/broker/redis # -# $ release.sh v4/* # -# # -###################################################################################### - -CHANGELOG_TEMPLATE="scripts/template/changelog.md" -CHANGELOG_FILE="/tmp/changelog.md" - -function increment_minor_version() { - declare -a part=(${1//\./ }) - part[2]=0 - part[1]=$((part[1] + 1)) - new="${part[*]}" - echo -e "${new// /.}" -} - -function increment_patch_version() { - declare -a part=(${1//\./ }) - part[2]=$((part[2] + 1)) - new="${part[*]}" - echo -e "${new// /.}" -} - -function remove_prefix() { - echo "${1//\.\//}" -} - -function check_if_changed() { - local pkg="$1" - local last_tag=$(git tag --list --sort='-creatordate' "${pkg}/*" | head -n1) - if [[ ${last_tag} == "" ]]; then - echo -e "# No previous tag\n# Run:\ngh release create ""${pkg}/v1.0.0"" -n 'Initial release'" - return 1 - fi - - local changes="$(git --no-pager log "${last_tag}..HEAD" --format="%s" "${pkg}")" - if [[ ${#changes} == "0" ]]; then - # echo "# No changes detected in package '${pkg}'" - return 1 - fi - return 0 -} - -function release() { - if [[ ! -f "${1}/go.mod" ]]; then - echo "Unknown package '${1}' given." - return 1 - fi - - local pkg="${1}" - if ! check_if_changed "${pkg}"; then - return 1 - fi - - cat "${CHANGELOG_TEMPLATE}" >"${CHANGELOG_FILE}" - - local last_tag=$(git tag --list --sort='-creatordate' "${pkg}/*" | head -n1) - - # Create changelog file - git log "${last_tag}..HEAD" --format="%s" "${pkg}" | - xargs -d'\n' -I{} bash -c "echo \" * {}\" >> ${CHANGELOG_FILE}" - - declare -a last_tag_split=(${last_tag//\// }) - - local v_version=${last_tag_split[-1]} - local version=${v_version:1} - # Remove the version from last_tag_split - unset last_tag_split[-1] - - # Increment minor version if "feat:" commit found, otherwise patch version - git --no-pager log "${last_tag}..HEAD" --format="%s" "${pkg}/*" | grep -q -E "^feat:" - if [[ $? == "0" ]]; then - local tmp_new_tag="$(printf "/%s" "${last_tag_split[@]}")/v$(increment_minor_version "${version}")" - local new_tag=${tmp_new_tag:1} - else - local tmp_new_tag="$(printf "/%s" "${last_tag_split[@]}")/v$(increment_patch_version "${version}")" - local new_tag=${tmp_new_tag:1} - fi - - # echo -e "# Run:\n" - echo "# Upgrading pkg ${last_tag} >> ${new_tag}" - # echo "gh release create \"${new_tag}\" --generate-notes --notes-start-tag ${last_tag}" - gh release create "${new_tag}" --notes-file "${CHANGELOG_FILE}" -} - -function release_all() { - while read -r pkg; do - pkg=$(remove_prefix "${pkg}") - if echo "${pkg}" | grep -q "^v2"; then - continue - fi - release "${pkg}" - done < <(find . -name 'go.mod' -printf "%h\n") -} - -function release_specific() { - set +o noglob - while read -r pkg; do - # If path contains a star find all relevant packages - if echo "${pkg}" | grep -q "\*"; then - while read -r p; do - release "$(remove_prefix "${p}")" - done < <(find "${pkg}" -name 'go.mod' -printf "%h\n") - else - release "${pkg}" - fi - done < <(echo "${1}" | tr "," "\n") - # set -o noglob - # set +o noglob -} - -case $1 in -"all") - release_all - ;; -*) - release_specific "${1}" - ;; -esac diff --git a/scripts/template/changelog.md b/scripts/template/changelog.md deleted file mode 100644 index 825c32f0..00000000 --- a/scripts/template/changelog.md +++ /dev/null @@ -1 +0,0 @@ -# Changelog diff --git a/scripts/test.sh b/scripts/test.sh deleted file mode 100755 index 724032e1..00000000 --- a/scripts/test.sh +++ /dev/null @@ -1,237 +0,0 @@ -#!/usr/bin/env bash - -export SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -export ORB_ROOT=$(realpath "${SCRIPT_DIR}/..") - -if [[ "x$GOMAXPROCS" == "x" ]]; then - # Run all tests/benchmarks with a single core by default. - export GOMAXPROCS=1 -fi - -if [[ "x$PROCS" == "x" ]]; then - export PROCS=$(expr $(nproc) - 1) -fi - -export ORB_GO_TEST_FLAGS="-v -race -cover" - -source "${SCRIPT_DIR}/lib/util.sh" - - -# Find directories that contain changes. -function find_changes() { - # Find all directories that have changed files. - changes=($(git diff --name-only origin/main | xargs -d'\n' -I{} dirname {} | sort -u)) - - # Filter out directories without go.mod files. - changes=($(find "${changes[@]}" -maxdepth 1 -name 'go.mod' -printf '%h\n' 2>/dev/null)) - - echo "${changes[@]}" -} - -# Find all go directories. -function find_all() { - find "${ORB_ROOT}" -name 'go.mod' -printf '%h\n' -} - -# Get the dir list based on command type. -function get_dirs() { - if [[ $1 == "all" ]]; then - echo $(find_all) - elif [[ $1 == "changes" ]]; then - echo $(find_changes) - else - # no all or changes, so it must a be a list of directories. - # either prepend the root of go-orb/plugins or try to get the - # path with realpath. - for dir in "${@}"; do - if [[ ! -d ${dir} ]]; then - if [[ -d "${ORB_ROOT}/${dir}" ]]; then - echo -n "${ORB_ROOT}/${dir} " - fi - else - echo -n "$(realpath "${dir}") " - fi - done - fi -} - -# Run GoLangCi Linters. -function run_linter() { - if [[ ! -e /tmp/bin/golangci-lint ]]; then - curl -sSfL "https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh" | sh -s -- -b /tmp - fi - - /tmp/golangci-lint --version - - print_msg "Running linters with $PROCS procs" - dirs=$1 - failed="false" - printf "%s\0" "${dirs[@]}" | xargs -0 -n1 -P $PROCS -- /usr/bin/env bash "${SCRIPT_DIR}/lib/run_lint.sh" || failed="true" - - if [[ "x${failed}" != "xfalse" ]]; then - print_red_header "Lint failed" - exit 1 - else - print_header "Lint OK" - fi -} - -# Run Unit tests with RichGo for pretty output. -function run_test() { - dirs=$1 - - if [[ ! -e $(go env GOPATH)/bin/richgo ]]; then - print_msg "Downloading richgo..." - go install github.com/kyoh86/richgo@latest - fi - - procs=$PROCS - failed="false" - - if [[ ${#dirs[@]} == 1 ]] || [[ ${procs} == 1 ]]; then - for dir in "${dirs[@]}"; do - /usr/bin/env bash "${SCRIPT_DIR}/lib/run_test.sh" "direct" "${dir}" - done - else - print_msg "Running tests with ${procs} procs, GOMAXPROCS=${GOMAXPROCS}" - printf "%s\0" "${dirs[@]}" | xargs -0 -n1 -P ${procs} -- /usr/bin/env bash "${SCRIPT_DIR}/lib/run_test.sh" "xargs" || failed="true" - fi - - if [[ "x${failed}" != "xfalse" ]]; then - print_red_header "Tests failed" - exit 1 - fi -} - - -# Run Unit tests+benchamrks with RichGo for pretty output. -function run_bench() { - dirs=$1 - - if [[ ! -e $(go env GOPATH)/bin/richgo ]]; then - print_msg "Downloading richgo..." - go install github.com/kyoh86/richgo@latest - fi - - procs=$PROCS - failed="false" - - if [[ ${#dirs[@]} == 1 ]] || [[ ${procs} == 1 ]]; then - for dir in "${dirs[@]}"; do - /usr/bin/env bash "${SCRIPT_DIR}/lib/run_bench.sh" "direct" "${dir}" - done - else - print_msg "Running tests with ${procs} procs, GOMAXPROCS=${GOMAXPROCS}" - printf "%s\0" "${dirs[@]}" | xargs -0 -n1 -P ${procs} -- /usr/bin/env bash "${SCRIPT_DIR}/lib/run_bench.sh" "xargs" || failed="true" - fi - - if [[ "x${failed}" != "xfalse" ]]; then - print_red_header "Tests failed" - exit 1 - fi -} - - -# Run unit tests with tparse to create a summary. -function create_summary() { - go install github.com/mfridman/tparse@latest - - add_summary "## Test Summary" - - cwd=$(pwd) - dirs=$1 - failed="false" - for dir in "${dirs[@]}"; do - # Install dependencies if required. - pre_test "${dir}" - - pushd "${dir}" >/dev/null || continue - print_header "Creating summary for ${dir}" - - add_summary "\n### ${dir}\n" - - # Download all modules. - go get -v -t ./... - - go test ./... ${GO_TEST_FLAGS} -json | - tparse -notests -format=markdown >>"${GITHUB_STEP_SUMMARY}" - rc=$? - - - if [[ ${rc} -ne 0 ]]; then - failed="true" - print_red_msg "Failed" - fi - - popd >/dev/null || continue - - # Kill all depdency processes. - post_test "${dir}" - - if [[ ${rc} == 0 ]]; then - print_msg "Succeded" - fi - done - - if [[ ${failed} == "true" ]]; then - print_red_header "Tests failed" - exit 1 - fi -} - -if [[ ! -z "${CI}" ]]; then # only run in github_ci - if [[ -f ${ORB_ROOT}/ORB_BRANCH ]]; then - if [[ ! -d ${ORB_ROOT}/../go-orb ]]; then - print_header "Fetching go-orb: $(cat ${ORB_ROOT}/ORB_BRANCH)" - git clone --branch "$(cat ${ORB_ROOT}/ORB_BRANCH)" https://github.com/go-orb/go-orb ${ORB_ROOT}/../go-orb - else - print_header "Updating go-orb with branch: $(cat ${ORB_ROOT}/ORB_BRANCH)" - pushd ${ORB_ROOT}/../go-orb >/dev/null - git reset --hard - git checkout "$(cat ${ORB_ROOT}/ORB_BRANCH)" - git pull - popd >/dev/null - fi - fi -fi - -case $1 in -"lint") - read -a dirs <<< $(get_dirs "${@:2}") - [[ ${#dirs[@]} -eq 0 ]] && print_red_header "No changed Go files detected" && exit 0 - - print_list "${dirs[@]}" - run_linter "${dirs[@]}" - ;; -"test") - read -a dirs <<< $(get_dirs "${@:2}") - [[ ${#dirs[@]} -eq 0 ]] && print_red_header "No changed Go files detected" && exit 0 - - print_list "${dirs[@]}" - - run_test "${dirs[@]}" - ;; -"bench") - read -a dirs <<< $(get_dirs "${@:2}") - [[ ${#dirs[@]} -eq 0 ]] && print_red_header "No changed Go files detected" && exit 0 - - print_list "${dirs[@]}" - - run_bench "${dirs[@]}" - ;; -"summary") - read -a dirs <<< $(get_dirs "${@:2}") - [[ ${#dirs[@]} -eq 0 ]] && print_red_header "No changed Go files detected" && exit 0 - - print_list "${dirs[@]}" - create_summary "${dirs[@]}" - ;; -"") - printf "Please provide a command [lint, test, summary]." - exit 1 - ;; -*) - printf "Command not found: $1. Select one of [lint, test, bench, summary]" - exit 1 - ;; -esac