cache-apt-pkgs-action

repository·master·Indexed 43 days ago

https://github.com/awalsh128/cache-apt-pkgs-action

A GitHub Action that caches APT package dependencies to reduce workflow execution time by avoiding repeated installations. It supports adding third-party PPAs via the add-repository input, executing Debian package install scripts, and provides outputs such as cache-hit and package-version-list. Includes the apt_query CLI tool for resolving package names into normalized version lists.

Tokens
1.3K
Snippets
4
Records
6
Agent score
7%

What's inside cache-apt-pkgs-action

  1. Install cache-apt-pkgs-action in a GitHub Workflow

    master

    To use this action, create a workflow .yml file in your repository's .github/workflows directory. The action caches APT package dependencies to speed up workflow execution by avoiding re-installation on every run. It is a composition of actions/cache and the apt utility.

    Versioning Options

    • @v#: Pins to the latest release of a major version (e.g., v1).
    • @master: Most recent manually and automatically tested code (potentially unstable).
    • @staging: Most recent automatically tested code (experimental features).
    • @dev: Very unstable, contains experimental features.

    Note: The latest symbol is deprecated. Always pin to a specific version.

    steps:
      - uses: actions/checkout@v4
      - uses: awalsh128/cache-apt-pkgs-action@v1
        with:
          packages: dia doxygen graphviz
          version: 1.0
  2. Configure cache-apt-pkgs-action inputs

    master

    The following inputs are available for configuring the action:

    InputDescription
    packagesA space-delimited list of packages to install.
    versionThe version of the cache to load. Each version has its own unique cache. All characters except spaces are allowed.
    execute_install_scriptsIf true, attempts to execute Debian package pre and post install scripts upon restore.
    empty_packages_behaviorBehavior when packages is empty. Options: 'error' (default), 'warn', or 'ignore'.
    add-repositoryA space-delimited list of repositories to add via apt-add-repository before installation. Supports PPA (e.g., ppa:user/repo) and other formats.
  3. Handle Non-file Dependencies and Install Scripts

    master

    Because this action caches files, it may not automatically handle packages that require complex pre- or post-installation scripts located in /var/lib/dpkg/info/.

    Attempting to execute scripts

    You can try to resolve this using the execute_install_scripts input:

    - uses: awalsh128/cache-apt-pkgs-action@v1
      with:
        packages: mypackage
        version: 1.0
        execute_install_scripts: true

    Fallback for problematic packages

    If execute_install_scripts does not resolve the issue, you must run apt-get install as a separate, un-cached step for that specific package:

    - name: Manual Install
      run: apt-get install mypackage
      shell: bash
  4. Install packages from Third-party PPAs

    master

    You can add repositories (including PPAs) using the add-repository input. This must be done before the packages are installed.

    Single PPA

    - uses: awalsh128/cache-apt-pkgs-action@v1
      with:
        packages: chromium-browser
        add-repository: ppa:canonical-chromium-builds/stage
        version: 1.0

    Multiple Repositories

    - uses: awalsh128/cache-apt-pkgs-action@v1
      with:
        packages: package1 package2
        add-repository: ppa:user/repo1 ppa:user/repo2
        version: 1.0
    install_from_multiple_repos:
      runs-on: ubuntu-latest
      steps:
        - uses: actions/checkout@v4
        - uses: awalsh128/cache-apt-pkgs-action@v1
          with:
            packages: package1 package2
            add-repository: ppa:user/repo1 ppa:user/repo2
            version: 1.0
  5. Use outputs from cache-apt-pkgs-action

    master

    The action provides the following outputs:

    OutputDescription
    cache-hitA boolean indicating if a cache was found for the requested packages.
    package-version-listA comma-delimited list of the requested packages and their installed versions (e.g., pkg1=1.0,pkg2=2.0).
    all-package-version-listA comma-delimited list of all installed packages and versions, including dependencies (e.g., pkg1=1.0,dep1=1.2,...).
  6. Use the apt_query CLI to list normalized package versions

    master

    The apt_query binary is a CLI tool used to resolve APT package names into a normalized list of versions. It can execute real commands or replay output from a log file for testing/debugging.

    Commands

    CommandDescription
    normalized-list <pkg1> <pkg2> ...Resolves the provided package names and outputs their serialized normalized information.

    Flags

    FlagDescription
    --debugEnables diagnostic logging. A log file named <binary_name>.log will be created alongside the binary.
    --replayfile <path>Instead of executing a real binary, the tool will replay command output from the specified file. The file must follow the format generated when using the --debug flag.

    Usage Example

    To get the normalized list for curl and git:

    ./apt_query normalized-list curl git
    ./apt_query normalized-list <package_name1> <package_name2> ...
    
    # With debug logging enabled
    ./apt_query --debug normalized-list curl
    
    # Replaying from a log file
    ./apt_query --replayfile ./apt_query.log normalized-list curl