-
Notifications
You must be signed in to change notification settings - Fork 1
/
goreleaser.go
73 lines (58 loc) · 1.72 KB
/
goreleaser.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package cimodules
import (
"context"
"dagger.io/dagger"
)
type GoReleaserOpts struct {
Source string
DryRun bool `default:"false"`
Snapshot bool `default:"false"`
RemoveDist bool `default:"false"`
Env map[string]string
Secret map[string]dagger.SecretID
Image Image
}
var defaultGoreleaserImage = Image{
Name: "goreleaser/goreleaser",
//# renovate: datasource=docker depName=goreleaser/goreleaser versioning=docker
Version: "v1.26.2",
}
func release(ctx context.Context, client dagger.Client, opts GoReleaserOpts) error {
commands := createFlags(opts)
sourceDir := client.Host().Directory(opts.Source)
goreleaser := client.Container().From(createImageString(defaultGoreleaserImage, opts.Image))
goreleaser = goreleaser.WithMountedDirectory("/src", sourceDir)
goreleaser = goreleaser.WithWorkdir("/src")
// write env secrets - access-tokens etc.
for key, val := range opts.Secret {
goreleaser = goreleaser.WithSecretVariable(key, client.LoadSecretFromID(val))
}
// write env variables
for key, val := range opts.Env {
goreleaser = goreleaser.WithEnvVariable(key, val)
}
// set entrypoint
goreleaser = goreleaser.WithEntrypoint([]string{"goreleaser"})
// run the container
goreleaser = goreleaser.WithExec(commands)
// export the build artifacts to the host
_, err := goreleaser.Directory("/src/dist").Export(ctx, opts.Source+"/dist")
if err != nil {
return err
}
return nil
}
func createFlags(opts GoReleaserOpts) []string {
var flags []string
if opts.DryRun {
flags = append(flags, "--skip-publish")
flags = append(flags, "--skip-announce")
}
if opts.Snapshot {
flags = append(flags, "--snapshot")
}
if opts.RemoveDist {
flags = append(flags, "--clean")
}
return flags
}