mirror of
https://github.com/safedep/pmg.git
synced 2026-08-03 07:24:09 +02:00
add runner hostname to CI invocation context (#356)
* add runner hostname to CI invocation context * update test
This commit is contained in:
@@ -57,6 +57,10 @@ func (r *githubActionsEnvResolver) Metadata() map[string]string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if hostname, err := os.Hostname(); err == nil && hostname != "" {
|
||||||
|
metadata["hostname"] = hostname
|
||||||
|
}
|
||||||
|
|
||||||
if len(metadata) == 0 {
|
if len(metadata) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package audit
|
package audit
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
controltowerv1 "buf.build/gen/go/safedep/api/protocolbuffers/go/safedep/messages/controltower/v1"
|
controltowerv1 "buf.build/gen/go/safedep/api/protocolbuffers/go/safedep/messages/controltower/v1"
|
||||||
@@ -55,6 +56,11 @@ func TestGithubActionsResolverMetadata(t *testing.T) {
|
|||||||
assert.Equal(t, "build", metadata["job"])
|
assert.Equal(t, "build", metadata["job"])
|
||||||
assert.Equal(t, "1", metadata["run_attempt"])
|
assert.Equal(t, "1", metadata["run_attempt"])
|
||||||
assert.Equal(t, "https://github.com", metadata["server_url"])
|
assert.Equal(t, "https://github.com", metadata["server_url"])
|
||||||
|
|
||||||
|
hostname, err := os.Hostname()
|
||||||
|
if err == nil && hostname != "" {
|
||||||
|
assert.Equal(t, hostname, metadata["hostname"])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGithubActionsResolverMetadataEmpty(t *testing.T) {
|
func TestGithubActionsResolverMetadataEmpty(t *testing.T) {
|
||||||
@@ -64,7 +70,14 @@ func TestGithubActionsResolverMetadataEmpty(t *testing.T) {
|
|||||||
t.Setenv("GITHUB_SERVER_URL", "")
|
t.Setenv("GITHUB_SERVER_URL", "")
|
||||||
|
|
||||||
resolver := newGithubActionsCIResolver()
|
resolver := newGithubActionsCIResolver()
|
||||||
assert.Nil(t, resolver.Metadata())
|
metadata := resolver.Metadata()
|
||||||
|
|
||||||
|
hostname, err := os.Hostname()
|
||||||
|
if err == nil && hostname != "" {
|
||||||
|
assert.Equal(t, map[string]string{"hostname": hostname}, metadata)
|
||||||
|
} else {
|
||||||
|
assert.Nil(t, metadata)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGithubActionsResolverNonPRRef(t *testing.T) {
|
func TestGithubActionsResolverNonPRRef(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user