diff options
author | TKaxv_7S <954067342@qq.com> | 2024-01-20 01:20:15 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-20 01:20:15 +0100 |
commit | f055d4ae607a1d68695bbee1d9b444d3056fb387 (patch) | |
tree | b18cb06c80d29a8bf2551c112d7457ed38a5bd76 /pkg | |
parent | feat: cli option to enable the new action cache (#1954) (diff) | |
download | forgejo-act-f055d4ae607a1d68695bbee1d9b444d3056fb387.tar.xz forgejo-act-f055d4ae607a1d68695bbee1d9b444d3056fb387.zip |
feat: support offline mode (#2128)
* Add: Actions Offline Mode
* Add: Actions Offline Mode
---------
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/common/git/git.go | 26 | ||||
-rw-r--r-- | pkg/runner/reusable_workflow.go | 9 | ||||
-rw-r--r-- | pkg/runner/runner.go | 1 | ||||
-rw-r--r-- | pkg/runner/step_action_remote.go | 9 |
4 files changed, 27 insertions, 18 deletions
diff --git a/pkg/common/git/git.go b/pkg/common/git/git.go index bf77155..0a819b9 100644 --- a/pkg/common/git/git.go +++ b/pkg/common/git/git.go @@ -221,10 +221,11 @@ func findGitSlug(url string, githubInstance string) (string, string, error) { // NewGitCloneExecutorInput the input for the NewGitCloneExecutor type NewGitCloneExecutorInput struct { - URL string - Ref string - Dir string - Token string + URL string + Ref string + Dir string + Token string + OfflineMode bool } // CloneIfRequired ... @@ -302,12 +303,16 @@ func NewGitCloneExecutor(input NewGitCloneExecutorInput) common.Executor { return err } + isOfflineMode := input.OfflineMode + // fetch latest changes fetchOptions, pullOptions := gitOptions(input.Token) - err = r.Fetch(&fetchOptions) - if err != nil && !errors.Is(err, git.NoErrAlreadyUpToDate) { - return err + if !isOfflineMode { + err = r.Fetch(&fetchOptions) + if err != nil && !errors.Is(err, git.NoErrAlreadyUpToDate) { + return err + } } var hash *plumbing.Hash @@ -367,9 +372,10 @@ func NewGitCloneExecutor(input NewGitCloneExecutorInput) common.Executor { return err } } - - if err = w.Pull(&pullOptions); err != nil && err != git.NoErrAlreadyUpToDate { - logger.Debugf("Unable to pull %s: %v", refName, err) + if !isOfflineMode { + if err = w.Pull(&pullOptions); err != nil && err != git.NoErrAlreadyUpToDate { + logger.Debugf("Unable to pull %s: %v", refName, err) + } } logger.Debugf("Cloned %s to %s", input.URL, input.Dir) diff --git a/pkg/runner/reusable_workflow.go b/pkg/runner/reusable_workflow.go index b5e3d5b..7ce68e9 100644 --- a/pkg/runner/reusable_workflow.go +++ b/pkg/runner/reusable_workflow.go @@ -102,10 +102,11 @@ func cloneIfRequired(rc *RunContext, remoteReusableWorkflow remoteReusableWorkfl func(ctx context.Context) error { remoteReusableWorkflow.URL = rc.getGithubContext(ctx).ServerURL return git.NewGitCloneExecutor(git.NewGitCloneExecutorInput{ - URL: remoteReusableWorkflow.CloneURL(), - Ref: remoteReusableWorkflow.Ref, - Dir: targetDirectory, - Token: rc.Config.Token, + URL: remoteReusableWorkflow.CloneURL(), + Ref: remoteReusableWorkflow.Ref, + Dir: targetDirectory, + Token: rc.Config.Token, + OfflineMode: rc.Config.ActionOfflineMode, })(ctx) }, nil, diff --git a/pkg/runner/runner.go b/pkg/runner/runner.go index 5a7b1ad..dd8afe5 100644 --- a/pkg/runner/runner.go +++ b/pkg/runner/runner.go @@ -23,6 +23,7 @@ type Config struct { Actor string // the user that triggered the event Workdir string // path to working directory ActionCacheDir string // path used for caching action contents + ActionOfflineMode bool // when offline, use caching action contents BindWorkdir bool // bind the workdir to the job container EventName string // name of event to run EventPath string // path to JSON file to use for event.json in containers diff --git a/pkg/runner/step_action_remote.go b/pkg/runner/step_action_remote.go index 4019388..5c8a8f2 100644 --- a/pkg/runner/step_action_remote.go +++ b/pkg/runner/step_action_remote.go @@ -106,10 +106,11 @@ func (sar *stepActionRemote) prepareActionExecutor() common.Executor { actionDir := fmt.Sprintf("%s/%s", sar.RunContext.ActionCacheDir(), safeFilename(sar.Step.Uses)) gitClone := stepActionRemoteNewCloneExecutor(git.NewGitCloneExecutorInput{ - URL: sar.remoteAction.CloneURL(), - Ref: sar.remoteAction.Ref, - Dir: actionDir, - Token: github.Token, + URL: sar.remoteAction.CloneURL(), + Ref: sar.remoteAction.Ref, + Dir: actionDir, + Token: github.Token, + OfflineMode: sar.RunContext.Config.ActionOfflineMode, }) var ntErr common.Executor if err := gitClone(ctx); err != nil { |