Home > other >  Powershell command Compress-Archive incredibly slow
Powershell command Compress-Archive incredibly slow

Time:09-14

I'm new to windows development and I'm attempting using github actions to do a build/deploy. In the build step I compress my project and upload it

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

and then in my deploy step I download it, expand it, and then deploy it.

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 .

The issue is that it takes an incredible amount of time to do the compression/expansion. I had previously done this on linux and it took around 2 minutes for compression/expansion, but using powershell it's taking about 15 minutes to compress and 12 minutes to expand. Why are the Compress/Expand commands going so slow? Am I doing something wrong? The expanded folder size is around 200MB

CodePudding user response:

You may experiment with compression parameters, e. g. -CompressionLevel Fastest.

Alternatively use .NET API directly, as Santiago Squarzon suggests. This requires PowerShell (Core) 7 :

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

Note that .NET API has a different current directory than PowerShell, so best practice is to pass only absolute paths to .NET API. The simplest way to do this is to prepend $PWD (PowerShell's current directory) to any path, e. g. "$PWD\SomeFile.xyz".

  • Related