Fix regex for GITHUB_ENV parsing (#893)
* fix: correct env pattern regex GitHub Actions allows for envvars to contain Signed-off-by: hackercat <me@hackerc.at> * format: format and typo fix Signed-off-by: hackercat <me@hackerc.at> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
parent
4ae71b5878
commit
96cf907c5e
2 changed files with 15 additions and 5 deletions
|
@ -369,7 +369,10 @@ var singleLineEnvPattern, mulitiLineEnvPattern *regexp.Regexp
|
||||||
|
|
||||||
func (cr *containerReference) extractEnv(srcPath string, env *map[string]string) common.Executor {
|
func (cr *containerReference) extractEnv(srcPath string, env *map[string]string) common.Executor {
|
||||||
if singleLineEnvPattern == nil {
|
if singleLineEnvPattern == nil {
|
||||||
singleLineEnvPattern = regexp.MustCompile("^([^=]+)=([^=]+)$")
|
// Single line pattern matches:
|
||||||
|
// SOME_VAR=data=moredata
|
||||||
|
// SOME_VAR=datamoredata
|
||||||
|
singleLineEnvPattern = regexp.MustCompile(`^([^=]*)\=(.*)$`)
|
||||||
mulitiLineEnvPattern = regexp.MustCompile(`^([^<]+)<<(\w+)$`)
|
mulitiLineEnvPattern = regexp.MustCompile(`^([^<]+)<<(\w+)$`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
15
pkg/runner/testdata/env-and-path/push.yaml
vendored
15
pkg/runner/testdata/env-and-path/push.yaml
vendored
|
@ -43,7 +43,16 @@ jobs:
|
||||||
- name: "Check single line env"
|
- name: "Check single line env"
|
||||||
run: |
|
run: |
|
||||||
if [[ "${KEY}" != "value" ]]; then
|
if [[ "${KEY}" != "value" ]]; then
|
||||||
echo "${KEY} dosen't == 'value'"
|
echo "${KEY} doesn't == 'value'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
- name: "Write single line env with more than one 'equals' signs to $GITHUB_ENV"
|
||||||
|
run: |
|
||||||
|
echo "KEY=value=anothervalue" >> $GITHUB_ENV
|
||||||
|
- name: "Check single line env"
|
||||||
|
run: |
|
||||||
|
if [[ "${KEY}" != "value=anothervalue" ]]; then
|
||||||
|
echo "${KEY} doesn't == 'value=anothervalue'"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
- name: "Write multiline env to $GITHUB_ENV"
|
- name: "Write multiline env to $GITHUB_ENV"
|
||||||
|
@ -54,8 +63,6 @@ jobs:
|
||||||
- name: "Check multiline line env"
|
- name: "Check multiline line env"
|
||||||
run: |
|
run: |
|
||||||
if [[ "${KEY2}" != "value2" ]]; then
|
if [[ "${KEY2}" != "value2" ]]; then
|
||||||
echo "${KEY2} dosen't == 'value'"
|
echo "${KEY2} doesn't == 'value'"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue