github-actionsunzip

Github Action step to extract .zip file?


Is there a way to extract the contents of a .zip file as part of a Github Action with a Windows runner?

I can't seem to find a reference for things like renaming files, unzipping/zipping, etc.


Solution

  • GitHub Actions just provides you with an operating system (Windows in your case), so the question is in fact, how would you do it in Windows command line. Once you know how to do this, you can do it on GitHub Actions.

    GitHub Actions documentation provides a list of pre-installed software on the runners, and more particularly, the Tools section on the Windows Server 2019 runner - specifies that 7zip is installed.

    So, it should be a matter of just running 7z x archive.zip in your step, or whatever the command you need.

    steps:
    - name: Checkout code
      uses: actions/checkout@v2
    
    - name: Extract some files
      run: 7z x archive.zip
    
    # ...
    

    If I were you, I would install 7zip locally, in order to figure out exactly how its CLI works, so you can just paste it later in a GitHub Action configuration file.