diff --git a/pkg/container/parse_env_file.go b/pkg/container/parse_env_file.go index ee79b7e..9192762 100644 --- a/pkg/container/parse_env_file.go +++ b/pkg/container/parse_env_file.go @@ -25,8 +25,16 @@ func parseEnvFile(e Container, srcPath string, env *map[string]string) common.Ex return err } s := bufio.NewScanner(reader) + firstLine := true for s.Scan() { line := s.Text() + if firstLine { + firstLine = false + // skip utf8 bom, powershell 5 legacy uses it for utf8 + if len(line) >= 3 && line[0] == 239 && line[1] == 187 && line[2] == 191 { + line = line[3:] + } + } singleLineEnv := strings.Index(line, "=") multiLineEnv := strings.Index(line, "<<") if singleLineEnv != -1 && (multiLineEnv == -1 || singleLineEnv < multiLineEnv) { diff --git a/pkg/runner/run_context.go b/pkg/runner/run_context.go index 2efad2c..c609175 100644 --- a/pkg/runner/run_context.go +++ b/pkg/runner/run_context.go @@ -520,8 +520,16 @@ func (rc *RunContext) UpdateExtraPath(ctx context.Context, githubEnvPath string) return err } s := bufio.NewScanner(reader) + firstLine := true for s.Scan() { line := s.Text() + if firstLine { + firstLine = false + // skip utf8 bom, powershell 5 legacy uses it for utf8 + if len(line) >= 3 && line[0] == 239 && line[1] == 187 && line[2] == 191 { + line = line[3:] + } + } if len(line) > 0 { rc.addPath(ctx, line) } diff --git a/pkg/runner/runner_test.go b/pkg/runner/runner_test.go index 8936812..029fca7 100644 --- a/pkg/runner/runner_test.go +++ b/pkg/runner/runner_test.go @@ -429,6 +429,8 @@ func TestRunEventHostEnvironment(t *testing.T) { tables = append(tables, []TestJobFileInfo{ {workdir, "windows-prepend-path", "push", "", platforms, secrets}, {workdir, "windows-add-env", "push", "", platforms, secrets}, + {workdir, "windows-prepend-path-powershell-5", "push", "", platforms, secrets}, + {workdir, "windows-add-env-powershell-5", "push", "", platforms, secrets}, {workdir, "windows-shell-cmd", "push", "", platforms, secrets}, }...) } else { diff --git a/pkg/runner/testdata/windows-add-env-powershell-5/action/action.yml b/pkg/runner/testdata/windows-add-env-powershell-5/action/action.yml new file mode 100644 index 0000000..89a64f6 --- /dev/null +++ b/pkg/runner/testdata/windows-add-env-powershell-5/action/action.yml @@ -0,0 +1,7 @@ +runs: + using: composite + steps: + - run: | + echo $env:GITHUB_ENV + echo "kEy=n/a" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + shell: powershell diff --git a/pkg/runner/testdata/windows-add-env-powershell-5/push.yml b/pkg/runner/testdata/windows-add-env-powershell-5/push.yml new file mode 100644 index 0000000..3582476 --- /dev/null +++ b/pkg/runner/testdata/windows-add-env-powershell-5/push.yml @@ -0,0 +1,48 @@ +on: + push: +jobs: + test: + runs-on: windows-latest + steps: + - run: | + echo $env:GITHUB_ENV + echo "key=val" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + echo "key2< $env:GITHUB_ENV + echo "key=val" >> $env:GITHUB_ENV echo "key2<> $env:GITHUB_ENV echo "line1" >> $env:GITHUB_ENV echo "line2" >> $env:GITHUB_ENV @@ -24,7 +24,9 @@ jobs: } - run: | echo $env:GITHUB_ENV + # Defect missing append echo "KEY=test" > $env:GITHUB_ENV + # Defect missing append, test is broken!!! echo "Key=expected" > $env:GITHUB_ENV - name: Assert GITHUB_ENV is merged case insensitive run: exit 1 diff --git a/pkg/runner/testdata/windows-prepend-path-powershell-5/push.yml b/pkg/runner/testdata/windows-prepend-path-powershell-5/push.yml new file mode 100644 index 0000000..7468b45 --- /dev/null +++ b/pkg/runner/testdata/windows-prepend-path-powershell-5/push.yml @@ -0,0 +1,34 @@ +on: + push: +defaults: + run: + shell: powershell +jobs: + test: + runs-on: windows-latest + steps: + - run: | + mkdir build + echo '@echo off' | Out-File -FilePath build/test.cmd -Encoding utf8 + echo 'echo Hi' | Out-File -FilePath build/test.cmd -Encoding utf8 -Append + mkdir build2 + echo '@echo off' | Out-File -FilePath build/test2.cmd -Encoding utf8 + echo 'echo test2' | Out-File -FilePath build/test2.cmd -Encoding utf8 -Append + - run: | + echo '${{ tojson(runner) }}' + ls + echo '${{ github.workspace }}' + working-directory: ${{ github.workspace }}\build + - run: | + echo $env:GITHUB_PATH + echo '${{ github.workspace }}\build' | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + cat $env:GITHUB_PATH + - run: | + echo $env:PATH + test + - run: | + echo "PATH=$env:PATH;${{ github.workspace }}\build2" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + - run: | + echo $env:PATH + test + test2 \ No newline at end of file