mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-24 04:16:27 +02:00
ci: daggerize test pipeline (#4969)
## What is this? This daggerizes the lint, test, and build pipelines for Goreleaser. ## Why? For context, the previous pass at this can be found here https://github.com/goreleaser/goreleaser/pull/4186 . Since that time, the DX for using Dagger has been considerably improved. The benefit this brings to the Goreleaser project is that the test pipeline can be run locally the same as it is run in CI without requiring contributors to configure additional tools in their developer environments. Additionally, by codifying the test and build execution environments, you no longer need to be concerned with changing or outdated Github Actions runner environments. ## How? As a contributor, you can simply clone/fork Goreleaser and run: `dagger functions` to see which commands are available. To lint local code: `dagger call --source . lint` To run tests against local code: `dagger call --source . test output` To run tests against local code and get the coverage report: `dagger call --source . test coverage-report -o ./coverage.txt` To run tests on the main branch on Github: `dagger call --source=https://github.com/goreleaser/goreleaser test output` To run tests against a PR branch on Github: `dagger call --source=https://github.com/goreleaser/goreleaser#pull/4958/head test output` To run tests against a PR branch using the dagger pipeline committed to the main branch, without checking out goreleaser: `dagger -m github.com/goreleaser/goreleaser call --source=https://github.com/goreleaser/goreleaser#pull/4958/head test output` And so on 😃 ## Also In addition to the Dagger code, I've updated the build.yml workflow to use the test pipeline and updated CONTRIBUTING.md with the command to run tests with Dagger. Note that I did not update the Taskfile.yml to avoid breaking anything for contributors comfortable with their existing workflows. Do you feel that this will benefit the Goreleaser project? Would you like to see the Dagger functions doing more/less? --------- Signed-off-by: kpenfound <kyle@dagger.io> Signed-off-by: Lev Lazinskiy <lev@levlaz.org> Signed-off-by: Lev Lazinskiy <lev@dagger.io> Co-authored-by: Lev Lazinskiy <lev@levlaz.org> Co-authored-by: Lev Lazinskiy <lev@dagger.io>
This commit is contained in:
parent
0a42a983b0
commit
d594cdd436
50
.github/workflows/dagger-build.yml
vendored
Normal file
50
.github/workflows/dagger-build.yml
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
name: daggerized build
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- "main"
|
||||
pull_request:
|
||||
paths:
|
||||
- "go.*"
|
||||
- "**/*.go"
|
||||
- "Taskfile.yml"
|
||||
- "Dockerfile"
|
||||
- ".github/workflows/*.yml"
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
govulncheck:
|
||||
uses: caarlos0/meta/.github/workflows/govulncheck.yml@main
|
||||
semgrep:
|
||||
uses: caarlos0/meta/.github/workflows/semgrep.yml@main
|
||||
ruleguard:
|
||||
uses: caarlos0/meta/.github/workflows/ruleguard.yml@main
|
||||
with:
|
||||
args: "-disable largeloopcopy"
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- uses: dagger/dagger-for-github@v6.8.0
|
||||
with:
|
||||
args: build -o ./goreleaser
|
||||
engine-stop: false
|
||||
- uses: dagger/dagger-for-github@v6.8.0
|
||||
with:
|
||||
args: test coverage-report -o ./coverage.txt
|
||||
# - uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4
|
||||
# with:
|
||||
# file: ./coverage.txt
|
||||
- run: git diff
|
||||
check:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- run: go run . check
|
@ -10,17 +10,9 @@ By participating in this project, you agree to abide our
|
||||
Prerequisites:
|
||||
|
||||
- [Task](https://taskfile.dev/installation)
|
||||
- [Dagger](https://docs.dagger.io/install)
|
||||
- [Go 1.23+](https://go.dev/doc/install)
|
||||
|
||||
Other things you might need to run the tests:
|
||||
|
||||
- [cosign](https://github.com/sigstore/cosign)
|
||||
- [Docker](https://www.docker.com/)
|
||||
- [GPG](https://gnupg.org)
|
||||
- [Podman](https://podman.io/)
|
||||
- [Snapcraft](https://snapcraft.io/)
|
||||
- [Syft](https://github.com/anchore/syft)
|
||||
- [upx](https://upx.github.io/)
|
||||
|
||||
Clone `goreleaser` anywhere:
|
||||
|
||||
@ -41,6 +33,12 @@ go build -o goreleaser .
|
||||
./goreleaser --version
|
||||
```
|
||||
|
||||
A good way to check if everything is alright is to run the test suite:
|
||||
|
||||
```bash
|
||||
dagger call test
|
||||
```
|
||||
|
||||
### A note about Docker multi-arch builds
|
||||
|
||||
If you want to properly run the Docker tests, or run `goreleaser release
|
||||
|
12
dagger.json
Normal file
12
dagger.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "goreleaser",
|
||||
"sdk": "go",
|
||||
"dependencies": [
|
||||
{
|
||||
"name": "docker",
|
||||
"source": "github.com/shykes/daggerverse/docker@c9a80c9eac0675a53a7e052da3594207f4235988"
|
||||
}
|
||||
],
|
||||
"source": "dagger",
|
||||
"engineVersion": "v0.13.0"
|
||||
}
|
4
dagger/.gitattributes
vendored
Normal file
4
dagger/.gitattributes
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
/dagger.gen.go linguist-generated
|
||||
/internal/dagger/** linguist-generated
|
||||
/internal/querybuilder/** linguist-generated
|
||||
/internal/telemetry/** linguist-generated
|
4
dagger/.gitignore
vendored
Normal file
4
dagger/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
/dagger.gen.go
|
||||
/internal/dagger
|
||||
/internal/querybuilder
|
||||
/internal/telemetry
|
75
dagger/build.go
Normal file
75
dagger/build.go
Normal file
@ -0,0 +1,75 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
|
||||
"github.com/goreleaser/goreleaser/dagger/internal/dagger"
|
||||
)
|
||||
|
||||
const (
|
||||
// cgr.dev/chainguard/wolfi-base:latest 6/26/2024
|
||||
wolfiBase = "cgr.dev/chainguard/wolfi-base@sha256:7a5b796ae54f72b78b7fc33c8fffee9a363af2c6796dac7c4ef65de8d67d348d"
|
||||
)
|
||||
|
||||
// Build Goreleaser
|
||||
func (g *Goreleaser) Build(
|
||||
// Target OS to build
|
||||
// +default="linux"
|
||||
os string,
|
||||
// Target architecture to build
|
||||
// +optional
|
||||
arch string,
|
||||
) *dagger.File {
|
||||
if arch == "" {
|
||||
arch = runtime.GOARCH
|
||||
}
|
||||
return g.BuildEnv().
|
||||
WithUser("nonroot").
|
||||
WithEnvVariable("GOOS", os).
|
||||
WithEnvVariable("GOARCH", arch).
|
||||
WithExec([]string{"go", "build", "-o", "/src/dist/goreleaser"}).
|
||||
File("/src/dist/goreleaser")
|
||||
}
|
||||
|
||||
// Base container to build and test Goreleaser
|
||||
func (g *Goreleaser) Base() *dagger.Container {
|
||||
// Base image with Go
|
||||
return dag.Container().
|
||||
From(wolfiBase).
|
||||
WithExec([]string{"apk", "add", "go"}).
|
||||
// Mount the Go cache
|
||||
WithMountedCache(
|
||||
"/go",
|
||||
dag.CacheVolume("goreleaser-goroot"),
|
||||
dagger.ContainerWithMountedCacheOpts{
|
||||
Owner: "nonroot",
|
||||
}).
|
||||
WithEnvVariable("GOMODCACHE", "/go/pkg/mod").
|
||||
// Mount the Go build cache
|
||||
WithMountedCache(
|
||||
"/gocache",
|
||||
dag.CacheVolume("goreleaser-gobuild"),
|
||||
dagger.ContainerWithMountedCacheOpts{
|
||||
Owner: "nonroot",
|
||||
}).
|
||||
WithEnvVariable("GOCACHE", "/gocache")
|
||||
}
|
||||
|
||||
// Container to build Goreleaser
|
||||
func (g *Goreleaser) BuildEnv() *dagger.Container {
|
||||
// Base image with Go
|
||||
return g.Base().
|
||||
// Mount the source code last to optimize cache
|
||||
With(WithSource(g))
|
||||
}
|
||||
|
||||
// Helper function to mount the project source into a container
|
||||
func WithSource(g *Goreleaser) dagger.WithContainerFunc {
|
||||
return func(c *dagger.Container) *dagger.Container {
|
||||
return c.
|
||||
WithMountedDirectory("/src", g.Source, dagger.ContainerWithMountedDirectoryOpts{
|
||||
Owner: "nonroot",
|
||||
}).
|
||||
WithWorkdir("/src")
|
||||
}
|
||||
}
|
48
dagger/go.mod
Normal file
48
dagger/go.mod
Normal file
@ -0,0 +1,48 @@
|
||||
module github.com/goreleaser/goreleaser/dagger
|
||||
|
||||
go 1.22.1
|
||||
|
||||
require (
|
||||
github.com/99designs/gqlgen v0.17.49
|
||||
github.com/Khan/genqlient v0.7.0
|
||||
github.com/vektah/gqlparser/v2 v2.5.16
|
||||
go.opentelemetry.io/otel v1.28.0
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.28.0
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.28.0
|
||||
go.opentelemetry.io/otel/sdk v1.28.0
|
||||
go.opentelemetry.io/otel/trace v1.28.0
|
||||
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
|
||||
golang.org/x/sync v0.7.0
|
||||
google.golang.org/grpc v1.65.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.21.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/otlplog/otlploggrpc v0.0.0-20240801193407-d7372079a809
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.4.0
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 // indirect
|
||||
go.opentelemetry.io/otel/log v0.4.0
|
||||
go.opentelemetry.io/otel/metric v1.28.0 // indirect
|
||||
go.opentelemetry.io/otel/sdk/log v0.4.0
|
||||
go.opentelemetry.io/proto/otlp v1.3.1
|
||||
golang.org/x/net v0.27.0 // indirect
|
||||
golang.org/x/sys v0.22.0 // indirect
|
||||
golang.org/x/text v0.16.0 // indirect
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240730163845-b1a4ccb954bf // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240730163845-b1a4ccb954bf // 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
|
87
dagger/go.sum
Normal file
87
dagger/go.sum
Normal file
@ -0,0 +1,87 @@
|
||||
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.21.0 h1:CWyXh/jylQWp2dtiV33mY4iSSp6yf4lmn+c7/tN+ObI=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.21.0/go.mod h1:nCLIt0w3Ept2NwF8ThLmrppXsfT07oC8k0XNDxd8sVU=
|
||||
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.28.0 h1:/SqNcYk+idO0CxKEUOtKQClMK/MimZihKYMruSMViUo=
|
||||
go.opentelemetry.io/otel v1.28.0/go.mod h1:q68ijF8Fc8CnMHKyzqL6akLO46ePnjkgfIMIjUIX9z4=
|
||||
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.28.0 h1:3Q/xZUyC1BBkualc9ROb4G8qkH90LXEIICcs5zv1OYY=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0/go.mod h1:s75jGIWA9OfCMzF0xr+ZgfrB5FEbbV7UuYo32ahUiFI=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.28.0 h1:R3X6ZXmNPRR8ul6i3WgFURCHzaXjHdm0karRG/+dj3s=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.28.0/go.mod h1:QWFXnDavXWwMx2EEcZsf3yxgEKAqsxQ+Syjp+seyInw=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.28.0 h1:j9+03ymgYhPKmeXGk5Zu+cIZOlVzd9Zv7QIiyItjFBU=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.28.0/go.mod h1:Y5+XiUG4Emn1hTfciPzGPJaSI+RpDts6BnCIir0SLqk=
|
||||
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.28.0 h1:f0HGvSl1KRAU1DLgLGFjrwVyismPlnuU6JD6bOeuA5Q=
|
||||
go.opentelemetry.io/otel/metric v1.28.0/go.mod h1:Fb1eVBFZmLVTMb6PPohq3TO9IIhUisDsbJoL/+uQW4s=
|
||||
go.opentelemetry.io/otel/sdk v1.28.0 h1:b9d7hIry8yZsgtbmM0DKyPWMMUMlK9NEKuIG4aBqWyE=
|
||||
go.opentelemetry.io/otel/sdk v1.28.0/go.mod h1:oYj7ClPUA7Iw3m+r7GeEjz0qckQRJK2B8zjcZEfu7Pg=
|
||||
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.28.0 h1:GhQ9cUuQGmNDd5BTCP2dAvv75RdMxEfTmYejp+lkx9g=
|
||||
go.opentelemetry.io/otel/trace v1.28.0/go.mod h1:jPyXzNPg6da9+38HEwElrQiHlVMTnVfM3/yv2OlIHaI=
|
||||
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-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8=
|
||||
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
|
||||
golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
|
||||
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
|
||||
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
|
||||
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
|
||||
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
|
||||
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240730163845-b1a4ccb954bf h1:GillM0Ef0pkZPIB+5iO6SDK+4T9pf6TpaYR6ICD5rVE=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240730163845-b1a4ccb954bf/go.mod h1:OFMYQFHJ4TM3JRlWDZhJbZfra2uqc3WLBZiaaqP4DtU=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240730163845-b1a4ccb954bf h1:liao9UHurZLtiEwBgT9LMOnKYsHze6eA6w1KQCMVN2Q=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240730163845-b1a4ccb954bf/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY=
|
||||
google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc=
|
||||
google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ=
|
||||
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=
|
27
dagger/lint.go
Normal file
27
dagger/lint.go
Normal file
@ -0,0 +1,27 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Lint Goreleaser
|
||||
func (g *Goreleaser) Lint(
|
||||
ctx context.Context,
|
||||
// Version of golangci-lint to use
|
||||
// +default="v1.58.1"
|
||||
golangciLintVersion string,
|
||||
) (string, error) {
|
||||
lintImage := fmt.Sprintf("golangci/golangci-lint:%s", golangciLintVersion)
|
||||
return dag.Container().From(lintImage).
|
||||
WithMountedDirectory("/src", g.Source).
|
||||
WithWorkdir("/src").
|
||||
WithExec([]string{
|
||||
"golangci-lint",
|
||||
"run",
|
||||
"--config",
|
||||
"./.golangci.yaml",
|
||||
"./...",
|
||||
}).
|
||||
Stdout(ctx)
|
||||
}
|
27
dagger/main.go
Normal file
27
dagger/main.go
Normal file
@ -0,0 +1,27 @@
|
||||
// A module for Goreleaser Dagger functions
|
||||
|
||||
package main
|
||||
|
||||
import "github.com/goreleaser/goreleaser/dagger/internal/dagger"
|
||||
|
||||
type Goreleaser struct {
|
||||
// +private
|
||||
Source *dagger.Directory
|
||||
}
|
||||
|
||||
func New(
|
||||
// The Goreleaser source code to use
|
||||
// +optional
|
||||
// +defaultPath="/"
|
||||
Source *dagger.Directory,
|
||||
) *Goreleaser {
|
||||
if Source == nil {
|
||||
Source = dag.Git(
|
||||
"https://github.com/goreleaser/goreleaser.git",
|
||||
dagger.GitOpts{KeepGitDir: true},
|
||||
).
|
||||
Branch("main").
|
||||
Tree()
|
||||
}
|
||||
return &Goreleaser{Source: Source}
|
||||
}
|
27
dagger/run.go
Normal file
27
dagger/run.go
Normal file
@ -0,0 +1,27 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"runtime"
|
||||
|
||||
"github.com/goreleaser/goreleaser/dagger/internal/dagger"
|
||||
)
|
||||
|
||||
// Run Goreleaser
|
||||
func (g *Goreleaser) Run(
|
||||
ctx context.Context,
|
||||
// Context directory to run in
|
||||
context *dagger.Directory,
|
||||
// Arguments to pass to Goreleaser
|
||||
args []string,
|
||||
) (string, error) {
|
||||
binary := g.Build("linux", runtime.GOARCH)
|
||||
|
||||
return dag.Container().
|
||||
From("cgr.dev/chainguard/wolfi-base").
|
||||
WithMountedFile("/bin/goreleaser", binary).
|
||||
WithMountedDirectory("/src", context).
|
||||
WithWorkdir("/src").
|
||||
WithExec(append([]string{"/bin/goreleaser"}, args...)).
|
||||
Stdout(ctx)
|
||||
}
|
124
dagger/test.go
Normal file
124
dagger/test.go
Normal file
@ -0,0 +1,124 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"runtime"
|
||||
|
||||
"github.com/goreleaser/goreleaser/dagger/internal/dagger"
|
||||
)
|
||||
|
||||
const (
|
||||
// nixos/nix:2.18.3
|
||||
nixBase = "nixos/nix@sha256:3f8fec6acf10ae6f1c8843ccc607490d4635d620a75afc0b523eedba7617c16e"
|
||||
buildxVersion = "v0.15.1"
|
||||
)
|
||||
|
||||
// Test Goreleaser
|
||||
func (g *Goreleaser) Test(ctx context.Context) *TestResult {
|
||||
test := g.TestEnv().
|
||||
WithExec([]string{
|
||||
"go",
|
||||
"test",
|
||||
"-failfast",
|
||||
"-race",
|
||||
"-coverpkg=./...",
|
||||
"-covermode=atomic",
|
||||
"-coverprofile=coverage.txt",
|
||||
"./...",
|
||||
"-run",
|
||||
".",
|
||||
})
|
||||
|
||||
return &TestResult{
|
||||
Container: test,
|
||||
}
|
||||
}
|
||||
|
||||
// Custom type for test results
|
||||
type TestResult struct {
|
||||
// Container with the test executed
|
||||
Container *dagger.Container
|
||||
}
|
||||
|
||||
// Coverage report from the test. Save with '-o ./coverage.txt'
|
||||
func (t *TestResult) CoverageReport() *dagger.File {
|
||||
return t.Container.File("coverage.txt")
|
||||
}
|
||||
|
||||
// Stdout from the test command
|
||||
func (t *TestResult) Output(ctx context.Context) (string, error) {
|
||||
return t.Container.Stdout(ctx)
|
||||
}
|
||||
|
||||
// Container to test Goreleaser
|
||||
func (g *Goreleaser) TestEnv() *dagger.Container {
|
||||
// Dependencies needed for testing
|
||||
testDeps := []string{
|
||||
"bash",
|
||||
"curl",
|
||||
"git",
|
||||
"gpg",
|
||||
"gpg-agent",
|
||||
"upx",
|
||||
"cosign",
|
||||
"docker",
|
||||
"syft",
|
||||
}
|
||||
return g.Base().
|
||||
WithEnvVariable("CGO_ENABLED", "1").
|
||||
WithExec(append([]string{"apk", "add"}, testDeps...)).
|
||||
With(installNix).
|
||||
With(installBuildx).
|
||||
WithUser("nonroot").
|
||||
WithExec([]string{"go", "install", "github.com/google/ko@latest"}).
|
||||
// This is bound at localhost for the hardcoded docker and ko registry tests
|
||||
WithServiceBinding("localhost", dag.Docker().Engine()).
|
||||
WithEnvVariable("DOCKER_HOST", "tcp://localhost:2375").
|
||||
// Mount the source code last to optimize cache
|
||||
With(WithSource(g))
|
||||
}
|
||||
|
||||
// Install Nix binaries from nixos image
|
||||
func installNix(target *dagger.Container) *dagger.Container {
|
||||
nix := dag.Container().From(nixBase)
|
||||
nixBin := "/root/.nix-profile/bin"
|
||||
|
||||
binaries := []string{
|
||||
"nix",
|
||||
"nix-build",
|
||||
"nix-channel",
|
||||
"nix-collect-garbage",
|
||||
"nix-copy-closure",
|
||||
"nix-daemon",
|
||||
"nix-env",
|
||||
"nix-hash",
|
||||
"nix-instantiate",
|
||||
"nix-prefetch-url",
|
||||
"nix-shell",
|
||||
"nix-store",
|
||||
}
|
||||
|
||||
for _, binary := range binaries {
|
||||
target = target.WithFile("/bin/"+binary, nix.File(nixBin+"/"+binary))
|
||||
}
|
||||
|
||||
target = target.WithDirectory("/nix/store", nix.Directory("/nix/store"))
|
||||
|
||||
return target
|
||||
}
|
||||
|
||||
// Install buildx plugin for Docker from buildx github release
|
||||
func installBuildx(target *dagger.Container) *dagger.Container {
|
||||
arch := runtime.GOARCH
|
||||
url := fmt.Sprintf("https://github.com/docker/buildx/releases/download/%s/buildx-%s.linux-%s", buildxVersion, buildxVersion, arch)
|
||||
|
||||
bin := dag.HTTP(url)
|
||||
|
||||
return target.WithFile(
|
||||
"/usr/lib/docker/cli-plugins/docker-buildx",
|
||||
bin,
|
||||
dagger.ContainerWithFileOpts{
|
||||
Permissions: 0777,
|
||||
})
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user