From cabaab6237824ca926e04d20ad9fdfe7f0cba0b0 Mon Sep 17 00:00:00 2001
From: infinoid <infinoid@noreply.gitea.com>
Date: Fri, 24 Nov 2023 01:56:27 +0000
Subject: [PATCH 1/7] Fix #404: nil map error when reading env file (#405)

Co-authored-by: Mark Glines <mark@glines.org>
Reviewed-on: https://gitea.com/gitea/act_runner/pulls/405
Reviewed-by: Jason Song <i@wolfogre.com>
Co-authored-by: infinoid <infinoid@noreply.gitea.com>
Co-committed-by: infinoid <infinoid@noreply.gitea.com>
(cherry picked from commit 934471813a41efabf6a9b5d5b22a2a5770ff12ce)
---
 internal/pkg/config/config.go | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/internal/pkg/config/config.go b/internal/pkg/config/config.go
index 540c82a..a7bb977 100644
--- a/internal/pkg/config/config.go
+++ b/internal/pkg/config/config.go
@@ -99,6 +99,9 @@ func LoadDefault(file string) (*Config, error) {
 			if err != nil {
 				return nil, fmt.Errorf("read env file %q: %w", cfg.Runner.EnvFile, err)
 			}
+			if cfg.Runner.Envs == nil {
+				cfg.Runner.Envs = map[string]string{}
+			}
 			for k, v := range envs {
 				cfg.Runner.Envs[k] = v
 			}

From 0d5eb12574bc3654dbd464d2c3fa8cf73831af02 Mon Sep 17 00:00:00 2001
From: hakito <hakito@noreply.gitea.com>
Date: Wed, 20 Dec 2023 07:06:46 +0000
Subject: [PATCH 2/7] Sanitize UFT-8 content in logs (#453)

I accidently closed my previous PR #384

This PR replaces invalid UTF-8 character in a stream with `?` character. On Windows Server 2019 other characters are replaced by `?` as well so it's consistent.

fixes #452

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-on: https://gitea.com/gitea/act_runner/pulls/453
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-by: Jason Song <i@wolfogre.com>
Co-authored-by: hakito <hakito@noreply.gitea.com>
Co-committed-by: hakito <hakito@noreply.gitea.com>
(cherry picked from commit daf52d0e628d2d57b9f50a2556e404a3f05c34aa)
---
 internal/app/cmd/exec.go        | 2 +-
 internal/pkg/report/reporter.go | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/internal/app/cmd/exec.go b/internal/app/cmd/exec.go
index ffd932c..30a8c76 100644
--- a/internal/app/cmd/exec.go
+++ b/internal/app/cmd/exec.go
@@ -486,7 +486,7 @@ func loadExecCmd(ctx context.Context) *cobra.Command {
 	execCmd.PersistentFlags().BoolVarP(&execArg.noSkipCheckout, "no-skip-checkout", "", false, "Do not skip actions/checkout")
 	execCmd.PersistentFlags().BoolVarP(&execArg.debug, "debug", "d", false, "enable debug log")
 	execCmd.PersistentFlags().BoolVarP(&execArg.dryrun, "dryrun", "n", false, "dryrun mode")
-	execCmd.PersistentFlags().StringVarP(&execArg.image, "image", "i", "node:16-bullseye", "docker image to use")
+	execCmd.PersistentFlags().StringVarP(&execArg.image, "image", "i", "node:16-bullseye", "Docker image to use. Use \"-self-hosted\" to run directly on the host.")
 	execCmd.PersistentFlags().StringVarP(&execArg.network, "network", "", "", "Specify the network to which the container will connect")
 	execCmd.PersistentFlags().BoolVarP(&execArg.enableIPv6, "enable-ipv6", "6", false, "Create network with IPv6 enabled.")
 	execCmd.PersistentFlags().StringVarP(&execArg.githubInstance, "gitea-instance", "", "", "Gitea instance to use.")
diff --git a/internal/pkg/report/reporter.go b/internal/pkg/report/reporter.go
index 7e9a2d5..0a3ed79 100644
--- a/internal/pkg/report/reporter.go
+++ b/internal/pkg/report/reporter.go
@@ -418,7 +418,7 @@ func (r *Reporter) parseLogRow(entry *log.Entry) *runnerv1.LogRow {
 
 	return &runnerv1.LogRow{
 		Time:    timestamppb.New(entry.Time),
-		Content: content,
+		Content: strings.ToValidUTF8(content, "?"),
 	}
 }
 

From 1c2091614409fb7d1d2c1a9e3f06f0e12d49a1b3 Mon Sep 17 00:00:00 2001
From: Christopher Homberger <christopher.homberger@web.de>
Date: Thu, 8 Feb 2024 02:43:39 +0000
Subject: [PATCH 3/7] Use artifacts v4 jwt if available (#471)

Needs https://github.com/go-gitea/gitea/pull/28885 to provide jwt if sent by server

Could fix #459, but that has not been verified.

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-on: https://gitea.com/gitea/act_runner/pulls/471
Reviewed-by: delvh <dev.lh@web.de>
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Christopher Homberger <christopher.homberger@web.de>
Co-committed-by: Christopher Homberger <christopher.homberger@web.de>
(cherry picked from commit e6630e2e369f41fc9d9f9e570610611da18dda1d)
---
 internal/app/run/runner.go      | 8 ++++++--
 internal/pkg/report/reporter.go | 3 +++
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/internal/app/run/runner.go b/internal/app/run/runner.go
index 0884c50..be202c9 100644
--- a/internal/app/run/runner.go
+++ b/internal/app/run/runner.go
@@ -169,8 +169,12 @@ func (r *Runner) run(ctx context.Context, task *runnerv1.Task, reporter *report.
 		preset.Token = t
 	}
 
-	// use task token to action api token
-	r.envs["ACTIONS_RUNTIME_TOKEN"] = preset.Token
+	giteaRuntimeToken := taskContext["gitea_runtime_token"].GetStringValue()
+	if giteaRuntimeToken == "" {
+		// use task token to action api token for previous Gitea Server Versions
+		giteaRuntimeToken = preset.Token
+	}
+	r.envs["ACTIONS_RUNTIME_TOKEN"] = giteaRuntimeToken
 
 	eventJSON, err := json.Marshal(preset.Event)
 	if err != nil {
diff --git a/internal/pkg/report/reporter.go b/internal/pkg/report/reporter.go
index 0a3ed79..7a8658e 100644
--- a/internal/pkg/report/reporter.go
+++ b/internal/pkg/report/reporter.go
@@ -47,6 +47,9 @@ func NewReporter(ctx context.Context, cancel context.CancelFunc, client client.C
 	if v := task.Context.Fields["token"].GetStringValue(); v != "" {
 		oldnew = append(oldnew, v, "***")
 	}
+	if v := task.Context.Fields["gitea_runtime_token"].GetStringValue(); v != "" {
+		oldnew = append(oldnew, v, "***")
+	}
 	for _, v := range task.Secrets {
 		oldnew = append(oldnew, v, "***")
 	}

From cd206e466062179b066adfbef7fd139edaa36851 Mon Sep 17 00:00:00 2001
From: Christopher Homberger <christopher.homberger@web.de>
Date: Mon, 19 Feb 2024 02:30:54 +0000
Subject: [PATCH 4/7] Add ACTIONS_RESULTS_URL to env (#473)

actions/upload-artifact@v4 and actions/download-artifact@v4 depend on this variable

BaseUrl in a url are ignored by the nodejs code of the new actions, so this change doesn't append the path of the older `ACTIONS_RUNTIME_URL`.

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-on: https://gitea.com/gitea/act_runner/pulls/473
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Christopher Homberger <christopher.homberger@web.de>
Co-committed-by: Christopher Homberger <christopher.homberger@web.de>
(cherry picked from commit e14f42c40ac91d032c6a7c3e912646e55b2031a8)
---
 internal/app/run/runner.go | 1 +
 1 file changed, 1 insertion(+)

diff --git a/internal/app/run/runner.go b/internal/app/run/runner.go
index be202c9..78bb956 100644
--- a/internal/app/run/runner.go
+++ b/internal/app/run/runner.go
@@ -81,6 +81,7 @@ func NewRunner(cfg *config.Config, reg *config.Registration, cli client.Client)
 	// set artifact gitea api
 	artifactGiteaAPI := strings.TrimSuffix(cli.Address(), "/") + "/api/actions_pipeline/"
 	envs["ACTIONS_RUNTIME_URL"] = artifactGiteaAPI
+	envs["ACTIONS_RESULTS_URL"] = strings.TrimSuffix(cli.Address(), "/")
 
 	// Set specific environments to distinguish between Gitea and GitHub
 	envs["GITEA_ACTIONS"] = "true"

From 82c30f5cf74f4605e29745917214364ee7c41427 Mon Sep 17 00:00:00 2001
From: sillyguodong <gedong_1994@163.com>
Date: Fri, 1 Mar 2024 08:33:32 +0000
Subject: [PATCH 5/7] Set the status of steps to `skipped` if job is skipped
 (#500)

If a job is detected as skipped, its steps should also be `skipped`.

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-on: https://gitea.com/gitea/act_runner/pulls/500
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: sillyguodong <gedong_1994@163.com>
Co-committed-by: sillyguodong <gedong_1994@163.com>
(cherry picked from commit 45270656dfb7a0c8b382df3a9e8a212dbe5615d8)
---
 internal/pkg/report/reporter.go | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/internal/pkg/report/reporter.go b/internal/pkg/report/reporter.go
index 7a8658e..0930e88 100644
--- a/internal/pkg/report/reporter.go
+++ b/internal/pkg/report/reporter.go
@@ -114,6 +114,9 @@ func (r *Reporter) Fire(entry *log.Entry) error {
 				for _, s := range r.state.Steps {
 					if s.Result == runnerv1.Result_RESULT_UNSPECIFIED {
 						s.Result = runnerv1.Result_RESULT_CANCELLED
+						if jobResult == runnerv1.Result_RESULT_SKIPPED {
+							s.Result = runnerv1.Result_RESULT_SKIPPED
+						}
 					}
 				}
 			}

From 74cb9034e388365142a93bc02579e856886164ba Mon Sep 17 00:00:00 2001
From: Earl Warren <contact@earl-warren.org>
Date: Mon, 11 Mar 2024 21:36:04 +0700
Subject: [PATCH 6/7] Support cloning remote actions from insecure Gitea
 instances (#508)

(cherry picked from commit 75006a59cc4e6d18653926ec2578de5072ba6c32)
---
 internal/app/run/runner.go | 1 +
 1 file changed, 1 insertion(+)

diff --git a/internal/app/run/runner.go b/internal/app/run/runner.go
index 78bb956..ee12165 100644
--- a/internal/app/run/runner.go
+++ b/internal/app/run/runner.go
@@ -217,6 +217,7 @@ func (r *Runner) run(ctx context.Context, task *runnerv1.Task, reporter *report.
 		PlatformPicker:             r.labels.PickPlatform,
 		Vars:                       task.Vars,
 		ValidVolumes:               r.cfg.Container.ValidVolumes,
+		InsecureSkipTLS:            r.cfg.Runner.Insecure,
 	}
 
 	rr, err := runner.New(runnerConfig)

From ddd2eb7be92b86f0d22b6bc546902b86db16a6ab Mon Sep 17 00:00:00 2001
From: Earl Warren <contact@earl-warren.org>
Date: Mon, 11 Mar 2024 22:11:23 +0700
Subject: [PATCH 7/7] update release notes for 3.4.0

---
 RELEASE-NOTES.md | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md
index a8e94a8..21dff1e 100644
--- a/RELEASE-NOTES.md
+++ b/RELEASE-NOTES.md
@@ -13,6 +13,8 @@
   * add support for `runs-on.labels` which is equivalent to `runs-on` followed by a list of labels
   * the expressions in the service `ports` and `volumes` values are evaluated
   * network aliases are only supported when the network is user specified, not when it is provided by the runner
+* Fix compatibility issue with actions/{upload,download}-artifact@v4
+* If `[runner].insecure` is true in the configuration, insecure cloning actions is allowed
 
 ## 3.3.0