summaryrefslogtreecommitdiffstats
path: root/pkg/runner
diff options
context:
space:
mode:
authorEng Zer Jun <engzerjun@gmail.com>2023-08-09 14:41:12 +0200
committerGitHub <noreply@github.com>2023-08-09 14:41:12 +0200
commit8a9e4f9f38340ff9b7f9727add3dae62f3f6c7bb (patch)
treee094327a8b5d9e372f87150bd2555b72ec2ef8b0 /pkg/runner
parentfeat: Add new Action Cache (#1913) (diff)
downloadforgejo-act-8a9e4f9f38340ff9b7f9727add3dae62f3f6c7bb.tar.xz
forgejo-act-8a9e4f9f38340ff9b7f9727add3dae62f3f6c7bb.zip
refactor: remove unnecessary nil check in RunContext (#1955)
From the Go docs: "For a nil slice, the number of iterations is 0" [1] Therefore, an additional nil check for `job.RunsOn()` before the loop is unnecessary because `job.RunsOn()` returns a `[]string`. [1]: https://go.dev/ref/spec#For_range Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
Diffstat (limited to 'pkg/runner')
-rw-r--r--pkg/runner/run_context.go20
1 files changed, 9 insertions, 11 deletions
diff --git a/pkg/runner/run_context.go b/pkg/runner/run_context.go
index bcd36a8..37f4767 100644
--- a/pkg/runner/run_context.go
+++ b/pkg/runner/run_context.go
@@ -789,17 +789,15 @@ func (rc *RunContext) withGithubEnv(ctx context.Context, github *model.GithubCon
}
job := rc.Run.Job()
- if job.RunsOn() != nil {
- for _, runnerLabel := range job.RunsOn() {
- platformName := rc.ExprEval.Interpolate(ctx, runnerLabel)
- if platformName != "" {
- if platformName == "ubuntu-latest" {
- // hardcode current ubuntu-latest since we have no way to check that 'on the fly'
- env["ImageOS"] = "ubuntu20"
- } else {
- platformName = strings.SplitN(strings.Replace(platformName, `-`, ``, 1), `.`, 2)[0]
- env["ImageOS"] = platformName
- }
+ for _, runnerLabel := range job.RunsOn() {
+ platformName := rc.ExprEval.Interpolate(ctx, runnerLabel)
+ if platformName != "" {
+ if platformName == "ubuntu-latest" {
+ // hardcode current ubuntu-latest since we have no way to check that 'on the fly'
+ env["ImageOS"] = "ubuntu20"
+ } else {
+ platformName = strings.SplitN(strings.Replace(platformName, `-`, ``, 1), `.`, 2)[0]
+ env["ImageOS"] = platformName
}
}
}