Skip to content

Commit

Permalink
ci: add goreleaser pre-release config (dagger#9646)
Browse files Browse the repository at this point in the history
  • Loading branch information
jedevc authored Feb 20, 2025
1 parent 9903699 commit 2699209
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 22 deletions.
74 changes: 53 additions & 21 deletions .dagger/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,22 @@ func (cli *CLI) Publish(
ctx context.Context,
tag string,

githubOrgName string,
githubToken *dagger.Secret,

goreleaserKey *dagger.Secret,

awsAccessKeyID *dagger.Secret,
awsSecretAccessKey *dagger.Secret,
githubOrgName string,
githubToken *dagger.Secret, // +optional

awsRegion string,
awsBucket string,
artefactsFQDN string,
awsAccessKeyID *dagger.Secret, // +optional
awsSecretAccessKey *dagger.Secret, // +optional
awsRegion string, // +optional
awsBucket string, // +optional
artefactsFQDN string, // +optional

dryRun bool, // +optional
) error {
) (*dagger.Directory, error) {
ctr, err := publishEnv(ctx)
if err != nil {
return err
return nil, err
}
ctr = ctr.
WithWorkdir("/app").
Expand All @@ -68,7 +67,7 @@ func (cli *CLI) Publish(
if err != nil {
err, ok := err.(*ExecError)
if !ok || !strings.Contains(err.Stderr, "not a valid ref") {
return err
return nil, err
}
tag = ""
}
Expand All @@ -79,9 +78,21 @@ func (cli *CLI) Publish(
}

args := []string{"release", "--clean", "--skip=validate", "--verbose"}
if tag != "" && semver.Prerelease(tag) == "" {
args = append(args, "--release-notes", fmt.Sprintf(".changes/%s.md", tag))
if tag != "" {
if semver.Prerelease(tag) == "" {
// public release (vX.Y.Z)
args = append(args,
"--release-notes", fmt.Sprintf(".changes/%s.md", tag),
)
} else {
// public pre-release (vX.Y.Z-prerelease)
args = append(args,
"--nightly",
"--config", ".goreleaser.prerelease.yml",
)
}
} else {
// nightly off of main
args = append(args,
"--nightly",
"--config", ".goreleaser.nightly.yml",
Expand All @@ -91,23 +102,44 @@ func (cli *CLI) Publish(
args = append(args, "--skip=publish")
}

_, err = ctr.
ctr, err = ctr.
WithEnvVariable("GH_ORG_NAME", githubOrgName).
WithSecretVariable("GITHUB_TOKEN", githubToken).
WithSecretVariable("GORELEASER_KEY", goreleaserKey).
WithSecretVariable("AWS_ACCESS_KEY_ID", awsAccessKeyID).
WithSecretVariable("AWS_SECRET_ACCESS_KEY", awsSecretAccessKey).
WithEnvVariable("AWS_REGION", awsRegion).
WithEnvVariable("AWS_BUCKET", awsBucket).
WithEnvVariable("ARTEFACTS_FQDN", artefactsFQDN).
With(optSecretVariable("GITHUB_TOKEN", githubToken)).
With(optSecretVariable("AWS_ACCESS_KEY_ID", awsAccessKeyID)).
With(optSecretVariable("AWS_SECRET_ACCESS_KEY", awsSecretAccessKey)).
With(optEnvVariable("AWS_REGION", awsRegion)).
With(optEnvVariable("AWS_BUCKET", awsBucket)).
With(optEnvVariable("ARTEFACTS_FQDN", artefactsFQDN)).
WithEnvVariable("ENGINE_VERSION", cli.Dagger.Version).
WithEnvVariable("ENGINE_TAG", cli.Dagger.Tag).
WithEntrypoint([]string{"/sbin/tini", "--", "/entrypoint.sh"}).
WithExec(args, dagger.ContainerWithExecOpts{
UseEntrypoint: true,
}).
Sync(ctx)
return err
if err != nil {
return nil, err
}
return ctr.Directory("dist"), nil
}

func optEnvVariable(name string, val string) dagger.WithContainerFunc {
return func(ctr *dagger.Container) *dagger.Container {
if val == "" {
return ctr
}
return ctr.WithEnvVariable(name, val)
}
}

func optSecretVariable(name string, val *dagger.Secret) dagger.WithContainerFunc {
return func(ctr *dagger.Container) *dagger.Container {
if val == nil {
return ctr
}
return ctr.WithSecretVariable(name, val)
}
}

func (cli *CLI) PublishMetadata(
Expand Down
25 changes: 25 additions & 0 deletions .goreleaser.prerelease.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: 2

includes:
- from_file:
path: ./.goreleaser.common.yml

nightly:
# version_template will override .Version for nightly builds:
# https://goreleaser.com/customization/nightlies/#how-it-works
version_template: "{{ .Tag }}"

archives:
- name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}"
id: sha
files:
- LICENSE
format_overrides:
- goos: windows
format: zip

blobs:
- provider: s3
region: "{{ .Env.AWS_REGION }}"
bucket: "{{ .Env.AWS_BUCKET }}"
directory: "dagger/releases/{{ .Version }}"
11 changes: 10 additions & 1 deletion releaser/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,16 @@ func (r *Releaser) Publish(
Tag: tag,
}
if !dryRun {
err = r.Dagger.Cli().Publish(ctx, tag, githubOrgName, githubToken, goreleaserKey, awsAccessKeyID, awsSecretAccessKey, awsRegion, awsBucket, artefactsFQDN)
_, err := r.Dagger.Cli().
Publish(tag, goreleaserKey, githubOrgName, dagger.DaggerDevCliPublishOpts{
GithubToken: githubToken,
AwsAccessKeyID: awsAccessKeyID,
AwsSecretAccessKey: awsSecretAccessKey,
AwsRegion: awsRegion,
AwsBucket: awsBucket,
ArtefactsFqdn: artefactsFQDN,
}).
Sync(ctx)
if err != nil {
artifact.Errors = append(artifact.Errors, dag.Error(err.Error()))
}
Expand Down

0 comments on commit 2699209

Please sign in to comment.