Skip to content

Commit

Permalink
feat: add published tag
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-timothy-albert committed Nov 19, 2024
1 parent c4e00e6 commit 6e18b3c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
10 changes: 9 additions & 1 deletion internal/actions/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ func addCurrentBranchTagging(g *git.Git, latestRelease map[string]releases.Langu
}

var sources, targets []string
// a tag that is applied if the target contributing is published
var isPublished bool
branch := strings.TrimPrefix(os.Getenv("GITHUB_REF"), "refs/heads/")
workflow, err := configuration.GetWorkflowAndValidateLanguages(true)
if err != nil {
Expand All @@ -172,6 +174,7 @@ func addCurrentBranchTagging(g *git.Git, latestRelease map[string]releases.Langu
// the tagging library treats targets synonymously with code samples
if specificTarget := environment.SpecifiedTarget(); specificTarget != "" {
if target, ok := workflow.Targets[specificTarget]; ok {
isPublished = target.IsPublished()
if source, ok := workflow.Sources[target.Source]; ok && source.Registry != nil {
sources = append(sources, target.Source)
}
Expand Down Expand Up @@ -206,6 +209,7 @@ func addCurrentBranchTagging(g *git.Git, latestRelease map[string]releases.Langu
}

if targetIsMatched {
isPublished = isPublished || target.IsPublished()
if source, ok := workflow.Sources[target.Source]; ok && source.Registry != nil {
sources = append(sources, target.Source)
}
Expand All @@ -219,7 +223,11 @@ func addCurrentBranchTagging(g *git.Git, latestRelease map[string]releases.Langu
}

if (len(sources) > 0 || len(targets) > 0) && branch != "" {
return cli.Tag([]string{branch}, sources, targets)
tags := []string{branch}
if isPublished {
tags = append(tags, "published")
}
return cli.Tag(tags, sources, targets)
}

return nil
Expand Down
8 changes: 8 additions & 0 deletions internal/actions/runWorkflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,12 @@ func addDirectModeBranchTagging() error {
branch := strings.TrimPrefix(os.Getenv("GITHUB_REF"), "refs/heads/")

var sources, targets []string
// a tag that is applied if the target contributing is published
var isPublished bool
// the tagging library treats targets synonymously with code samples
if specificTarget := environment.SpecifiedTarget(); specificTarget != "" {
if target, ok := wf.Targets[specificTarget]; ok {
isPublished = target.IsPublished()
if source, ok := wf.Sources[target.Source]; ok && source.Registry != nil {
sources = append(sources, target.Source)
}
Expand All @@ -317,6 +320,7 @@ func addDirectModeBranchTagging() error {
}
} else {
for name, target := range wf.Targets {
isPublished = isPublished || target.IsPublished()
if source, ok := wf.Sources[target.Source]; ok && source.Registry != nil {
sources = append(sources, target.Source)
}
Expand All @@ -327,6 +331,10 @@ func addDirectModeBranchTagging() error {
}
}
if (len(sources) > 0 || len(targets) > 0) && branch != "" {
tags := []string{branch}
if isPublished {
tags = append(tags, "published")
}
return cli.Tag([]string{branch}, sources, targets)
}

Expand Down

0 comments on commit 6e18b3c

Please sign in to comment.