Skip to content

Commit

Permalink
Merge pull request #14 from MisterMX/feat/publish-filter-ids
Browse files Browse the repository at this point in the history
feat(release): Add option to push only specific publish sets
  • Loading branch information
MisterMX authored Oct 2, 2024
2 parents 4e6bf46 + d23ae7e commit 4d8bf4d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,34 @@ To just build artifacts:
crossplanereleaser build
```

An example `.crossplanereleaser.yaml` config can look like this

```yaml
project_name: my-project
dist: dist/my-project

builds:
- id: composition-package
dir: package/compositions
examples: examples
- id: function-package
dir: package/function
examples: "IGNORE"
# Use a prebuilt image tar that contains the function binary, i.e. by Ko
runtime_image_tar: dist/function-base-image.tar

pushes:
- build: composition-package
image_templates:
- "my-registry.com/my-project/package-compositions:{{ .Tag }}"
- "my-registry.com/my-project/package-compositions:{{ .FullCommit }}"
- id: function # Used to manually filter for images to be pushed
build: function-package
image_templates:
- "my-registry.com/my-project/package-function:{{ .Tag }}"
- "my-registry.com/my-project/package-function:{{ .FullCommit }}"
```
# Requirements
Crossplanereleaser does not deal packages by itself but instead uses external
Expand Down
18 changes: 17 additions & 1 deletion cmd/crossplanereleaser/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"os"
"slices"

"github.com/google/go-containerregistry/pkg/name"
"github.com/pkg/errors"
Expand All @@ -20,7 +21,8 @@ type releaseCmd struct {
builder build.BuilderBackend
publisher publish.PackagePublisher

Skip string `help:"Specify steps to skip"`
Skip string `help:"Specify steps to skip"`
PushOnlyIDs []string `name:"push-only-ids" help:"Specify the IDs of the pushes that should be published. If not provided all pushes will be published."`
}

func (c *releaseCmd) BeforeApply() error {
Expand Down Expand Up @@ -70,6 +72,10 @@ func (c *releaseCmd) publishPackages(ctx context.Context, cfg *v1.Config) error
}

func (c *releaseCmd) publishPackage(ctx context.Context, cfg *v1.Config, push v1.PushConfig) error {
if !c.shouldBePublished(push) {
return nil
}

build := getBuildConfigByID(cfg, push.Build)
if build == nil {
return errors.Errorf("no build with ID %q", push.Build)
Expand All @@ -96,6 +102,16 @@ func (c *releaseCmd) publishPackage(ctx context.Context, cfg *v1.Config, push v1
return nil
}

func (c *releaseCmd) shouldBePublished(push v1.PushConfig) bool {
if len(c.PushOnlyIDs) == 0 {
return true
}
if push.ID == "" {
return false
}
return slices.Contains(c.PushOnlyIDs, push.ID)
}

func getBuildConfigByID(cfg *v1.Config, buildID string) *v1.BuildConfig {
for _, b := range cfg.Builds {
if b.ID == buildID {
Expand Down
1 change: 1 addition & 0 deletions config/v1/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type BuildConfig struct {
}

type PushConfig struct {
ID string `json:"id"`
Build string `json:"build"`
ImageTemplates []string `json:"image_templates"`
}

0 comments on commit 4d8bf4d

Please sign in to comment.