forked from akuity/kargo-render
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Kent Rancourt <kent.rancourt@gmail.com>
- Loading branch information
Showing
15 changed files
with
436 additions
and
463 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
|
||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
|
||
render "github.com/akuity/kargo-render" | ||
libLog "github.com/akuity/kargo-render/internal/log" | ||
libOS "github.com/akuity/kargo-render/internal/os" | ||
"github.com/akuity/kargo-render/internal/version" | ||
) | ||
|
||
type actionOptions struct { | ||
logger *log.Logger | ||
} | ||
|
||
func newActionCommand() *cobra.Command { | ||
cmdOpts := &actionOptions{ | ||
logger: libLog.LoggerOrDie(), | ||
} | ||
|
||
return &cobra.Command{ | ||
Use: "action", | ||
Hidden: true, | ||
Args: cobra.NoArgs, | ||
RunE: func(cmd *cobra.Command, _ []string) error { | ||
return cmdOpts.run(cmd.Context(), cmd.OutOrStdout()) | ||
}, | ||
} | ||
} | ||
|
||
// run performs manifest rendering in a GitHub Actions-compatible manner. | ||
func (o *actionOptions) run(_ context.Context, out io.Writer) error { | ||
logger := o.logger | ||
|
||
ver := version.GetVersion() | ||
logger.WithFields(log.Fields{ | ||
"version": ver.Version, | ||
"commit": ver.GitCommit, | ||
}).Info("Starting Kargo Render Action") | ||
|
||
req, err := request() | ||
if err != nil { | ||
logger.Fatal(err) | ||
} | ||
|
||
res, err := render.NewService( | ||
&render.ServiceOptions{ | ||
LogLevel: render.LogLevel(logger.Level), | ||
}, | ||
).RenderManifests(context.Background(), req) | ||
if err != nil { | ||
logger.Fatal(err) | ||
} | ||
|
||
switch res.ActionTaken { | ||
case render.ActionTakenNone: | ||
fmt.Fprintln( | ||
out, | ||
"\nThis request would not change any state. No action was taken.", | ||
) | ||
case render.ActionTakenOpenedPR: | ||
fmt.Fprintf( | ||
out, | ||
"\nOpened PR %s\n", | ||
res.PullRequestURL, | ||
) | ||
case render.ActionTakenPushedDirectly: | ||
fmt.Fprintf( | ||
out, | ||
"\nCommitted %s to branch %s\n", | ||
res.CommitID, | ||
req.TargetBranch, | ||
) | ||
case render.ActionTakenUpdatedPR: | ||
fmt.Fprintf( | ||
out, | ||
"\nUpdated an existing PR to %s\n", | ||
req.TargetBranch, | ||
) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func request() (render.Request, error) { | ||
req := render.Request{ | ||
RepoCreds: render.RepoCredentials{ | ||
Username: "git", | ||
}, | ||
Images: libOS.GetStringSliceFromEnvVar("INPUT_IMAGES", nil), | ||
} | ||
repo, err := libOS.GetRequiredEnvVar("GITHUB_REPOSITORY") | ||
if err != nil { | ||
return req, err | ||
} | ||
req.RepoURL = fmt.Sprintf("https://github.com/%s", repo) | ||
if req.RepoCreds.Password, err = | ||
libOS.GetRequiredEnvVar("INPUT_PERSONALACCESSTOKEN"); err != nil { | ||
return req, err | ||
} | ||
if req.Ref, err = libOS.GetRequiredEnvVar("GITHUB_SHA"); err != nil { | ||
return req, err | ||
} | ||
req.TargetBranch, err = libOS.GetRequiredEnvVar("INPUT_TARGETBRANCH") | ||
return req, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package action | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.