mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-01 20:59:45 +09:00
a71c5c94c5
Align job and `runs-on` validation with github.com, as implemented by the parser in https://github.com/actions/runner. A job without `runs-on` could be claimed by any runner, so a job meant for a container could run on the host. - Jobs without `runs-on` fail with `Required property is missing: runs-on`, called workflows included - Unknown job keys and callers (`uses:`) mixed with steps-only keys like `runs-on` are rejected - Empty, null and nested `runs-on` values are rejected - A `runs-on` evaluating to such a value fails only that job - Called workflows are validated at run creation, an invalid one fails the run as an invalid workflow file - Zero labels (`runs-on: []` or `{}`) never match a runner, including jobs queued before upgrading <img width="960" alt="image" src="https://github.com/user-attachments/assets/e746ce5a-b711-4e8b-aab8-81336ff53d86" /> **Behavior Change:** workflows that omit `runs-on`, use unknown job keys or mix `uses` with `runs-on` stop running until fixed. --------- Co-authored-by: bircni <bircni@icloud.com> Co-authored-by: silverwind <me@silverwind.io>
91 lines
2.0 KiB
Go
91 lines
2.0 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package actions
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"gitea.dev/modules/timeutil"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestShouldPersistLastOnline(t *testing.T) {
|
|
now := time.Now()
|
|
tests := []struct {
|
|
name string
|
|
last timeutil.TimeStamp
|
|
want bool
|
|
}{
|
|
{
|
|
name: "fresh, skip write",
|
|
last: timeutil.TimeStamp(now.Add(-5 * time.Second).Unix()),
|
|
want: false,
|
|
},
|
|
{
|
|
name: "exactly at interval, write",
|
|
last: timeutil.TimeStamp(now.Add(-RunnerHeartbeatInterval).Unix()),
|
|
want: true,
|
|
},
|
|
{
|
|
name: "stale, write",
|
|
last: timeutil.TimeStamp(now.Add(-2 * RunnerHeartbeatInterval).Unix()),
|
|
want: true,
|
|
},
|
|
{
|
|
name: "zero (never seen), write",
|
|
last: 0,
|
|
want: true,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
assert.Equal(t, tt.want, ShouldPersistLastOnline(tt.last, now))
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestShouldPersistLastActive(t *testing.T) {
|
|
now := time.Now()
|
|
tests := []struct {
|
|
name string
|
|
last timeutil.TimeStamp
|
|
want bool
|
|
}{
|
|
{
|
|
name: "fresh, skip write",
|
|
last: timeutil.TimeStamp(now.Add(-1 * time.Second).Unix()),
|
|
want: false,
|
|
},
|
|
{
|
|
name: "exactly at interval, write",
|
|
last: timeutil.TimeStamp(now.Add(-RunnerActiveInterval).Unix()),
|
|
want: true,
|
|
},
|
|
{
|
|
name: "stale, write",
|
|
last: timeutil.TimeStamp(now.Add(-2 * RunnerActiveInterval).Unix()),
|
|
want: true,
|
|
},
|
|
{
|
|
name: "zero (never seen), write",
|
|
last: 0,
|
|
want: true,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
assert.Equal(t, tt.want, ShouldPersistLastActive(tt.last, now))
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestCanMatchLabelsCaseInsensitive(t *testing.T) {
|
|
runner := &ActionRunner{AgentLabels: []string{"self-hosted", "Linux", "X64"}}
|
|
assert.True(t, runner.CanMatchLabels([]string{"SELF-HOSTED", "linux"}))
|
|
assert.False(t, runner.CanMatchLabels([]string{"linux", "arm64"}))
|
|
assert.False(t, runner.CanMatchLabels(nil))
|
|
}
|