Skip to content

somaz94/compress-decompress

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

Compress-Decompress Action

CI License Latest Tag Top Language GitHub Marketplace

Description

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.

Key Features:

  • Glob Pattern Support - Match multiple files with patterns like **/*.doc
  • Symbolic Link Support - Automatically follows symlinks (Bazel, Buck, and build tool integration)
  • Path Stripping - Remove path prefixes while preserving directory structure
  • Multiple Formats - Support for zip, tar, tgz, and tbz2
  • Flexible Options - Custom destinations, exclude patterns, and root control

Inputs

Input Description Required Default
command The operation to perform. It can be either "compress" or "decompress" Yes -
source The source directory, file, or glob pattern to compress or decompress. Supports glob patterns like **/*.doc to match multiple files. Yes -
dest The destination directory for the output. If not provided, it defaults to the current working directory. No -
destfilename The destination filename for the output (extension is appended depending on the format). If not provided, it defaults to the current working directory's name. No -
exclude Filename (or pattern) to exclude from compression process. 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
preserveGlobStructure When using glob patterns, preserve the directory structure in the archive. If false, all matched files are flattened to the root level. No false
stripPrefix Remove this prefix from file paths when preserving directory structure. Works only with glob patterns and preserveGlobStructure: true. Example: 'src/' changes src/app/main.py to app/main.py in the archive. No ""
fail_on_error Whether to fail the action if compression/decompression fails. No true
verbose Enable verbose logging for debugging purposes. No false

Outputs

Output Description
file_path The path to the compressed or decompressed file.

Usage

You can use this action in your GitHub workflow by specifying the action with its required inputs.


Documentation

Comprehensive Guides:


Example Workflows

Custom Destination and Filename

This example demonstrates how to use custom destination and filename options:

name: Compress Files with Custom Path

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
          dest: './custom_output'
          destfilename: 'my_archive'

      - name: Upload Artifact
        uses: actions/upload-artifact@v4
        with:
          name: compressed-data
          path: ./custom_output/my_archive.zip

Using Exclude Patterns

Exclude specific files or directories from compression:

- name: Compress Repository Excluding Git Files
  uses: somaz94/compress-decompress@v1
  with:
    command: compress
    source: .
    format: zip
    dest: './artifacts'
    destfilename: 'repo-backup'
    exclude: '.git .github node_modules *.log'

Common exclusions:

  • Version control: .git .svn
  • Dependencies: node_modules vendor
  • Temporary files: *.log *.tmp

πŸ“– View Advanced Usage Guide β†’


Using Glob Patterns

This action supports glob patterns for matching multiple files across your repository. This is useful when you need to archive specific file types without compressing entire directories.

- name: Compress All Documentation Files
  uses: somaz94/compress-decompress@v1
  with:
    command: compress
    source: '**/*.md'
    format: zip
    dest: './artifacts'
    destfilename: 'all-docs'

Common Patterns:

  • **/*.ext - All files with extension in all subdirectories
  • dir/**/*.ext - All files with extension in specific directory
  • **/*.{ext1,ext2} - Multiple file types

Key Behaviors:

  • Files are collected into a flattened archive structure by default
  • Use preserveGlobStructure: true to maintain directory structure
  • Use stripPrefix to remove path prefixes (e.g., 'src/' removes src/ from all paths)
  • No matches will fail by default (use fail_on_error: false to override)
  • Enable verbose: true to see matched files

Example with preserved structure:

- name: Archive Logs with Directory Structure
  uses: somaz94/compress-decompress@v1
  with:
    command: compress
    source: '**/*.log'
    format: zip
    preserveGlobStructure: true  # Preserves dir/subdir1/file.log structure

Example with stripped prefix:

- name: Archive Source Files Without Project Root
  uses: somaz94/compress-decompress@v1
  with:
    command: compress
    source: 'project/src/**/*.ts'
    format: zip
    preserveGlobStructure: true
    stripPrefix: 'project/'  # Changes project/src/app/main.ts to src/app/main.ts

πŸ“– View Complete Glob Pattern Guide β†’


Basic Compression and Decompression

Compress a directory:

- name: Compress Directory
  uses: somaz94/compress-decompress@v1
  with:
    command: compress
    source: ./data-folder
    format: zip

Decompress an archive:

- name: Decompress Archive
  uses: somaz94/compress-decompress@v1
  with:
    command: decompress
    source: ./data-folder.zip
    format: zip
    dest: './unpacked'

Troubleshooting


Common Issues:

Compression fails with "Source not found"?
  1. Verify source path exists: ls -la ./data-folder
  2. Use absolute paths: ${{ github.workspace }}/data-folder
  3. Check workspace state: ls -la ${{ github.workspace }}
  4. See Troubleshooting Guide
Glob pattern not matching files?
  1. Verify files exist: find . -name "*.doc"
  2. Enable verbose mode: verbose: true
  3. Check pattern syntax: Use single quotes '**/*.doc'
  4. See Glob Pattern Guide
Archive size is too large?
  1. Use exclude patterns: exclude: 'node_modules .git *.log'
  2. Use better compression: format: tbz2 instead of zip
  3. Split into multiple archives
  4. See Troubleshooting Guide
Exclude patterns not working?

Correct syntax (space-separated):

exclude: 'node_modules .git *.log'

Incorrect (comma-separated):

exclude: 'node_modules,.git,*.log'  # Wrong!

See Advanced Usage - Exclude Patterns

β†’ See full troubleshooting guide


Contributing


Contributions welcome! Please:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/my-feature
  3. Make your changes and test locally
  4. Commit: git commit -am "feat: Add new feature"
  5. Push and create a Pull Request

Running Tests

python3 -m venv .venv
source .venv/bin/activate
pip install pytest
python -m pytest tests/ -v

β†’ See full testing guide | β†’ See development and testing guide


License

This project is licensed under the MIT License - see the LICENSE file for details.


Support


Contributors

Thanks to all contributors:


Star History

Compress-Decompress Star History Chart

Made with efficiency for GitHub Actions workflows

Documentation | Examples | Troubleshooting