Actions Artifacts v4 backend (#2224)
* Actions Artifacts v4 backend * lint * fix it now * remove protofile, to make linter not complain * sync changes * add delete * import auth test from gitea * add more tests * codecov ignore protobuf
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/go-connections/nat"
|
||||
@@ -962,10 +963,15 @@ func setActionRuntimeVars(rc *RunContext, env map[string]string) {
|
||||
actionsRuntimeURL = fmt.Sprintf("http://%s:%s/", rc.Config.ArtifactServerAddr, rc.Config.ArtifactServerPort)
|
||||
}
|
||||
env["ACTIONS_RUNTIME_URL"] = actionsRuntimeURL
|
||||
env["ACTIONS_RESULTS_URL"] = actionsRuntimeURL
|
||||
|
||||
actionsRuntimeToken := os.Getenv("ACTIONS_RUNTIME_TOKEN")
|
||||
if actionsRuntimeToken == "" {
|
||||
actionsRuntimeToken = "token"
|
||||
runID := int64(1)
|
||||
if rid, ok := rc.Config.Env["GITHUB_RUN_ID"]; ok {
|
||||
runID, _ = strconv.ParseInt(rid, 10, 64)
|
||||
}
|
||||
actionsRuntimeToken, _ = common.CreateAuthorizationToken(runID, runID, runID)
|
||||
}
|
||||
env["ACTIONS_RUNTIME_TOKEN"] = actionsRuntimeToken
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
"github.com/nektos/act/pkg/exprparser"
|
||||
"github.com/nektos/act/pkg/model"
|
||||
|
||||
@@ -682,3 +683,52 @@ func TestRunContextGetEnv(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetRuntimeVariables(t *testing.T) {
|
||||
rc := &RunContext{
|
||||
Config: &Config{
|
||||
ArtifactServerAddr: "myhost",
|
||||
ArtifactServerPort: "8000",
|
||||
},
|
||||
}
|
||||
v := "http://myhost:8000/"
|
||||
env := map[string]string{}
|
||||
setActionRuntimeVars(rc, env)
|
||||
|
||||
assert.Equal(t, v, env["ACTIONS_RESULTS_URL"])
|
||||
assert.Equal(t, v, env["ACTIONS_RUNTIME_URL"])
|
||||
runtimeToken := env["ACTIONS_RUNTIME_TOKEN"]
|
||||
assert.NotEmpty(t, v, runtimeToken)
|
||||
|
||||
tkn, _, err := jwt.NewParser().ParseUnverified(runtimeToken, jwt.MapClaims{})
|
||||
assert.NotNil(t, tkn)
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
||||
func TestSetRuntimeVariablesWithRunID(t *testing.T) {
|
||||
rc := &RunContext{
|
||||
Config: &Config{
|
||||
ArtifactServerAddr: "myhost",
|
||||
ArtifactServerPort: "8000",
|
||||
Env: map[string]string{
|
||||
"GITHUB_RUN_ID": "45",
|
||||
},
|
||||
},
|
||||
}
|
||||
v := "http://myhost:8000/"
|
||||
env := map[string]string{}
|
||||
setActionRuntimeVars(rc, env)
|
||||
|
||||
assert.Equal(t, v, env["ACTIONS_RESULTS_URL"])
|
||||
assert.Equal(t, v, env["ACTIONS_RUNTIME_URL"])
|
||||
runtimeToken := env["ACTIONS_RUNTIME_TOKEN"]
|
||||
assert.NotEmpty(t, v, runtimeToken)
|
||||
|
||||
claims := jwt.MapClaims{}
|
||||
tkn, _, err := jwt.NewParser().ParseUnverified(runtimeToken, &claims)
|
||||
assert.NotNil(t, tkn)
|
||||
assert.Nil(t, err)
|
||||
scp, ok := claims["scp"]
|
||||
assert.True(t, ok, "scp claim exists")
|
||||
assert.Equal(t, "Actions.Results:45:45", scp, "contains expected scp claim")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user