From 32569df7e7224301f8891395c7a2548d9ff291b9 Mon Sep 17 00:00:00 2001 From: Mahyar McDonald Date: Fri, 31 Oct 2025 12:32:16 -0700 Subject: [PATCH] add setting to disable Aptfile usage --- README.md | 13 +++++++++++++ action.yml | 6 ++++++ pre_cache_action.sh | 28 ++++++++++++++++++---------- 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index dc65005..e189feb 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ There are three kinds of version labels you can use. - `execute_install_scripts` - Execute Debian package pre and post install script upon restore. See [Caveats / Non-file Dependencies](#non-file-dependencies) for more information. - `empty_packages_behavior` - Desired behavior when the given `packages` is empty. `'error'` (default), `'warn'` or `'ignore'`. - `add-repository` - Space delimited list of repositories to add via `apt-add-repository` before installing packages. Supports PPA (e.g., `ppa:user/repo`) and other repository formats. +- `use_aptfile` - Whether to read packages from `Aptfile` at repository root. Set to `false` to disable Aptfile usage even if `Aptfile` exists. Default is `true`. ### Outputs @@ -164,6 +165,18 @@ You can also combine packages from both the input and `Aptfile`: packages: protobuf-compiler sd # Additional packages beyond Aptfile ``` +### Disabling Aptfile Usage + +If you want to disable Aptfile reading even when an `Aptfile` exists in your repository, set `use_aptfile` to `false`: + +```yaml +- uses: awalsh128/cache-apt-pkgs-action@latest + with: + version: v1 + packages: cmake build-essential + use_aptfile: false # Ignore Aptfile even if it exists +``` + ## Caveats ### Non-file Dependencies diff --git a/action.yml b/action.yml index 3deb135..ef95422 100644 --- a/action.yml +++ b/action.yml @@ -39,6 +39,10 @@ inputs: description: 'Space delimited list of repositories to add via apt-add-repository before installing packages. Supports PPA (ppa:user/repo) and other repository formats.' required: false default: '' + use_aptfile: + description: 'Whether to read packages from Aptfile at repository root. Set to false to disable Aptfile usage even if Aptfile exists.' + required: false + default: 'true' outputs: cache-hit: @@ -64,6 +68,7 @@ runs: "$EXEC_INSTALL_SCRIPTS" \ "$DEBUG" \ "$ADD_REPOSITORY" \ + "$USE_APTFILE" \ "$PACKAGES" if [ -f ~/cache-apt-pkgs/cache_key.md5 ]; then echo "CACHE_KEY=$(cat ~/cache-apt-pkgs/cache_key.md5)" >> $GITHUB_ENV @@ -77,6 +82,7 @@ runs: EMPTY_PACKAGES_BEHAVIOR: "${{ inputs.empty_packages_behavior }}" DEBUG: "${{ inputs.debug }}" ADD_REPOSITORY: "${{ inputs.add-repository }}" + USE_APTFILE: "${{ inputs.use_aptfile }}" PACKAGES: "${{ inputs.packages }}" - id: load-cache diff --git a/pre_cache_action.sh b/pre_cache_action.sh index 880c34f..74aff11 100755 --- a/pre_cache_action.sh +++ b/pre_cache_action.sh @@ -27,24 +27,32 @@ debug="${4}" # Repositories to add before installing packages. add_repository="${5}" +# Whether to use Aptfile +use_aptfile="${6}" +validate_bool "${use_aptfile}" use_aptfile 5 + # List of the packages to use. -input_packages="${@:6}" +input_packages="${@:7}" # Check for Aptfile at repository root and merge with input packages aptfile_path="${GITHUB_WORKSPACE:-.}/Aptfile" aptfile_packages="" -if test -n "${GITHUB_WORKSPACE}" && test -f "${aptfile_path}"; then - log "Found Aptfile at ${aptfile_path}, parsing packages..." - aptfile_packages="$(parse_aptfile "${aptfile_path}")" - if test -n "${aptfile_packages}"; then - log "Parsed $(echo "${aptfile_packages}" | wc -w) package(s) from Aptfile" +if test "${use_aptfile}" = "true"; then + if test -n "${GITHUB_WORKSPACE}" && test -f "${aptfile_path}"; then + log "Found Aptfile at ${aptfile_path}, parsing packages..." + aptfile_packages="$(parse_aptfile "${aptfile_path}")" + if test -n "${aptfile_packages}"; then + log "Parsed $(echo "${aptfile_packages}" | wc -w) package(s) from Aptfile" + else + log "Aptfile is empty or contains only comments" + fi + elif test -z "${GITHUB_WORKSPACE}"; then + log "GITHUB_WORKSPACE not set, skipping Aptfile check" else - log "Aptfile is empty or contains only comments" + log "No Aptfile found at ${aptfile_path}" fi -elif test -z "${GITHUB_WORKSPACE}"; then - log "GITHUB_WORKSPACE not set, skipping Aptfile check" else - log "No Aptfile found at ${aptfile_path}" + log "Aptfile usage is disabled (use_aptfile=false)" fi # Merge input packages with Aptfile packages