diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 0e80884b..32ee193f 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -98,3 +98,12 @@ jobs: run: curl -fsSL https://dl.dagger.io/dagger/install.sh | sudo BIN_DIR=/usr/local/bin sh - name: Dagger build run: make dagger-build + + # dagger-goreleaser-dryrun: + # runs-on: ubuntu-24.04 + # steps: + # - uses: actions/checkout@v4 + # - name: Install Dagger + # run: curl -fsSL https://dl.dagger.io/dagger/install.sh | sudo BIN_DIR=/usr/local/bin sh + # - name: Goreleaser dryrun + # run: make dagger-goreleaser-dryrun diff --git a/Makefile b/Makefile index 94a45ca1..7190fbf9 100644 --- a/Makefile +++ b/Makefile @@ -95,6 +95,10 @@ build: dagger-build: dagger call build --progress plain export --path bin/replicated +.PHONY: dagger-goreleaser-dryrun +dagger-goreleaser-dryrun: + dagger call goreleaser-dryrun --progress plain + .PHONY: release release: dagger call release \ diff --git a/dagger.json b/dagger.json index c84269c1..bc88cf95 100644 --- a/dagger.json +++ b/dagger.json @@ -5,11 +5,6 @@ "source": "go" }, "dependencies": [ - { - "name": "goreleaser", - "source": "github.com/developer-guy/excoriate-daggerverse/goreleaser@b4bc20faec104b7f45c9a429b20f7d39d1531b79", - "pin": "b4bc20faec104b7f45c9a429b20f7d39d1531b79" - }, { "name": "onepassword", "source": "github.com/replicatedhq/daggerverse/onepassword@0b03c8c560c2067f34dab800c92154abc3834841", diff --git a/dagger/release.go b/dagger/release.go index 3bf76aaf..170ec8a6 100644 --- a/dagger/release.go +++ b/dagger/release.go @@ -12,7 +12,7 @@ import ( "github.com/pkg/errors" ) -var goreleaserVersion = "v2.10.2" +var goreleaserVersion = "v2.14.3" func (r *Replicated) Release( ctx context.Context, @@ -175,39 +175,68 @@ func (r *Replicated) Release( return errors.Wrap(err, "failed to publish patch docker container") } - goreleaserContainer := dag.Goreleaser(dagger.GoreleaserOpts{ - Version: goreleaserVersion, - }).Ctr(). + args := []string{"goreleaser"} + if snapshot { + args = append(args, "release", "--snapshot") + } else { + args = append(args, "release") + } + if clean { + args = append(args, "--clean") + } + + ctr := newGoreleaserContainer(ctx, updatedSource). WithSecretVariable("GITHUB_TOKEN", githubToken). WithEnvVariable("GORELEASER_CURRENT_TAG", nextVersionTag). - WithEnvVariable("GORELEASER_PREVIOUS_TAG", previousVersionTag) + WithEnvVariable("GORELEASER_PREVIOUS_TAG", previousVersionTag). + With(CacheBustingExec(args)) - if snapshot { - _, err := dag. - Goreleaser(dagger.GoreleaserOpts{ - Version: goreleaserVersion, - Ctr: goreleaserContainer, - }). - WithSource(updatedSource). - Snapshot(ctx, dagger.GoreleaserSnapshotOpts{ - Clean: clean, - }) - if err != nil { - return errors.Wrap(err, "failed to snapshot goreleaser") - } - } else { - _, err := dag. - Goreleaser(dagger.GoreleaserOpts{ - Version: goreleaserVersion, - Ctr: goreleaserContainer, - }). - WithSource(updatedSource). - Release(ctx, dagger.GoreleaserReleaseOpts{ - Clean: clean, - }) - if err != nil { - return errors.Wrap(err, "failed to release goreleaser") - } + _, err = ctr.Stdout(ctx) + if err != nil { + return errors.Wrap(err, "failed to run goreleaser") + } + + return nil +} + +// newGoreleaserContainer returns a Go container with goreleaser installed and +// the source mounted, ready to run goreleaser commands. +func newGoreleaserContainer(ctx context.Context, source *dagger.Directory) *dagger.Container { + image, err := goImage(ctx, source) + if err != nil { + image = "golang:latest" + } + goModCache, goBuildCache, err := goCacheVolumes(ctx, source) + if err != nil { + goModCache = dag.CacheVolume("replicated-go-mod") + goBuildCache = dag.CacheVolume("replicated-go-build") + } + + return dag.Container(). + From(image). + WithExec([]string{"go", "install", "github.com/goreleaser/goreleaser/v2@" + goreleaserVersion}). + WithMountedDirectory("/src", source). + WithWorkdir("/src"). + WithMountedCache("/go/pkg/mod", goModCache). + WithEnvVariable("GOMODCACHE", "/go/pkg/mod"). + WithMountedCache("/go/build-cache", goBuildCache). + WithEnvVariable("GOCACHE", "/go/build-cache") +} + +// GoreleaserDryrun runs a goreleaser snapshot build to verify the release +// configuration works. This is intended to be used as a PR check. +func (r *Replicated) GoreleaserDryrun( + ctx context.Context, + + // +defaultPath="./" + source *dagger.Directory, +) error { + ctr := newGoreleaserContainer(ctx, source). + With(CacheBustingExec([]string{"goreleaser", "release", "--snapshot", "--clean"})) + + _, err := ctr.Stdout(ctx) + if err != nil { + return errors.Wrap(err, "failed to run goreleaser dryrun") } return nil