mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-08-01 17:38:36 +00:00
In replacement of code.gitea.io/actions-proto-go - https://gitea.com/gitea/actions-proto-def and https://gitea.com/gitea/actions-proto-go were merged into https://code.forgejo.org/forgejo/actions-proto to facilitate maintenance - the generated go code is different because the package name is different -f4285dfc28
shows they compare exactly identical before the name change -a3c95cb82f
is the generated code right after the name change - the cascading pull request further shows the protocol is compatible by running [end-to-end actions tests](https://code.forgejo.org/forgejo/end-to-end/src/branch/main/actions) that rely on it, using a runner binary built from [this pull request](https://code.forgejo.org/forgejo/end-to-end/actions/runs/3329/jobs/2#jobstep-4-640) `0296d988d65e66b8d8a7951d0d7d7f8c6cf78b44` matches `v0.0.1+576-g0296d98` - `time="2025-07-03T12:53:50Z" level=info msg="runner: runner, with version: v0.0.1+576-g0296d98, with labels: [docker], declared successfully" func="[func6]" file="[daemon.go:108]"` A similar pull request will be sent to Forgejo once this one is merged (less risky environment) Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/655 Reviewed-by: Michael Kriese <michael.kriese@gmx.de> Co-authored-by: Earl Warren <contact@earl-warren.org> Co-committed-by: Earl Warren <contact@earl-warren.org>
96 lines
2 KiB
Go
96 lines
2 KiB
Go
// Copyright 2023 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package run
|
|
|
|
import (
|
|
"testing"
|
|
|
|
runnerv1 "code.forgejo.org/forgejo/actions-proto/runner/v1"
|
|
"github.com/nektos/act/pkg/model"
|
|
"github.com/stretchr/testify/require"
|
|
"gotest.tools/v3/assert"
|
|
)
|
|
|
|
func Test_generateWorkflow(t *testing.T) {
|
|
type args struct {
|
|
task *runnerv1.Task
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
assert func(t *testing.T, wf *model.Workflow, err error)
|
|
want1 string
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "has needs",
|
|
args: args{
|
|
task: &runnerv1.Task{
|
|
WorkflowPayload: []byte(`
|
|
name: Build and deploy
|
|
on: push
|
|
|
|
jobs:
|
|
job9:
|
|
needs: build
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
- run: ./deploy --build ${{ needs.job1.outputs.output1 }}
|
|
- run: ./deploy --build ${{ needs.job2.outputs.output2 }}
|
|
`),
|
|
Needs: map[string]*runnerv1.TaskNeed{
|
|
"job1": {
|
|
Outputs: map[string]string{
|
|
"output1": "output1 value",
|
|
},
|
|
Result: runnerv1.Result_RESULT_SUCCESS,
|
|
},
|
|
"job2": {
|
|
Outputs: map[string]string{
|
|
"output2": "output2 value",
|
|
},
|
|
Result: runnerv1.Result_RESULT_SUCCESS,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
assert: func(t *testing.T, wf *model.Workflow, err error) {
|
|
assert.DeepEqual(t, wf.GetJob("job9").Needs(), []string{"job1", "job2"})
|
|
},
|
|
want1: "job9",
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "valid YAML syntax in top level env but wrong value type",
|
|
args: args{
|
|
task: &runnerv1.Task{
|
|
WorkflowPayload: []byte(`
|
|
on: push
|
|
|
|
env:
|
|
value: {{ }}
|
|
`),
|
|
},
|
|
},
|
|
assert: func(t *testing.T, wf *model.Workflow, err error) {
|
|
require.Nil(t, wf)
|
|
assert.ErrorContains(t, err, "cannot unmarshal")
|
|
},
|
|
wantErr: true,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, got1, err := generateWorkflow(tt.args.task)
|
|
if tt.wantErr {
|
|
require.Error(t, err)
|
|
} else {
|
|
require.NoError(t, err)
|
|
assert.Equal(t, got1, tt.want1)
|
|
}
|
|
tt.assert(t, got, err)
|
|
})
|
|
}
|
|
}
|