Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CI] Fix Windows Wheel flaky build caused by ', using heredoc in refreshenv. #29903

Merged
merged 1 commit into from
Nov 1, 2022

Conversation

cadedaniel
Copy link
Member

Screen Shot 2022-11-01 at 12 20 06 PM

Description

See #29878 and #29717 for context.

TL;DR there is a script which exports environment variables present in powershell to bash, but it fails to handle cases where environment variable values contain single quotes. This causes the Windows Wheels build to fail whenever an environment variable value contains a single quote, particularly when the commit message has a single quote (common!). I fixed it by exporting the variables using bash heredocs which are more robust against arbitrary input values.

Testing

Powershell code to test:

#Import-Module "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
#Update-SessionEnvironment
# Round brackets in variable names cause problems with bash
Get-ChildItem env:* | %{
  if (!($_.Name.Contains('('))) {
    $value = $_.Value
    if ($_.Name -eq 'PATH') {
      $value = $value -replace ';',':'
    }
    # Write-Output ("export " + $_.Name + "='" + $value + "'")
    Write-Output ("export " + $_.Name + "=$`(cat <<- 'REFRESHENV_EOF'`n" + $value + "`nREFRESHENV_EOF`)")
  }
}

Test runner (COMPLEX_ENV_VAR_1 has single quotes):

#!/usr/bin/env bash

pwsh=$(which pwsh)

export COMPLEX_ENV_VAR_1=$(cat <<- "EOF"
[Jobs] Deflake jobs sdk test (#29707)
--
Wait for all nodes to come up before running the unit test to deflake the unit test. It submits a bunch of jobs and checks that at least one was run on a worker node. However if the jobs are submitted too soon, its' possible that only the head node has come up, so 'theyll all be scheduled on the head node. The fix is to only submit the jobs after all the nodes are up.
Also adds some logs to improve debuggability.

Related issue number
Closes #29006
EOF)

env -i COMPLEX_ENV_VAR_1="$COMPLEX_ENV_VAR_1" $pwsh ps.ps | sed 's/export PATH/export FAKE_PATH/g' > refreshenv.sh
echo 'env' >> refreshenv.sh

env -i bash refreshenv.sh

Output:

$ ./test.sh
FAKE_PATH=/usr/local/microsoft/powershell/7:
COMPLEX_ENV_VAR_1=[Jobs] Deflake jobs sdk test (#29707)
--
Wait for all nodes to come up before running the unit test to deflake the unit test. It submits a bunch of jobs and checks that at least one was run on a worker node. However if the jobs are submitted too soon, its' possible that only the head node has come up, so 'theyll all be scheduled on the head node. The fix is to only submit the jobs after all the nodes are up.
Also adds some logs to improve debuggability.

Related issue number
Closes #29006
__CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0
PSModulePath=/tmp/71636ff1-42ce-40a1-9c08-d4e9ae135fad/.local/share/powershell/Modules:/usr/local/share/powershell/Modules:/usr/local/microsoft/powershell/7/Modules
PWD=/Users/cade/dev/cadelabs/ray-powershell-fix
SHLVL=1
_=/usr/bin/env

It worked! Without the heredoc, it gets borked:

$ ./test.sh
refreshenv.sh: line 3: export: `up,': not a valid identifier
refreshenv.sh: line 3: export: `theyll all be scheduled on the head node. The fix is to only submit the jobs after all the nodes are up.
Also adds some logs to improve debuggability.

Related issue number
Closes #29006': not a valid identifier
FAKE_PATH=/usr/local/microsoft/powershell/7:
COMPLEX_ENV_VAR_1=[Jobs] Deflake jobs sdk test (#29707)
--
Wait for all nodes to come up before running the unit test to deflake the unit test. It submits a bunch of jobs and checks that at least one was run on a worker node. However if the jobs are submitted too soon, its
__CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0
PSModulePath=/tmp/81c31618-cb53-4d44-b01c-fd622dba6734/.local/share/powershell/Modules:/usr/local/share/powershell/Modules:/usr/local/microsoft/powershell/7/Modules
PWD=/Users/cade/dev/cadelabs/ray-powershell-fix
SHLVL=1
_=/usr/bin/env

@cadedaniel cadedaniel self-assigned this Nov 1, 2022
@cadedaniel cadedaniel linked an issue Nov 1, 2022 that may be closed by this pull request
@cadedaniel cadedaniel changed the title Fix Windows Wheel flaky build by using heredoc in refreshenv [CI] Fix Windows Wheel flaky build by using heredoc in refreshenv Nov 1, 2022
Copy link
Collaborator

@jjyao jjyao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a single quote to the commit message to make sure it works :)

@cadedaniel
Copy link
Member Author

haha, sure :)

@cadedaniel cadedaniel changed the title [CI] Fix Windows Wheel flaky build by using heredoc in refreshenv [CI] Fix Windows Wheel flaky build caused by ', using heredoc in refreshenv. Nov 1, 2022
@cadedaniel
Copy link
Member Author

@jjyao my edit will go into the merge commit, right?

@cadedaniel
Copy link
Member Author

@jjyao merge please

@jjyao jjyao merged commit f39d323 into master Nov 1, 2022
@jjyao jjyao deleted the heredoc-refreshenv branch November 1, 2022 21:40
@cadedaniel cadedaniel restored the heredoc-refreshenv branch November 1, 2022 21:41
@cadedaniel cadedaniel deleted the heredoc-refreshenv branch November 1, 2022 21:41
@cadedaniel
Copy link
Member Author

🤔🤔🤔🤔

+ source /c/Users/ContainerAdministrator/AppData/Local/Temp/refreshenv.sh
/c/Users/ContainerAdministrator/AppData/Local/Temp/refreshenv.sh: line 6: warning: here-document at line 4 delimited by end-of-file (wanted `REFRESHENV_EOF')
+++ cat
++ export BUILDKITE=true
++ BUILDKITE=true
/c/Users/ContainerAdministrator/AppData/Local/Temp/refreshenv.sh: line 9: warning: here-document at line 7 delimited by end-of-file (wanted `REFRESHENV_EOF')
+++ cat
++ export 'ProgramW6432=C:\Program Files'
++ ProgramW6432='C:\Program Files'
/c/Users/ContainerAdministrator/AppData/Local/Temp/refreshenv.sh: line 12: warning: here-document at line 10 delimited by end-of-file (wanted `REFRESHENV_EOF')
+++ cat
++ export 'ChocolateyInstall=C:\ProgramData\chocolatey'
++ ChocolateyInstall='C:\ProgramData\chocolatey'
/c/Users/ContainerAdministrator/AppData/Local/Temp/refreshenv.sh: line 15: warning: here-document at line 13 delimited by end-of-file (wanted `REFRESHENV_EOF')

NKcqx pushed a commit to NKcqx/ray that referenced this pull request Nov 8, 2022
…eshenv. (ray-project#29903)

See ray-project#29878 and ray-project#29717 for context.

TL;DR there is a script which exports environment variables present in powershell to bash, but it fails to handle cases where environment variable values contain single quotes. This causes the Windows Wheels build to fail whenever an environment variable value contains a single quote, particularly when the commit message has a single quote (common!). I fixed it by exporting the variables using bash heredocs which are more robust against arbitrary input values.

Signed-off-by: Cade Daniel <[email protected]>
Signed-off-by: JasonChen <[email protected]>
peytondmurray pushed a commit to peytondmurray/ray that referenced this pull request Dec 16, 2022
…eshenv. (ray-project#29903)

See ray-project#29878 and ray-project#29717 for context.

TL;DR there is a script which exports environment variables present in powershell to bash, but it fails to handle cases where environment variable values contain single quotes. This causes the Windows Wheels build to fail whenever an environment variable value contains a single quote, particularly when the commit message has a single quote (common!). I fixed it by exporting the variables using bash heredocs which are more robust against arbitrary input values.

Signed-off-by: Cade Daniel <[email protected]>
WeichenXu123 pushed a commit to WeichenXu123/ray that referenced this pull request Dec 19, 2022
…eshenv. (ray-project#29903)

See ray-project#29878 and ray-project#29717 for context.

TL;DR there is a script which exports environment variables present in powershell to bash, but it fails to handle cases where environment variable values contain single quotes. This causes the Windows Wheels build to fail whenever an environment variable value contains a single quote, particularly when the commit message has a single quote (common!). I fixed it by exporting the variables using bash heredocs which are more robust against arbitrary input values.

Signed-off-by: Cade Daniel <[email protected]>
Signed-off-by: Weichen Xu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CI] bk:https://:windows: Wheels is failing/flaky on master.
2 participants