This GitHub Action provides the functionality to compress or decompress files
using various compression formats including zip
, tar
, tgz
, and tbz2
. It
is designed to be easy to use within GitHub workflows for handling file
compression and decompression tasks efficiently.
Input | Description | Required | Default |
---|---|---|---|
command |
The operation to perform. It can be either "compress" or "decompress" | Yes | - |
source |
The source directory or file to compress or decompress. | Yes | - |
dest |
The destination directory or file for the output. If not provided, it defaults to the current working directory. | No | - |
format |
The compression format to use. Supported formats are zip , tar , tgz , and tbz2 . |
Yes | - |
includeRoot |
Whether to include the root folder itself in the compressed file. | No | yes |
Output | Description |
---|---|
file_path |
The path to the compressed or decompressed file. |
You can use this action in your GitHub workflow by specifying the action with its required inputs.
This example demonstrates how to use the Compress-Decompress action to compress a directory:
name: Compress Files
on: [push]
jobs:
compress-job:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Compress Directory
uses: somaz94/compress-decompress@v1
with:
command: compress
source: ./data-folder
format: zip
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: compressed-data
path: ./data-folder.zip
To decompress files, you can modify the workflow like so:
name: Decompress Files
on: [push]
jobs:
decompress-job:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Download Artifact
uses: actions/download-artifact@v4
with:
name: compressed-data
- name: List contents in the workspace
run: ls -la ${{ github.workspace }}
- name: Decompress Directory
uses: somaz94/compress-decompress@v1
with:
command: decompress
source: ./data-folder.zip
format: zip
dest: './unpacked'
- name: Display Content of the Unpacked Files
run: |
ls -la ${{ github.workspace }}/unpacked
cat ${{ github.workspace }}/unpacked/data-folder
This example demonstrates how to use the Compress-Decompress action to compress a directory:
name: Compress Files
on: [push]
jobs:
compress-job:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Compress Directory
uses: somaz94/compress-decompress@v1
with:
command: compress
source: ./data-folder
format: zip
includeRoot: 'false'
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: compressed-data
path: ./data-folder/data-folder.zip
To decompress files, you can modify the workflow like so:
name: Decompress Files
on: [push]
jobs:
decompress-job:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Download Artifact
uses: actions/download-artifact@v4
with:
name: compressed-data
- name: List contents in the workspace
run: ls -la ${{ github.workspace }}
- name: Decompress Directory
uses: somaz94/compress-decompress@v1
with:
command: decompress
source: ./data-folder.zip
format: zip
dest: './unpacked'
- name: Display Content of the Unpacked Files
run: |
ls -la ${{ github.workspace }}/unpacked
cat ${{ github.workspace }}/unpacked/data-folder.txt # You'll have all the files in that directory. This is an example
The includeRoot
option controls how files are structured within the compressed archive:
- Creates the archive with the source folder as the root directory
- Preserves the original directory structure
- Example structure:
data-folder.zip └── data-folder/ ├── file1.txt ├── file2.txt └── subfolder/ └── file3.txt
- Output location:
./data-folder.zip
- Compresses only the contents of the source folder without the parent directory
- Files are directly at the root of the archive
- Example structure:
data-folder.zip ├── file1.txt ├── file2.txt └── subfolder/ └── file3.txt
- Output location:
./data-folder/data-folder.zip
- Use
includeRoot: true
when you want to preserve the directory structure and need the parent folder name in the archive - Use
includeRoot: false
when you only want to compress the contents without the parent directory name
This project is licensed under the MIT License file for details.
Contributions are welcome! Please feel free to submit a Pull Request.