1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-09-15 18:57:01 +00:00

fix #121 and #123 - add support for reading env variables from .env (#133)

This commit is contained in:
Casey Lee 2020-03-06 12:30:24 -08:00 committed by GitHub
parent c64bbd5c93
commit f9befb34a3
11 changed files with 620 additions and 0 deletions

View file

@ -3,9 +3,11 @@ package runner
import (
"context"
"fmt"
"os"
"path/filepath"
"testing"
"github.com/joho/godotenv"
"github.com/nektos/act/pkg/model"
log "github.com/sirupsen/logrus"
@ -88,3 +90,53 @@ func TestRunEvent(t *testing.T) {
})
}
}
func TestRunEventSecrets(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
log.SetLevel(log.DebugLevel)
ctx := context.Background()
platforms := map[string]string{
"ubuntu-latest": "node:12.6-buster-slim",
}
workflowPath := "secrets"
eventName := "push"
workdir, err := filepath.Abs("testdata")
assert.NilError(t, err, workflowPath)
_ = godotenv.Load(filepath.Join(workdir, workflowPath, ".env"))
secrets := make(map[string]string)
for _, secret := range []string{
"MY_SECRET",
"MULTILINE_SECRET",
"JSON_SECRET",
} {
if env, ok := os.LookupEnv(secret); ok && env != "" {
secrets[secret] = env
}
}
runnerConfig := &Config{
Workdir: workdir,
EventName: eventName,
Platforms: platforms,
ReuseContainers: false,
Secrets: secrets,
}
runner, err := New(runnerConfig)
assert.NilError(t, err, workflowPath)
planner, err := model.NewWorkflowPlanner(fmt.Sprintf("testdata/%s", workflowPath))
assert.NilError(t, err, workflowPath)
plan := planner.PlanEvent(eventName)
err = runner.NewPlanExecutor(plan)(ctx)
assert.NilError(t, err, workflowPath)
}