Skip to content

Commit 3a9e7d1

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 b4edc95 commit 3a9e7d1

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
@@ -225,6 +225,9 @@ type NewGitCloneExecutorInput struct {
225225
Ref string
226226
Dir string
227227
Token string
228+
229+
// For Gitea
230+
InsecureSkipTLS bool
228231
}
229232

230233
// CloneIfRequired ...
@@ -246,6 +249,8 @@ func CloneIfRequired(ctx context.Context, refName plumbing.ReferenceName, input
246249
cloneOptions := git.CloneOptions{
247250
URL: input.URL,
248251
Progress: progressWriter,
252+
253+
InsecureSkipTLS: input.InsecureSkipTLS, // For Gitea
249254
}
250255
if input.Token != "" {
251256
cloneOptions.Auth = &http.BasicAuth{
@@ -305,6 +310,11 @@ func NewGitCloneExecutor(input NewGitCloneExecutorInput) common.Executor {
305310
// fetch latest changes
306311
fetchOptions, pullOptions := gitOptions(input.Token)
307312

313+
if input.InsecureSkipTLS { // For Gitea
314+
fetchOptions.InsecureSkipTLS = true
315+
pullOptions.InsecureSkipTLS = true
316+
}
317+
308318
err = r.Fetch(&fetchOptions)
309319
if err != nil && !errors.Is(err, git.NoErrAlreadyUpToDate) {
310320
return err

pkg/runner/runner.go

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

7576
// GetToken: Adapt to Gitea

pkg/runner/step_action_remote.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ func (sar *stepActionRemote) prepareActionExecutor() common.Executor {
7575
For GitHub, they are the same, always github.com.
7676
But for Gitea, tasks triggered by a.com can clone actions from b.com.
7777
*/
78+
79+
InsecureSkipTLS: sar.cloneSkipTLS(), // For Gitea
7880
})
7981
var ntErr common.Executor
8082
if err := gitClone(ctx); err != nil {
@@ -212,6 +214,22 @@ func (sar *stepActionRemote) getCompositeSteps() *compositeSteps {
212214
return sar.compositeSteps
213215
}
214216

217+
// For Gitea
218+
// cloneSkipTLS returns true if the runner can clone an action from the Gitea instance
219+
func (sar *stepActionRemote) cloneSkipTLS() bool {
220+
if !sar.RunContext.Config.InsecureSkipTLS {
221+
// Return false if the Gitea instance is not an insecure instance
222+
return false
223+
}
224+
if sar.remoteAction.URL == "" {
225+
// Empty URL means the default action instance should be used
226+
// Return true if the URL of the Gitea instance is the same as the URL of the default action instance
227+
return sar.RunContext.Config.DefaultActionInstance == sar.RunContext.Config.GitHubInstance
228+
}
229+
// Return true if the URL of the remote action is the same as the URL of the Gitea instance
230+
return sar.remoteAction.URL == sar.RunContext.Config.GitHubInstance
231+
}
232+
215233
type remoteAction struct {
216234
URL string
217235
Org string

0 commit comments

Comments
 (0)