Powershell命令压缩存档速度慢得令人难以置信



我是windows开发的新手,正在尝试使用github操作进行构建/部署。在构建步骤中,我压缩我的项目并上传

jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: Set up Node.js version
uses: actions/setup-node@v1
with:
node-version: '16.x'
- name: npm install, build, and test
run: |
npm install
npm run build --if-present
npm run test --if-present

- name: Zip contents for upload
shell: powershell
run: |
Compress-Archive -Path . -DestinationPath nextjs-app.zip
- name: Upload artifact for deployment job
uses: actions/upload-artifact@v2
with:
name: nextjs-app
path: nextjs-app.7z

然后在我的部署步骤中,我下载它,展开它,然后部署它

deploy:
runs-on: windows-latest 
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Download artifact from build job
uses: actions/download-artifact@v2
with:
name: nextjs-app
- name: Unzip archive file
shell: powershell
run: |
Expand-Archive nextjs-app.zip -DestinationPath .

问题是压缩/膨胀需要花费大量的时间。我以前在linux上做过这件事,压缩/扩展大约需要2分钟,但使用powershell压缩大约需要15分钟,扩展大约需要12分钟。为什么压缩/展开命令运行如此缓慢?我做错什么了吗?扩展后的文件夹大小约为200MB

您可以尝试压缩参数,例如-CompressionLevel Fastest

或者直接使用.NET API,就像Santiago Squarzon建议的那样。这需要PowerShell(Core(7+:

[IO.Compression.ZipFile]::CreateFromDirectory( $sourceDirectory, $zipFileName, 'Fastest', $false )

请注意,.NET API的当前目录与PowerShell不同,因此最佳做法是仅将绝对路径传递给.NET API。最简单的方法是将$PWD(PowerShell的当前目录(前置到任何路径,例如"$PWDSomeFile.xyz"

最新更新