diff --git a/acceptance/README.md b/acceptance/README.md index 82d7e1ab6..750cb75d1 100644 --- a/acceptance/README.md +++ b/acceptance/README.md @@ -57,7 +57,7 @@ The following custom environment variables are made available to the scripts: * `ORG`: Set to the value of the `GH_ACCEPTANCE_ORG` env var provided to `go test` * `GH_TOKEN`: Set to the value of the `GH_ACCEPTANCE_TOKEN` env var provided to `go test` * `RANDOM_STRING`: Set to a length 10 random string of letters to help isolate globally visible resources - * `SCRIPT_NAME`: Set to the name of the `testscript` currently running, without extension e.g. `pr-view` + * `SCRIPT_NAME`: Set to the name of the `testscript` currently running, without extension and replacing hyphens with underscores e.g. `pr_view` * `HOME`: Set to the initial working directory. Required for `git` operations * `GH_CONFIG_DIR`: Set to the initial working directory. Required for `gh` operations diff --git a/acceptance/acceptance_test.go b/acceptance/acceptance_test.go index 58e27f506..de708e38c 100644 --- a/acceptance/acceptance_test.go +++ b/acceptance/acceptance_test.go @@ -111,7 +111,11 @@ func sharedSetup(tsEnv testScriptEnv) func(ts *testscript.Env) error { if !ok { ts.T().Fatal("script name not found") } - ts.Setenv("SCRIPT_NAME", scriptName) + + // When using script name to uniquely identify where test data comes from, + // some places like GitHub Actions secret names don't accept hyphens. + // Replace them with underscores until such a time this becomes a problem. + ts.Setenv("SCRIPT_NAME", strings.ReplaceAll(scriptName, "-", "_")) ts.Setenv("HOME", ts.Cd) ts.Setenv("GH_CONFIG_DIR", ts.Cd) @@ -182,6 +186,8 @@ func sharedCmds(tsEnv testScriptEnv) map[string]func(ts *testscript.TestScript, src := ts.MkAbs(args[0]) ts.Logf("replace src: %s", src) + + // Preserve the existing file mode while replacing the contents similar to native cp behavior info, err := os.Stat(src) ts.Check(err) mode := info.Mode() & 0o777 @@ -198,7 +204,7 @@ func sharedCmds(tsEnv testScriptEnv) map[string]func(ts *testscript.TestScript, value := arg[i+1:] ts.Logf("replace %s: %s", name, value) - // `replace` was originally built similar to `cmpenv`, expanding environment variables within a file. + // `replace` was originally built similar to `cp` and `cmpenv`, expanding environment variables within a file. // However files with content that looks like environments variable such as GitHub Actions workflows // were being modified unexpectedly. Thus `replace` has been designed to using string replacement // looking for `$KEY` specifically. diff --git a/acceptance/testdata/secret/secret-org.txtar b/acceptance/testdata/secret/secret-org.txtar index 2bc6a845b..7d383009c 100644 --- a/acceptance/testdata/secret/secret-org.txtar +++ b/acceptance/testdata/secret/secret-org.txtar @@ -1,6 +1,6 @@ # Setup environment variables used for testscript -env REPO=$SCRIPT_NAME-$RANDOM_STRING -env2upper SECRET_NAME=$SCRIPT_NAME_$RANDOM_STRING +env REPO=${SCRIPT_NAME}-${RANDOM_STRING} +env2upper SECRET_NAME=${SCRIPT_NAME}_${RANDOM_STRING} # Use gh as a credential helper exec gh auth setup-git