我有一个github动作,想要测试是否已经创建了一个特定的路径,我遇到了一个问题,github有
USERNAME=runneradmin
TMP=C:UsersRUNNER~1AppDataLocalTemp
测试脚本(VIRTUAL_ENV
由activate.bat脚本设置):
echo on
set "WORKON_HOME=%TMP%wo home %RANDOM%"
mkdir "%WORKON_HOME%"
cd /d "%WORKON_HOME%"
virtualenv "name with spaces"
cd "name with spaces"
call Scriptsactivate.bat
if "%WORKON_HOME%name with spaces"=="%VIRTUAL_ENV%" (
echo workon home and virtualenv are equal
) else (
echo. "%WORKON_HOME%name with spaces" is not equal to "%VIRTUAL_ENV%"
)
if "%CD%"=="%VIRTUAL_ENV%" (
echo cd and virtualenv are equal
) else (
echo. "%CD%" is not equal to "%VIRTUAL_ENV%"
)
exit /b 1
输出为(RUNNER~1
vsrunneradmin
的差异):
"C:UsersRUNNER~1AppDataLocalTempwo home 14549name with spaces" is not equal to "C:UsersrunneradminAppDataLocalTempwo home 14549name with spaces"
"C:UsersRUNNER~1AppDataLocalTempwo home 14549name with spaces" is not equal to "C:UsersrunneradminAppDataLocalTempwo home 14549name with spaces"
操作的完整性:
name: BUG
on: [ push, pull_request, workflow_dispatch ]
jobs:
ci-test:
name: BUG
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.9
- run: pip install virtualenv
- shell: cmd
run: set
- name: Run tests
shell: cmd
run: |
testsbug.bat
如何使路径比较相等?
我使用子例程和%~s1
魔法字符串找到了一个答案,以获得8.3版本的文件名:
echo on
set "WORKON_HOME=%TMP%wo home %RANDOM%"
mkdir "%WORKON_HOME%"
cd /d "%WORKON_HOME%"
virtualenv "name with spaces"
cd "name with spaces"
call Scriptsactivate.bat
call:shorten "%WORKON_HOME%name with spaces",WO
call:shorten "%VIRTUAL_ENV%",VE
if "%WO%"=="%VE%" (
echo workon home and virtualenv are equal
) else (
echo. "%WORKON_HOME%name with spaces" is not equal to "%VIRTUAL_ENV%"
)
goto:eof
:shorten
for %%T in ("%~s1") do set "%~2=%%T"
exit /b 0