@@ -27,21 +27,21 @@ import (
2727
2828 "github.com/go-git/go-billy/v5"
2929 "github.com/go-git/go-billy/v5/memfs"
30+ "github.com/go-git/go-billy/v5/osfs"
3031 "github.com/go-git/go-git/v5"
3132 "github.com/go-git/go-git/v5/plumbing/transport/http"
3233 "github.com/go-git/go-git/v5/storage/memory"
3334 "github.com/google/go-github/v60/github"
3435 "github.com/stacklok/frizbee/pkg/replacer"
3536 "github.com/stacklok/frizbee/pkg/utils/config"
36- "golang.org/x/oauth2"
3737
3838 "github.com/stacklok/frizbee-action/pkg/action"
3939)
4040
4141func main () {
4242 ctx := context .Background ()
4343 // Initialize the frizbee action
44- frizbeeAction , err := initAction (ctx )
44+ frizbeeAction , err := initAction ()
4545 if err != nil {
4646 log .Fatalf ("Error initializing action: %v" , err )
4747 }
@@ -58,16 +58,13 @@ func main() {
5858}
5959
6060// initAction initializes the frizbee action - reads the environment variables, creates the GitHub client, etc.
61- func initAction (ctx context.Context ) (* action.FrizbeeAction , error ) {
61+ func initAction () (* action.FrizbeeAction , error ) {
62+ var repo * git.Repository
63+ var fs billy.Filesystem
64+ var githubClient * github.Client
65+
6266 // Get the GitHub token from the environment
6367 token := os .Getenv ("GITHUB_TOKEN" )
64- if token == "" {
65- return nil , errors .New ("GITHUB_TOKEN environment variable is not set" )
66- }
67-
68- // Create a new GitHub client
69- ts := oauth2 .StaticTokenSource (& oauth2.Token {AccessToken : token })
70- tc := oauth2 .NewClient (ctx , ts )
7168
7269 // Get the GITHUB_REPOSITORY_OWNER
7370 repoOwner := os .Getenv ("GITHUB_REPOSITORY_OWNER" )
@@ -81,10 +78,28 @@ func initAction(ctx context.Context) (*action.FrizbeeAction, error) {
8178 return nil , errors .New ("GITHUB_REPOSITORY environment variable is not set" )
8279 }
8380
84- // Clone the repository
85- fs , repo , err := cloneRepository ("https://github.com/" + repoFullName , repoOwner , token )
86- if err != nil {
87- return nil , fmt .Errorf ("failed to clone repository: %w" , err )
81+ repoRoot := os .Getenv ("INPUT_REPO_ROOT" )
82+ if repoRoot == "" {
83+ if token == "" {
84+ return nil , errors .New ("GITHUB_TOKEN environment variable is not set" )
85+ }
86+
87+ // Create a new GitHub client
88+ githubClient = github .NewClient (nil ).WithAuthToken (token )
89+
90+ // Clone the repository
91+ var err error
92+ fs , repo , err = cloneRepository ("https://github.com/" + repoFullName , repoOwner , token )
93+ if err != nil {
94+ return nil , fmt .Errorf ("failed to clone repository: %w" , err )
95+ }
96+ } else {
97+ fs = osfs .New (repoRoot )
98+ var err error
99+ repo , err = git .PlainOpen (repoRoot )
100+ if err != nil {
101+ return nil , fmt .Errorf ("failed to open repository: %w" , err )
102+ }
88103 }
89104
90105 cfg := config .DefaultConfig ()
@@ -105,14 +120,19 @@ func initAction(ctx context.Context) (*action.FrizbeeAction, error) {
105120 cfg .Images .ExcludeTags = valToStrings (excludeTags )
106121 }
107122
123+ actionsPathList , err := actionsPathList ()
124+ if err != nil {
125+ return nil , err
126+ }
127+
108128 // Read the action settings from the environment and create the new frizbee replacers for actions and images
109129 return & action.FrizbeeAction {
110- Client : github . NewClient ( tc ) ,
130+ Client : githubClient ,
111131 Token : token ,
112132 RepoOwner : repoOwner ,
113133 RepoName : strings .TrimPrefix (repoFullName , repoOwner + "/" ),
114134
115- ActionsPath : os . Getenv ( "INPUT_ACTIONS" ) ,
135+ ActionsPaths : actionsPathList ,
116136 DockerfilesPaths : envToStrings ("INPUT_DOCKERFILES" ),
117137 KubernetesPaths : envToStrings ("INPUT_KUBERNETES" ),
118138 DockerComposePaths : envToStrings ("INPUT_DOCKER_COMPOSE" ),
@@ -162,3 +182,19 @@ func valToStrings(val string) []string {
162182
163183 return vals
164184}
185+
186+ func actionsPathList () ([]string , error ) {
187+ actions := os .Getenv ("INPUT_ACTIONS" )
188+ actionsPaths := os .Getenv ("INPUT_ACTIONS_PATHS" )
189+ if actions != "" && actionsPaths != "" {
190+ return nil , errors .New ("cannot set both INPUT_ACTIONS and INPUT_ACTIONS_PATHS" )
191+ } else if actions == "" && actionsPaths == "" {
192+ // Default for actions was `.github/workflows``
193+ actions = ".github/workflows"
194+ }
195+
196+ if actions != "" {
197+ return []string {actions }, nil
198+ }
199+ return valToStrings (actionsPaths ), nil
200+ }
0 commit comments