forked from tubenhirn/dagger-ci-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
semanticrelease.go
81 lines (65 loc) · 2.18 KB
/
semanticrelease.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
74
75
76
77
78
79
80
81
package cimodules
import (
"context"
"errors"
"dagger.io/dagger"
)
type SemanticOpts struct {
Source string
Platform string
Env map[string]string
Secret map[string]dagger.SecretID
Image Image
}
var defaultSemanticreleaseGithubImage = Image{
Name: "tubenhirn/semantic-release-github",
//# renovate: datasource=docker depName=tubenhirn/semantic-release-github versioning=docker
Version: "v4.1.10",
}
var defaultSemanticreleaseGitlabImage = Image{
Name: "tubenhirn/semantic-release-gitlab",
//# renovate: datasource=docker depName=tubenhirn/semantic-release-gitlab versioning=docker
Version: "v4.1.10",
}
var defaultSemanticreleaseGitImage = Image{
Name: "tubenhirn/semantic-release-git",
//# renovate: datasource=docker depName=tubenhirn/semantic-release-git versioning=docker
Version: "v4.1.10",
}
var defaultSemanticreleaseAzueImage = Image{
Name: "tubenhirn/semantic-release-azdo",
//# renovate: datasource=docker depName=tubenhirn/semantic-release-azdo versioning=docker
Version: "v4.1.10",
}
func semanticrelease(ctx context.Context, client dagger.Client, opts SemanticOpts) error {
sourceDir := client.Host().Directory(opts.Source)
var image string
switch opts.Platform {
case "github":
image = createImageString(defaultSemanticreleaseGithubImage, opts.Image)
case "gitlab":
image = createImageString(defaultSemanticreleaseGitlabImage, opts.Image)
case "git":
image = createImageString(defaultSemanticreleaseGitImage, opts.Image)
case "azure":
image = createImageString(defaultSemanticreleaseAzueImage, opts.Image)
default:
return errors.New("Platform net set.")
}
semanticreleaseImage := client.Container().From(image)
semanticrelease := semanticreleaseImage.WithMountedDirectory("/src", sourceDir)
semanticrelease = semanticrelease.WithWorkdir("/src")
// write env secrets - access-tokens etc.
for key, val := range opts.Secret {
semanticrelease = semanticrelease.WithSecretVariable(key, client.LoadSecretFromID(val))
}
// write dditional env variables
for key, val := range opts.Env {
semanticrelease = semanticrelease.WithEnvVariable(key, val)
}
_, err := semanticrelease.WithExec(nil).Stdout(ctx)
if err != nil {
return err
}
return nil
}