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 af970769d7
commit 4fde7d8865
14 changed files with 629 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)
}

3
pkg/runner/testdata/secrets/.env vendored Normal file
View File

@@ -0,0 +1,3 @@
MY_SECRET=top-secret
MULTILINE_SECRET="foo\nbar\nbaz"
JSON_SECRET={"foo": "bar"}

View File

@@ -7,3 +7,7 @@ jobs:
steps:
- run: |
echo '${{secrets.MY_SECRET}}' | grep 'top-secret'
- run: |
echo "${{secrets.MULTILINE_SECRET}}" | wc -l | grep 3
- run: |
echo '${{secrets.JSON_SECRET}}' | grep "{\"foo\": \"bar\"}"