Skip to content

Commit 96cf907

Browse files
Ryanmergify[bot]
Ryan
andauthored
Fix regex for GITHUB_ENV parsing (#893)
* fix: correct env pattern regex GitHub Actions allows for envvars to contain Signed-off-by: hackercat <[email protected]> * format: format and typo fix Signed-off-by: hackercat <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 4ae71b5 commit 96cf907

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

Diff for: pkg/container/docker_run.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,10 @@ var singleLineEnvPattern, mulitiLineEnvPattern *regexp.Regexp
369369

370370
func (cr *containerReference) extractEnv(srcPath string, env *map[string]string) common.Executor {
371371
if singleLineEnvPattern == nil {
372-
singleLineEnvPattern = regexp.MustCompile("^([^=]+)=([^=]+)$")
372+
// Single line pattern matches:
373+
// SOME_VAR=data=moredata
374+
// SOME_VAR=datamoredata
375+
singleLineEnvPattern = regexp.MustCompile(`^([^=]*)\=(.*)$`)
373376
mulitiLineEnvPattern = regexp.MustCompile(`^([^<]+)<<(\w+)$`)
374377
}
375378

Diff for: pkg/runner/testdata/env-and-path/push.yaml

+11-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,16 @@ jobs:
4343
- name: "Check single line env"
4444
run: |
4545
if [[ "${KEY}" != "value" ]]; then
46-
echo "${KEY} dosen't == 'value'"
46+
echo "${KEY} doesn't == 'value'"
47+
exit 1
48+
fi
49+
- name: "Write single line env with more than one 'equals' signs to $GITHUB_ENV"
50+
run: |
51+
echo "KEY=value=anothervalue" >> $GITHUB_ENV
52+
- name: "Check single line env"
53+
run: |
54+
if [[ "${KEY}" != "value=anothervalue" ]]; then
55+
echo "${KEY} doesn't == 'value=anothervalue'"
4756
exit 1
4857
fi
4958
- name: "Write multiline env to $GITHUB_ENV"
@@ -54,8 +63,6 @@ jobs:
5463
- name: "Check multiline line env"
5564
run: |
5665
if [[ "${KEY2}" != "value2" ]]; then
57-
echo "${KEY2} dosen't == 'value'"
66+
echo "${KEY2} doesn't == 'value'"
5867
exit 1
5968
fi
60-
61-

0 commit comments

Comments
 (0)