Files
Bussa Aditya Naga Sai LaxmanandCursor 7f3c946f42 fix: [CI-23943]: make plugin compatible with act 0.2.89 (#32)
* fix: [CI-23943]: remediate github-actions image vulnerabilities

Upgrade the Go toolchain, dependencies, Docker base image, and act runtime to reduce vulnerabilities while preserving plugin behavior.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix: [CI-23943]: generate valid workflows for act

Skip invalid placeholder output steps so actions without outputs remain compatible with newer act validation.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix: [CI-23943]: skip invalid env var names in act env file

Harness injects a step's output variables into later steps in the stage
(e.g. cache-hit and node-version from actions/setup-node). Hyphenated
names are not valid in dotenv files, and act >= 0.2.89 fails to parse
--env-file when they are present:

  Error loading from /tmp/action.env: unexpected character "-" in
  variable name near "cache-hit=..."

Filter out any name that is not a valid dotenv identifier when writing
the env file. Secrets handling and PLUGIN_* exclusion are unchanged.

Found during HHI migration smoke testing (CI-24652) with
harnesssecure/github-actions built on custom-ci-dind-base:29.8
(act 0.2.89).

Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-17 21:04:55 +05:30

66 lines
1.6 KiB
Go

package utils
import (
"os"
"regexp"
"strings"
"github.com/joho/godotenv"
"github.com/pkg/errors"
)
// validEnvName matches names that are legal in a dotenv file. Harness injects
// a step's output variables into later steps in the stage (e.g. cache-hit and
// node-version from actions/setup-node), and act >= 0.2.89 fails to parse
// hyphenated names in --env-file.
var validEnvName = regexp.MustCompile(`^[A-Za-z_][A-Za-z0-9_]*$`)
func CreateEnvAndSecretFile(envFile, secretFile string, secrets []string) error {
envVars := getEnvVars()
actionEnvVars := make(map[string]string)
for key, val := range envVars {
if !validEnvName.MatchString(key) {
continue
}
if !strings.HasPrefix(key, "PLUGIN_") && !Exists(secrets, key) {
actionEnvVars[key] = val
}
}
secretEnvVars := make(map[string]string)
for _, secretName := range secrets {
if os.Getenv(secretName) != "" {
secretEnvVars[secretName] = os.Getenv(secretName)
}
}
if err := godotenv.Write(actionEnvVars, envFile); err != nil {
return errors.Wrap(err, "failed to write environment variables file")
}
if err := godotenv.Write(secretEnvVars, secretFile); err != nil {
return errors.Wrap(err, "failed to write secret variables file")
}
return nil
}
// Return environment variables set in a map format
func getEnvVars() map[string]string {
m := make(map[string]string)
for _, e := range os.Environ() {
if i := strings.Index(e, "="); i >= 0 {
m[e[:i]] = e[i+1:]
}
}
return m
}
func Exists(slice []string, val string) bool {
for _, item := range slice {
if item == val {
return true
}
}
return false
}