GitHub Actions zip directory


This post goes over how to zip a directory with GitHub Actions:

POSIX

To archive a folder build in GitHub Actions for Ubuntu/macOS:

- run: cd build && zip -r my_archive.zip .

Changing the directory removes the extra folder when zipping the contents.

Alternatively, you can replace cd with working-directory:

- run: zip -r my_archive.zip .
  working-directory: build

Windows

On Windows, the zip command is unavailable, but 7-Zip is available:

- run: 7z a -r my_archive.zip ./*
  working-directory: build

All

A step that works on all runners (Linux, macOS, and Windows):

- working-directory: build
  shell: bash
  run: |
    if [[ $RUNNER_OS == 'Windows' ]]; then
      7z a -r my_archive.zip ./*
    else
      zip -r my_archive.zip .
    fi

See example.



Please support this site and join our Discord!