mirror of
https://gitea.com/gitea/act_runner.git
synced 2026-08-07 09:24:22 +02:00
Revert #1136 and use actionslib instead. revert chore: bump the module path to `/v3`, take the version from the VCS stamp (#1136) gitea can not consume the runner's api by version while it's version mismatches the module version: ``` go: gitea.com/gitea/runner@v3.0.1: invalid version: module contains a go.mod file, so module path must match major version ("gitea.com/gitea/runner/v3") ``` Fix that by bumping the module version now. The existing `v3.0.0` and `v3.0.1` tags stay unusable, so a new tag is needed after this lands. Also drop the version `-X` linker flags, which would otherwise have to repeat the new path in both `Makefile` and `.goreleaser.yaml`, where a stale path makes injection silently no-op. Go has recorded the module version in the build info since 1.24, so `Version()` reads it from there, keeping the variable as an override for builds without a VCS stamp. That part started as https://gitea.com/gitea/runner/pulls/1137 but belongs here: the stamp resolves against the tags that are legal for the module path, so without the `/v3` bump it would report `v1.0.9-0.<ts>-<sha>`. Since `release-nightly.yml` triggers on every push to `main`, splitting them would publish a nightly with a `v1` version. --------- Co-authored-by: bircni <bircni@icloud.com> Reviewed-on: https://gitea.com/gitea/runner/pulls/1136 Reviewed-by: techknowlogick <9+techknowlogick@noreply.gitea.com> Reviewed-by: bircni <bircni@icloud.com> Co-authored-by: silverwind <me@silverwind.io> Reviewed-on: https://gitea.com/gitea/runner/pulls/1148 Reviewed-by: Zettat123 <39446+zettat123@noreply.gitea.com>
104 lines
2.7 KiB
Go
104 lines
2.7 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package run
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
"testing"
|
|
|
|
"gitea.com/gitea/runner/internal/pkg/labels"
|
|
"gitea.com/gitea/runner/internal/pkg/ver"
|
|
|
|
runnerv1 "gitea.dev/actions-proto-go/runner/v1"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"google.golang.org/protobuf/types/known/structpb"
|
|
)
|
|
|
|
func TestSetupLines(t *testing.T) {
|
|
original := osReleasePath
|
|
path := filepath.Join(t.TempDir(), "os-release")
|
|
require.NoError(t, os.WriteFile(path, []byte("PRETTY_NAME=\"Ubuntu 24.04.4 LTS\"\n"), 0o600))
|
|
osReleasePath = path
|
|
defer func() { osReleasePath = original }()
|
|
|
|
r := &Runner{
|
|
name: "gitea-com-gitea-0003",
|
|
labels: labels.Labels{
|
|
{Name: "ubuntu-latest", Schema: labels.SchemeDocker, Arg: "//node:20"},
|
|
{Name: "ubuntu-22.04", Schema: labels.SchemeDocker, Arg: "//node:20"},
|
|
},
|
|
}
|
|
taskCtx, err := structpb.NewStruct(map[string]any{
|
|
"job": "lint",
|
|
"repository": "gitea/runner",
|
|
"event_name": "pull_request",
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, []string{
|
|
"gitea-com-gitea-0003(version:" + ver.Version() + ")",
|
|
"::group::Runner Information",
|
|
"Runner labels: ubuntu-latest, ubuntu-22.04",
|
|
"Task: 268506",
|
|
"Job: lint",
|
|
"Repository: gitea/runner",
|
|
"Triggered by event: pull_request",
|
|
"::endgroup::",
|
|
"::group::Operating System",
|
|
"Ubuntu 24.04.4 LTS",
|
|
fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
|
|
"::endgroup::",
|
|
}, r.setupLines(&runnerv1.Task{Id: 268506, Context: taskCtx}))
|
|
}
|
|
|
|
func TestPrettyOSName(t *testing.T) {
|
|
tests := map[string]struct {
|
|
osRelease string
|
|
want string
|
|
}{
|
|
"quoted value": {
|
|
osRelease: "NAME=\"Ubuntu\"\nVERSION_ID=\"24.04\"\nPRETTY_NAME=\"Ubuntu 24.04.4 LTS\"\n",
|
|
want: "Ubuntu 24.04.4 LTS",
|
|
},
|
|
"unquoted value": {
|
|
osRelease: "PRETTY_NAME=Alpine Linux v3.21\n",
|
|
want: "Alpine Linux v3.21",
|
|
},
|
|
"no pretty name": {
|
|
osRelease: "NAME=\"Ubuntu\"\nVERSION_ID=\"24.04\"\n",
|
|
want: "",
|
|
},
|
|
// A key that merely ends in PRETTY_NAME must not be mistaken for it.
|
|
"similar key": {
|
|
osRelease: "IMAGE_PRETTY_NAME=\"Ubuntu Core 24\"\n",
|
|
want: "",
|
|
},
|
|
}
|
|
|
|
for name, tt := range tests {
|
|
t.Run(name, func(t *testing.T) {
|
|
path := filepath.Join(t.TempDir(), "os-release")
|
|
require.NoError(t, os.WriteFile(path, []byte(tt.osRelease), 0o600))
|
|
|
|
original := osReleasePath
|
|
osReleasePath = path
|
|
defer func() { osReleasePath = original }()
|
|
|
|
assert.Equal(t, tt.want, prettyOSName())
|
|
})
|
|
}
|
|
|
|
t.Run("missing file", func(t *testing.T) {
|
|
original := osReleasePath
|
|
osReleasePath = filepath.Join(t.TempDir(), "absent")
|
|
defer func() { osReleasePath = original }()
|
|
|
|
assert.Empty(t, prettyOSName())
|
|
})
|
|
}
|