Skip to content

Commit 0cc67b8

Browse files
Zettat123wolfogre
authored andcommitted
Support cloning remote actions from insecure Gitea instances (#92)
Related to go-gitea/gitea#28693 Reviewed-on: https://gitea.com/gitea/act/pulls/92 Reviewed-by: Jason Song <[email protected]> Co-authored-by: Zettat123 <[email protected]> Co-committed-by: Zettat123 <[email protected]>
1 parent 7e20ddf commit 0cc67b8

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

pkg/common/git/git.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ type NewGitCloneExecutorInput struct {
226226
Dir string
227227
Token string
228228
OfflineMode bool
229+
230+
// For Gitea
231+
InsecureSkipTLS bool
229232
}
230233

231234
// CloneIfRequired ...
@@ -247,6 +250,8 @@ func CloneIfRequired(ctx context.Context, refName plumbing.ReferenceName, input
247250
cloneOptions := git.CloneOptions{
248251
URL: input.URL,
249252
Progress: progressWriter,
253+
254+
InsecureSkipTLS: input.InsecureSkipTLS, // For Gitea
250255
}
251256
if input.Token != "" {
252257
cloneOptions.Auth = &http.BasicAuth{
@@ -308,6 +313,11 @@ func NewGitCloneExecutor(input NewGitCloneExecutorInput) common.Executor {
308313
// fetch latest changes
309314
fetchOptions, pullOptions := gitOptions(input.Token)
310315

316+
if input.InsecureSkipTLS { // For Gitea
317+
fetchOptions.InsecureSkipTLS = true
318+
pullOptions.InsecureSkipTLS = true
319+
}
320+
311321
if !isOfflineMode {
312322
err = r.Fetch(&fetchOptions)
313323
if err != nil && !errors.Is(err, git.NoErrAlreadyUpToDate) {

pkg/runner/runner.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ type Config struct {
7272
PlatformPicker func(labels []string) string // platform picker, it will take precedence over Platforms if isn't nil
7373
JobLoggerLevel *log.Level // the level of job logger
7474
ValidVolumes []string // only volumes (and bind mounts) in this slice can be mounted on the job container or service containers
75+
InsecureSkipTLS bool // whether to skip verifying TLS certificate of the Gitea instance
7576
}
7677

7778
// GetToken: Adapt to Gitea

pkg/runner/step_action_remote.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ func (sar *stepActionRemote) prepareActionExecutor() common.Executor {
121121
But for Gitea, tasks triggered by a.com can clone actions from b.com.
122122
*/
123123
OfflineMode: sar.RunContext.Config.ActionOfflineMode,
124+
125+
InsecureSkipTLS: sar.cloneSkipTLS(), // For Gitea
124126
})
125127
var ntErr common.Executor
126128
if err := gitClone(ctx); err != nil {
@@ -258,6 +260,22 @@ func (sar *stepActionRemote) getCompositeSteps() *compositeSteps {
258260
return sar.compositeSteps
259261
}
260262

263+
// For Gitea
264+
// cloneSkipTLS returns true if the runner can clone an action from the Gitea instance
265+
func (sar *stepActionRemote) cloneSkipTLS() bool {
266+
if !sar.RunContext.Config.InsecureSkipTLS {
267+
// Return false if the Gitea instance is not an insecure instance
268+
return false
269+
}
270+
if sar.remoteAction.URL == "" {
271+
// Empty URL means the default action instance should be used
272+
// Return true if the URL of the Gitea instance is the same as the URL of the default action instance
273+
return sar.RunContext.Config.DefaultActionInstance == sar.RunContext.Config.GitHubInstance
274+
}
275+
// Return true if the URL of the remote action is the same as the URL of the Gitea instance
276+
return sar.remoteAction.URL == sar.RunContext.Config.GitHubInstance
277+
}
278+
261279
type remoteAction struct {
262280
URL string
263281
Org string

0 commit comments

Comments
 (0)