From 57e87e9313cfe9721eba1799104819c9286e6702 Mon Sep 17 00:00:00 2001 From: Ryan Albert <42415738+ryan-timothy-albert@users.noreply.github.com> Date: Thu, 14 Nov 2024 12:15:11 -0800 Subject: [PATCH] fix: accurate github tagging (#188) * fix: accurate github tagging * feat: update --- internal/actions/runWorkflow.go | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/internal/actions/runWorkflow.go b/internal/actions/runWorkflow.go index d618ddd..72fef9d 100644 --- a/internal/actions/runWorkflow.go +++ b/internal/actions/runWorkflow.go @@ -85,6 +85,10 @@ func RunWorkflow() error { } }() + if branchName != "" { + os.Setenv("SPEAKEASY_ACTIVE_BRANCH", branchName) + } + runRes, outputs, err := run.Run(g, pr, wf) if err != nil { if err := setOutputs(outputs); err != nil { @@ -278,12 +282,44 @@ func finalize(inputs finalizeInputs) error { } } + // add merging branch registry tag + if err = addDirectModeBranchTagging(); err != nil { + logging.Debug("failed to tag registry images: %v", err) + } + inputs.Outputs["commit_hash"] = commitHash } return nil } +func addDirectModeBranchTagging() error { + wf, err := configuration.GetWorkflowAndValidateLanguages(true) + if err != nil { + return err + } + + branch := strings.TrimPrefix(os.Getenv("GITHUB_REF"), "refs/heads/") + + var sources, targets []string + if specificTarget := environment.SpecifiedTarget(); specificTarget != "" { + if target, ok := wf.Targets[environment.SpecifiedTarget()]; ok { + sources = append(sources, target.Source) + targets = append(targets, specificTarget) + } + } else { + for name, target := range wf.Targets { + sources = append(sources, target.Source) + targets = append(targets, name) + } + } + if len(sources) > 0 && len(targets) > 0 && branch != "" { + return cli.Tag([]string{branch}, sources, targets) + } + + return nil +} + func getReleasesInfo() (*releases.ReleasesInfo, error) { releasesDir, err := getReleasesDir() if err != nil {