diff options
| author | Xe Iaso <me@xeiaso.net> | 2025-03-21 10:34:01 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-21 10:34:01 -0400 |
| commit | 95dddb554920be465c2760e730a14d24ea3b57f3 (patch) | |
| tree | 89e69c9c96e73a0a6f4f6235f845d7e0feddd719 /cmd | |
| parent | 86b8c6c5f23d3a1a0a0ccf737ad0eccad78d5566 (diff) | |
| download | anubis-95dddb554920be465c2760e730a14d24ea3b57f3.tar.xz anubis-95dddb554920be465c2760e730a14d24ea3b57f3.zip | |
cmd/containerbuild: default to ttl.sh for third party contributions (#51)
* cmd/containerbuild: default to ttl.sh for third party contributions
Closes #48
Signed-off-by: Xe Iaso <me@xeiaso.net>
* track comment tags
Signed-off-by: Xe Iaso <me@xeiaso.net>
* empty commit to make sure double-commenting doesn't work
Signed-off-by: Xe Iaso <me@xeiaso.net>
---------
Signed-off-by: Xe Iaso <me@xeiaso.net>
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/containerbuild/main.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/cmd/containerbuild/main.go b/cmd/containerbuild/main.go index e99dee5..022cb7b 100644 --- a/cmd/containerbuild/main.go +++ b/cmd/containerbuild/main.go @@ -19,9 +19,25 @@ var ( dockerLabels = flag.String("docker-labels", os.Getenv("DOCKER_METADATA_OUTPUT_LABELS"), "Docker image labels") dockerRepo = flag.String("docker-repo", "registry.int.xeserv.us/techaro/anubis", "Docker image repository for Anubis") dockerTags = flag.String("docker-tags", os.Getenv("DOCKER_METADATA_OUTPUT_TAGS"), "newline separated docker tags including the registry name") + githubActor = flag.String("github-actor", "", "GitHub actor") + githubEventName = flag.String("github-event-name", "", "GitHub event name") + pullRequestID = flag.Int("pull-request-id", -1, "GitHub pull request ID") slogLevel = flag.String("slog-level", "INFO", "logging level (see https://pkg.go.dev/log/slog#hdr-Levels)") + + knownContributors = []string{ + "Xe", + } ) +func inList(needle string, haystack []string) bool { + for _, h := range haystack { + if h == needle { + return true + } + } + return false +} + func main() { flagenv.Parse() flag.Parse() @@ -29,6 +45,27 @@ func main() { internal.InitSlog(*slogLevel) koDockerRepo := strings.TrimRight(*dockerRepo, "/"+filepath.Base(*dockerRepo)) + + if *githubEventName == "pull_request" && !inList(*githubActor, knownContributors) { + if *pullRequestID == -1 { + log.Fatal("Must set --pull-request-id when --github-event-name=pull_request") + } + + *dockerRepo = fmt.Sprintf("ttl.sh/techaro/pr-%d/anubis", *pullRequestID) + *dockerTags = fmt.Sprintf("ttl.sh/techaro/pr-%d/anubis:24h", *pullRequestID) + koDockerRepo = fmt.Sprintf("ttl.sh/techaro/pr-%d", *pullRequestID) + + slog.Info( + "Building image for pull request", + "docker-repo", *dockerRepo, + "docker-tags", *dockerTags, + "github-event-name", *githubEventName, + "pull-request-id", *pullRequestID, + ) + } + + setOutput("docker_image", strings.SplitN(*dockerTags, "\n", 2)[0]) + version, err := run("git describe --tags --always --dirty") if err != nil { log.Fatal(err) @@ -129,6 +166,7 @@ func run(command string) (string, error) { if err != nil { return "", err } + slog.Debug("running command", "command", command) cmd := exec.Command(bin, "-c", command) cmd.Stderr = os.Stderr out, err := cmd.Output() |
