Compare commits

..

3 Commits

Author SHA1 Message Date
Jason Song
8ba56a0363 Remove emojis in command outputs (#97)
Remove emojis in command outputs; leave others since they don't matter.

Help https://github.com/go-gitea/gitea/pull/29777

Reviewed-on: https://gitea.com/gitea/act/pulls/97
2024-03-14 10:01:39 +00:00
Zettat123
0cc67b8817 Support cloning remote actions from insecure Gitea instances (#92)
Related to https://github.com/go-gitea/gitea/issues/28693

Reviewed-on: https://gitea.com/gitea/act/pulls/92
Reviewed-by: Jason Song <i@wolfogre.com>
Co-authored-by: Zettat123 <zettat123@gmail.com>
Co-committed-by: Zettat123 <zettat123@gmail.com>
2024-03-05 08:07:29 +00:00
Claudio Nicora
7e20ddf928 Patched options() to let container options propagate to job containers (#80)
This PR let "general" container config to be propagated to each job container.

See:
- https://gitea.com/gitea/act_runner/issues/265#issuecomment-744382
- https://gitea.com/gitea/act_runner/issues/79
- https://gitea.com/gitea/act_runner/issues/378

Reviewed-on: https://gitea.com/gitea/act/pulls/80
Reviewed-by: Jason Song <i@wolfogre.com>
Co-authored-by: Claudio Nicora <claudio.nicora@gmail.com>
Co-committed-by: Claudio Nicora <claudio.nicora@gmail.com>
2024-03-04 02:56:52 +00:00
5 changed files with 51 additions and 14 deletions

View File

@@ -226,6 +226,9 @@ type NewGitCloneExecutorInput struct {
Dir string
Token string
OfflineMode bool
// For Gitea
InsecureSkipTLS bool
}
// CloneIfRequired ...
@@ -247,6 +250,8 @@ func CloneIfRequired(ctx context.Context, refName plumbing.ReferenceName, input
cloneOptions := git.CloneOptions{
URL: input.URL,
Progress: progressWriter,
InsecureSkipTLS: input.InsecureSkipTLS, // For Gitea
}
if input.Token != "" {
cloneOptions.Auth = &http.BasicAuth{
@@ -308,6 +313,11 @@ func NewGitCloneExecutor(input NewGitCloneExecutorInput) common.Executor {
// fetch latest changes
fetchOptions, pullOptions := gitOptions(input.Token)
if input.InsecureSkipTLS { // For Gitea
fetchOptions.InsecureSkipTLS = true
pullOptions.InsecureSkipTLS = true
}
if !isOfflineMode {
err = r.Fetch(&fetchOptions)
if err != nil && !errors.Is(err, git.NoErrAlreadyUpToDate) {

View File

@@ -9,6 +9,7 @@ import (
)
var commandPatternGA *regexp.Regexp
var commandPatternADO *regexp.Regexp
func init() {
@@ -41,7 +42,9 @@ func (rc *RunContext) commandHandler(ctx context.Context) common.LineHandler {
}
if resumeCommand != "" && command != resumeCommand {
logger.Infof(" \U00002699 %s", line)
// There should not be any emojis in the log output for Gitea.
// The code in the switch statement is the same.
logger.Infof("%s", line)
return false
}
arg = unescapeCommandData(arg)
@@ -54,27 +57,27 @@ func (rc *RunContext) commandHandler(ctx context.Context) common.LineHandler {
case "add-path":
rc.addPath(ctx, arg)
case "debug":
logger.Infof(" \U0001F4AC %s", line)
logger.Infof("%s", line)
case "warning":
logger.Infof(" \U0001F6A7 %s", line)
logger.Infof("%s", line)
case "error":
logger.Infof(" \U00002757 %s", line)
logger.Infof("%s", line)
case "add-mask":
rc.AddMask(arg)
logger.Infof(" \U00002699 %s", "***")
logger.Infof("%s", "***")
case "stop-commands":
resumeCommand = arg
logger.Infof(" \U00002699 %s", line)
logger.Infof("%s", line)
case resumeCommand:
resumeCommand = ""
logger.Infof(" \U00002699 %s", line)
logger.Infof("%s", line)
case "save-state":
logger.Infof(" \U0001f4be %s", line)
logger.Infof("%s", line)
rc.saveState(ctx, kvPairs, arg)
case "add-matcher":
logger.Infof(" \U00002753 add-matcher %s", arg)
logger.Infof("%s", line)
default:
logger.Infof(" \U00002753 %s", line)
logger.Infof("%s", line)
}
// return true to let gitea's logger handle these special outputs also
@@ -84,7 +87,7 @@ func (rc *RunContext) commandHandler(ctx context.Context) common.LineHandler {
func (rc *RunContext) setEnv(ctx context.Context, kvPairs map[string]string, arg string) {
name := kvPairs["name"]
common.Logger(ctx).Infof(" \U00002699 ::set-env:: %s=%s", name, arg)
common.Logger(ctx).Infof("::set-env:: %s=%s", name, arg)
if rc.Env == nil {
rc.Env = make(map[string]string)
}
@@ -101,6 +104,7 @@ func (rc *RunContext) setEnv(ctx context.Context, kvPairs map[string]string, arg
mergeIntoMap(rc.Env, newenv)
mergeIntoMap(rc.GlobalEnv, newenv)
}
func (rc *RunContext) setOutput(ctx context.Context, kvPairs map[string]string, arg string) {
logger := common.Logger(ctx)
stepID := rc.CurrentStep
@@ -116,11 +120,12 @@ func (rc *RunContext) setOutput(ctx context.Context, kvPairs map[string]string,
return
}
logger.Infof(" \U00002699 ::set-output:: %s=%s", outputName, arg)
logger.Infof("::set-output:: %s=%s", outputName, arg)
result.Outputs[outputName] = arg
}
func (rc *RunContext) addPath(ctx context.Context, arg string) {
common.Logger(ctx).Infof(" \U00002699 ::add-path:: %s", arg)
common.Logger(ctx).Infof("::add-path:: %s", arg)
extraPath := []string{arg}
for _, v := range rc.ExtraPath {
if v != arg {
@@ -141,6 +146,7 @@ func parseKeyValuePairs(kvPairs string, separator string) map[string]string {
}
return rtn
}
func unescapeCommandData(arg string) string {
escapeMap := map[string]string{
"%25": "%",
@@ -152,6 +158,7 @@ func unescapeCommandData(arg string) string {
}
return arg
}
func unescapeCommandProperty(arg string) string {
escapeMap := map[string]string{
"%25": "%",
@@ -165,6 +172,7 @@ func unescapeCommandProperty(arg string) string {
}
return arg
}
func unescapeKvPairs(kvPairs map[string]string) map[string]string {
for k, v := range kvPairs {
kvPairs[k] = unescapeCommandProperty(v)

View File

@@ -717,7 +717,7 @@ func (rc *RunContext) options(ctx context.Context) string {
job := rc.Run.Job()
c := job.Container()
if c != nil {
return rc.ExprEval.Interpolate(ctx, c.Options)
return rc.Config.ContainerOptions + " " + rc.ExprEval.Interpolate(ctx, c.Options)
}
return rc.Config.ContainerOptions

View File

@@ -72,6 +72,7 @@ type Config struct {
PlatformPicker func(labels []string) string // platform picker, it will take precedence over Platforms if isn't nil
JobLoggerLevel *log.Level // the level of job logger
ValidVolumes []string // only volumes (and bind mounts) in this slice can be mounted on the job container or service containers
InsecureSkipTLS bool // whether to skip verifying TLS certificate of the Gitea instance
}
// GetToken: Adapt to Gitea

View File

@@ -121,6 +121,8 @@ func (sar *stepActionRemote) prepareActionExecutor() common.Executor {
But for Gitea, tasks triggered by a.com can clone actions from b.com.
*/
OfflineMode: sar.RunContext.Config.ActionOfflineMode,
InsecureSkipTLS: sar.cloneSkipTLS(), // For Gitea
})
var ntErr common.Executor
if err := gitClone(ctx); err != nil {
@@ -258,6 +260,22 @@ func (sar *stepActionRemote) getCompositeSteps() *compositeSteps {
return sar.compositeSteps
}
// For Gitea
// cloneSkipTLS returns true if the runner can clone an action from the Gitea instance
func (sar *stepActionRemote) cloneSkipTLS() bool {
if !sar.RunContext.Config.InsecureSkipTLS {
// Return false if the Gitea instance is not an insecure instance
return false
}
if sar.remoteAction.URL == "" {
// Empty URL means the default action instance should be used
// Return true if the URL of the Gitea instance is the same as the URL of the default action instance
return sar.RunContext.Config.DefaultActionInstance == sar.RunContext.Config.GitHubInstance
}
// Return true if the URL of the remote action is the same as the URL of the Gitea instance
return sar.remoteAction.URL == sar.RunContext.Config.GitHubInstance
}
type remoteAction struct {
URL string
Org string