How to archive files in artifact for github workflow actions in order to fix this warning?
Asked Answered
A

4

49

There are over 10,000 files in this artifact, consider creating an archive before upload to improve the upload performance.

Achromat answered 21/7, 2021 at 13:12 Comment(0)
S
121

I had this issue deploying a node app to Azure App Services.

I fixed it by adding a zip and an unzip step.

zip step is

  - name: Zip artifact for deployment
    run: zip release.zip ./* -r

unzip step is

  - name: unzip artifact for deployment
    run: unzip release.zip

Add the zip step after the build step and before Upload artifact step like this

  - name: npm install, build, and test
    run: |
      npm install
      npm run build --if-present
      npm run test --if-present

  - name: Zip artifact for deployment
    run: zip release.zip ./* -r

  - name: Upload artifact for deployment job
    uses: actions/upload-artifact@v2
    with:
      name: node-app
      path: release.zip

Then the unzip step is added after the download artifact step and before the deploy step like this.

steps:
  - name: Download artifact from build job
    uses: actions/download-artifact@v2
    with:
      name: node-app
      
  - name: unzip artifact for deployment
    run: unzip release.zip

  - name: 'Deploy to Azure Web App'
    id: deploy-to-webapp
    uses: azure/webapps-deploy@v2
    with:
Saintsimonianism answered 1/10, 2021 at 8:6 Comment(11)
great answer, i was looking for a way to speed up my azure deployments, and this was it. I went from a 40 minute average deployment, to a 5 minute deployment, so your answer is much appreciated!Epaminondas
Be careful with hidden files/dirs (i.e. those who start with a dot), as it won't pick them. In my case I had to manually add those (zip -r release.zip * .env .next)Lutenist
@Lutenist Thanks, I needed to add the ".next" for my next js appShaduf
You may also delete the zip file after the unzip step by running rm release.zipGilmagilman
Great answer. In case anyone is using this answer together with the working-directory option, and is receiving an error From directory doesn't exist, please refer to my Q&A here.Rammish
This was super helpful! If you want to include hidden files too, use zip release.zip . -rHyperplane
Is there a performance benefit to doing this technique even if you don't have such a large number of files to be uploaded? I.e., if you have, say 50-100 files to be uploaded into an archive, does this technique speed-up the upload or download process?Fortaleza
My two cents: if your zip archive contains symlinks and some already exist when running unzip, you'll get an error. I had to use unzip -o -u packages-build.zip to ignore the error and overwrite the files successfully.Ivie
may i add you dont need to unzip the release folder you can just add it to the deploy job as the zip to deploy publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_52DFB46EC5A2427FBB1FFC3D2FA0860F }} package: release.zipAuburta
None of this worked for me. I had to convert to tar and then I kept getting permission denied when trying to create the release.zip file.Mats
Do make sure this is using this build: runs-on: ubuntu-latest you will get a powershell error trying to zip with windows-latest.Carmancarmarthen
I
10

I also faced this issue when deploying a react based app to Azure App service.

To add to the answer written by @steve, If the App service instance is windows based, one can use Powershell's Compress-Archive.

In build steps - zipping

Compress-Archive . release.zip

In deploy steps - unzipping

Expand-Archive release.zip

or

unzip release.zip

if the deployment script is using bash

Incarnate answered 2/11, 2021 at 21:14 Comment(1)
I think Compress-Archive * release.zip and Expand-Archive release.zip -DestinationPath . will must better to avoid additional folder been created.Whitacre
V
1

I found on my case, I was using a windows hosting environment, and found the easy solution was adding the "./dist" (my output dir) instead of "." (no quotes in the file) so that it did not archive the node_modules folder. It still has an install and build command, but i've removed test, and altered this line. Mine now deploys in about 1 minute. I'm not certain what the ramifications of not archiving everything is with these artifacts as i'm new to Git, but this was able to resolve my issue, in the event someone else "just needs to get something hosted or else" as well. See code:

      - name: Upload artifact for deployment job
        uses: actions/upload-artifact@v2
        with:
          name: node-app
          path: ./dist
Vaticide answered 14/3, 2023 at 20:20 Comment(0)
Q
-1

You can zip all the files using below command and then upload the zip folder as your artifacts.

zip artifact.zip <generated_files>/*
Quamash answered 23/7, 2021 at 18:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.