-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublish.go
78 lines (69 loc) · 1.77 KB
/
publish.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
package main
import (
"fmt"
"strings"
"github.com/jjs-dev/ci-config-gen/actions"
"github.com/jjs-dev/ci-config-gen/bors"
"github.com/jjs-dev/ci-config-gen/config"
)
func generatePublishImageScript(config config.CiConfig) string {
lines := make([]string, 0)
lines = append(lines, "set -euxo pipefail")
header := `
# GENERATED FILE DO NOT EDIT
if [ "$GITHUB_REF" = "refs/heads/master" ]
then
TAG="latest"
elif [ "$GITHUB_REF" = "refs/heads/trying" ]
then
TAG="dev"
elif [ "$GITHUB_REF" = "refs/heads/staging" ]
then
exit 0
else
echo "unknown GITHUB_REF: $GITHUB_REF"
exit 1
fi
echo $GITHUB_TOKEN | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin`
lines = append(lines, header)
for _, image := range config.DockerImages {
lines = append(lines, fmt.Sprintf("docker tag %s ghcr.io/jjs-dev/%s:$TAG", image, image))
lines = append(lines, fmt.Sprintf("docker push ghcr.io/jjs-dev/%s:$TAG", image))
}
return strings.Join(lines, "\n")
}
func makePublishWorkflow(root string, config config.CiConfig, bc *bors.BorsConfig) actions.Workflow {
publishJob := actions.Job{
RunsOn: actions.UbuntuRunner,
If: "github.event_name == 'push'",
Timeout: config.JobTimeout,
Env: map[string]string{
"GITHUB_TOKEN": "${{ secrets.GITHUB_TOKEN }}",
},
Steps: []actions.Step{
actions.MakeCheckoutStep(),
{
Name: "Build artifacts",
Run: "bash ci/publish-build.sh",
},
{
Name: "Publish docker images",
Run: "bash ci/publish-images.sh",
},
},
}
w := actions.Workflow{
Name: "publish",
On: actions.Trigger{
PullRequest: actions.EmptyStruct{},
Push: actions.PushTrigger{
Branches: []string{"staging", "trying", "master"},
},
},
Jobs: map[string]actions.Job{
"publish": publishJob,
},
}
bc.AddJob("publish")
return w
}